8 #ifndef QMAPTHREADSAFETY_H 9 #define QMAPTHREADSAFETY_H 14 #include <QMutexLocker> 16 #include "cppwebframework_global.h" 19 template <
typename Key,
typename T>
25 mutable QMap<Key, T> m_map;
28 typedef typename QMap<Key, T>::iterator iterator;
30 typedef typename QMap<Key, T>::const_iterator const_iterator;
34 explicit QMapThreadSafety(std::initializer_list<std::pair<Key, T>> &list) : m_map(list){}
48 QMutexLocker locker(&mutex);
52 const_iterator cbegin()
const 54 QMutexLocker locker(&mutex);
55 return m_map.cbegin();
58 const_iterator cend()
const 60 QMutexLocker locker(&mutex);
64 const_iterator constBegin()
const 66 QMutexLocker locker(&mutex);
67 return m_map.constBegin();
70 const_iterator constEnd()
const 72 QMutexLocker locker(&mutex);
73 return m_map.constEnd();
76 const_iterator constFind(
const Key &key)
const 78 QMutexLocker locker(&mutex);
79 return m_map.constFind(key);
88 QMutexLocker locker(&mutex);
89 return m_map.contains(key);
92 int count(
const Key &key)
const 94 QMutexLocker locker(&mutex);
95 return m_map.count(key);
100 QMutexLocker locker(&mutex);
101 return m_map.count();
106 QMutexLocker locker(&mutex);
107 return m_map.empty();
115 QMutexLocker locker(&mutex);
119 QPair<iterator, iterator> equal_range(
const Key &key)
121 QMutexLocker locker(&mutex);
122 return m_map.equal_range(key);
125 iterator erase(iterator pos)
127 QMutexLocker locker(&mutex);
128 return m_map.erase(pos);
131 iterator find(
const Key &key)
133 QMutexLocker locker(&mutex);
134 return m_map.find(key);
137 const_iterator find(
const Key &key)
const 139 QMutexLocker locker(&mutex);
140 return m_map.find(key);
145 QMutexLocker locker(&mutex);
146 return m_map.first();
149 const T & first()
const 151 QMutexLocker locker(&mutex);
152 return m_map.first();
155 const Key & firstKey()
const 157 QMutexLocker locker(&mutex);
158 return m_map.firstKey();
166 iterator
insert(
const Key &key,
const T &value)
168 QMutexLocker locker(&mutex);
169 return m_map.insert(key, value);
172 iterator
insert(const_iterator pos,
const Key &key,
const T &value)
174 QMutexLocker locker(&mutex);
175 return m_map.insert(pos, key, value);
178 iterator insertMulti(
const Key &key,
const T &value)
180 QMutexLocker locker(&mutex);
181 return m_map.insertMulti(key, value);
186 QMutexLocker locker(&mutex);
187 return m_map.isEmpty();
190 QList<Key> keys()
const 192 QMutexLocker locker(&mutex);
196 QList<Key> keys(
const T &value)
const 198 QMutexLocker locker(&mutex);
204 QMutexLocker locker(&mutex);
208 const T &last()
const 210 QMutexLocker locker(&mutex);
215 iterator lowerBound(
const Key &key)
217 QMutexLocker locker(&mutex);
218 return m_map.lowerBound(key);
221 const_iterator lowerBound(
const Key &key)
const 223 QMutexLocker locker(&mutex);
224 return m_map.lowerBound(key);
231 int remove(
const Key &key)
233 QMutexLocker locker(&mutex);
234 return m_map.remove(key);
239 QMutexLocker locker(&mutex);
243 void swap(QMap<Key, T> & other)
245 QMutexLocker locker(&mutex);
249 T take(
const Key &key)
251 QMutexLocker locker(&mutex);
252 return m_map.take(key);
255 std::map<Key, T> toStdMap()
const 257 QMutexLocker locker(&mutex);
258 return m_map.toStdMap();
261 QList<Key> uniqueKeys()
const 263 QMutexLocker locker(&mutex);
264 return m_map.uniqueKeys();
267 QMap<Key, T> &unite(
const QMap<Key, T> & other)
269 QMutexLocker locker(&mutex);
270 return m_map.unite(other);
273 iterator upperBound(
const Key & key)
275 QMutexLocker locker(&mutex);
276 return m_map.upperBound(key);
279 const_iterator upperBound(
const Key & key)
const 281 QMutexLocker locker(&mutex);
282 return m_map.upperBound(key);
285 const T value(
const Key & key,
const T & defaultValue = T())
const 287 QMutexLocker locker(&mutex);
288 return m_map.value(key, defaultValue);
291 QList<T> values()
const 293 QMutexLocker locker(&mutex);
294 return m_map.values();
297 QList<T> values(
const Key & key)
const 299 QMutexLocker locker(&mutex);
300 return m_map.values(key);
303 bool operator!=(
const QMap<Key, T> & other)
const 305 QMutexLocker locker(&mutex);
306 return m_map.operator !=(other);
309 QMap<Key, T> & operator=(
const QMap<Key, T> & other)
311 QMutexLocker locker(&mutex);
312 return m_map.operator =(other);
315 QMap<Key, T> & operator=(QMap<Key, T> && other)
317 QMutexLocker locker(&mutex);
318 return m_map.operator =(other);
321 bool operator==(
const QMap<Key, T> & other)
const 323 QMutexLocker locker(&mutex);
324 return m_map.operator ==(other);
327 T & operator[](
const Key & key)
329 QMutexLocker locker(&mutex);
330 return m_map.operator [](key);
338 const T operator [](
const Key &key)
const 340 QMutexLocker locker(&mutex);
341 return m_map.operator [](key);
347 #endif // QMAPTHREADSAFETY_H iterator end()
This method retuns the end iterator.
Definition: qmapthreadsafety.h:113
iterator insert(const Key &key, const T &value)
This method inserts a new key and value in the map.
Definition: qmapthreadsafety.h:166
bool contains(const Key &key) const
This method checks if the map contains and specific element given a specific key. ...
Definition: qmapthreadsafety.h:86
The QMapThreadSafety class is a thread safe QMap.
Definition: qmapthreadsafety.h:23
iterator begin() const
This method retuns the begin iterator.
Definition: qmapthreadsafety.h:46