// Copyright 2018 The Dawn Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef COMMON_SERIALMAP_H_ #define COMMON_SERIALMAP_H_ #include "common/SerialStorage.h" #include #include template class SerialMap; template struct SerialStorageTraits> { using Serial = SerialT; using Value = ValueT; using Storage = std::map>; using StorageIterator = typename Storage::iterator; using ConstStorageIterator = typename Storage::const_iterator; }; // SerialMap stores a map from Serial to Value. // Unlike SerialQueue, items may be enqueued with Serials in any // arbitrary order. SerialMap provides useful iterators for iterating // through Value items in order of increasing Serial. template class SerialMap : public SerialStorage> { public: void Enqueue(const Value& value, Serial serial); void Enqueue(Value&& value, Serial serial); void Enqueue(const std::vector& values, Serial serial); void Enqueue(std::vector&& values, Serial serial); }; // SerialMap template void SerialMap::Enqueue(const Value& value, Serial serial) { this->mStorage[serial].emplace_back(value); } template void SerialMap::Enqueue(Value&& value, Serial serial) { this->mStorage[serial].emplace_back(value); } template void SerialMap::Enqueue(const std::vector& values, Serial serial) { DAWN_ASSERT(values.size() > 0); for (const Value& value : values) { Enqueue(value, serial); } } template void SerialMap::Enqueue(std::vector&& values, Serial serial) { DAWN_ASSERT(values.size() > 0); for (const Value& value : values) { Enqueue(value, serial); } } #endif // COMMON_SERIALMAP_H_