31#include <sptk5/sptk.h>
45template<
class K,
class T>
51 mutable std::mutex m_sync;
53 using Map = std::map<K, T>;
75 virtual void insert(
const K& key,
const T& data)
77 std::scoped_lock lock(m_sync);
78 m_map.emplace(key, data);
89 virtual bool get(
const K& key, T& item,
bool remove =
false)
91 std::scoped_lock lock(m_sync);
92 typename Map::iterator itor = m_map.find(key);
93 if (itor == m_map.end())
113 std::scoped_lock lock(m_sync);
114 typename Map::iterator itor = m_map.find(key);
115 if (itor == m_map.end())
128 std::scoped_lock lock(m_sync);
129 return m_map.empty();
137 std::scoped_lock lock(m_sync);
146 std::scoped_lock lock(m_sync);
157 std::scoped_lock lock(m_sync);
158 for (
auto itor: m_map)
160 if (!callbackFunction(itor.first, itor.second))
Definition: SynchronizedMap.h:47
virtual bool get(const K &key, T &item, bool remove=false)
Definition: SynchronizedMap.h:89
size_t size() const
Definition: SynchronizedMap.h:135
bool for_each(CallbackFunction callbackFunction)
Definition: SynchronizedMap.h:155
virtual bool remove(const K &key)
Definition: SynchronizedMap.h:111
bool empty() const
Definition: SynchronizedMap.h:126
virtual void insert(const K &key, const T &data)
Definition: SynchronizedMap.h:75
void clear()
Definition: SynchronizedMap.h:144
std::function< bool(const K &key, T &item)> CallbackFunction
Definition: SynchronizedMap.h:68