5 #include <QMutexLocker> 13 template <
typename TKey,
typename TValue>
21 QMutexLocker lock(&this->mutex);
23 auto a = this->data.find(name);
24 if (a == this->data.end())
34 TValue
getOrAdd(
const TKey &
name, std::function<TValue()> addLambda)
36 QMutexLocker lock(&this->mutex);
38 auto a = this->data.find(name);
39 if (a == this->data.end())
41 TValue value = addLambda();
42 this->data.insert(name, value);
51 QMutexLocker lock(&this->mutex);
53 return this->data[
name];
58 QMutexLocker lock(&this->mutex);
63 void insert(
const TKey &name,
const TValue &value)
65 QMutexLocker lock(&this->mutex);
67 this->data.insert(name, value);
71 std::function<
void(
const TKey &name,
const TValue &value)> func)
const 73 QMutexLocker lock(&this->mutex);
75 QMapIterator<TKey, TValue> it(this->data);
80 func(it.key(), it.value());
84 void each(std::function<
void(
const TKey &name, TValue &value)> func)
86 QMutexLocker lock(&this->mutex);
88 QMutableMapIterator<TKey, TValue> it(this->data);
93 func(it.key(), it.value());
99 QMap<TKey, TValue> data;
TValue getOrAdd(const TKey &name, std::function< TValue()> addLambda)
Definition: ConcurrentMap.hpp:34
Definition: ConcurrentMap.hpp:14
Definition: Application.cpp:48
void insert(const TKey &name, const TValue &value)
Definition: ConcurrentMap.hpp:63
void clear()
Definition: ConcurrentMap.hpp:56
void each(std::function< void(const TKey &name, TValue &value)> func)
Definition: ConcurrentMap.hpp:84
void each(std::function< void(const TKey &name, const TValue &value)> func) const
Definition: ConcurrentMap.hpp:70
TValue & operator[](const TKey &name)
Definition: ConcurrentMap.hpp:49
QString name
Definition: Credentials.cpp:94
bool tryGet(const TKey &name, TValue &value) const
Definition: ConcurrentMap.hpp:19