3#include <unordered_map>
7template <
typename IdType>
34template <
typename Key,
typename Value,
typename container = std::unordered_map<Key, Value>,
typename IdGen = IdGenerator<Key>>
49 std::lock_guard<std::mutex>
lock()
51 return std::lock_guard(m_mutex);
54 using container::begin;
57 using container::find;
59 Value
get(
const Key & key)
61 std::lock_guard
lock(m_mutex);
62 return container::at(key);
67 std::lock_guard
lock(m_mutex);
68 return container::size();
73 std::lock_guard
lock(m_mutex);
74 return container::find(key) != container::end();
79 std::lock_guard
lock(m_mutex);
80 Key key = m_id_generator.nextId();
81 container::insert(std::make_pair(key, value));
87 std::lock_guard
lock(m_mutex);
88 Key key = m_id_generator.nextId();
89 container::insert(std::make_pair(key, std::move(value)));
93 void insert(
const Key & key,
const Value & value)
95 std::lock_guard
lock(m_mutex);
96 container::insert(std::make_pair(key, value));
99 void insert(
const Key & key, Value && value)
101 std::lock_guard
lock(m_mutex);
102 container::insert(std::make_pair(key, std::move(value)));
107 std::lock_guard
lock(m_mutex);
108 container::erase(key);
113 std::lock_guard
lock(m_mutex);
114 std::vector<Value>
values;
115 values.reserve(container::size());
116 for (
const auto & [key, value] : *
this)
127 IdGen m_id_generator;
129 mutable std::mutex m_mutex;
IdGenerator(IdGenerator &&other)=delete
~IdGenerator()
Definition: List.hpp:14
static const IdType invalid_id
Definition: List.hpp:26
IdGenerator & operator=(IdGenerator &&other)=delete
IdGenerator & operator=(IdGenerator &other)=delete
IdGenerator()
Definition: List.hpp:13
IdGenerator(IdGenerator &other)=delete
IdType nextId()
Definition: List.hpp:21
std::vector< Value > values() const
Definition: List.hpp:111
IdList()
Definition: List.hpp:40
Key insert(Value &&value)
Definition: List.hpp:85
~IdList()
Definition: List.hpp:41
void erase(const Key &key)
Definition: List.hpp:105
void insert(const Key &key, const Value &value)
Definition: List.hpp:93
void insert(const Key &key, Value &&value)
Definition: List.hpp:99
IdList(const IdList &other)=delete
Value get(const Key &key)
Definition: List.hpp:59
bool contains(const Key &key) const
Definition: List.hpp:71
uint32_t size() const
Definition: List.hpp:65
std::lock_guard< std::mutex > lock()
Definition: List.hpp:49
Key insert(const Value &value)
Definition: List.hpp:77
static const Key invalid_id
Definition: List.hpp:123
IdList & operator=(const IdList &other)=delete
IdList & operator=(IdList &&other)=delete
IdList(IdList &&other)=delete