juicy compiler error
This commit is contained in:
+19
-10
@@ -1,20 +1,23 @@
|
||||
#ifndef CONCURRENTMAP_H
|
||||
#define CONCURRENTMAP_H
|
||||
|
||||
#include <QMutex>
|
||||
#include <QMap>
|
||||
#include <QMutex>
|
||||
#include <functional>
|
||||
|
||||
template<typename TKey, typename TValue>
|
||||
template <typename TKey, typename TValue>
|
||||
class ConcurrentMap
|
||||
{
|
||||
public:
|
||||
ConcurrentMap() {
|
||||
ConcurrentMap()
|
||||
{
|
||||
mutex = new QMutex();
|
||||
map = new QMap<TKey, TValue>();
|
||||
}
|
||||
|
||||
bool tryGet(const TKey &name, TValue& value) const {
|
||||
bool
|
||||
tryGet(const TKey &name, TValue &value) const
|
||||
{
|
||||
mutex->lock();
|
||||
auto a = map->find(name);
|
||||
if (a == map->end()) {
|
||||
@@ -27,7 +30,9 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
TValue getOrAdd(const TKey &name, std::function<TValue ()> addLambda) {
|
||||
TValue
|
||||
getOrAdd(const TKey &name, std::function<TValue()> addLambda)
|
||||
{
|
||||
mutex->lock();
|
||||
auto a = map->find(name);
|
||||
if (a == map->end()) {
|
||||
@@ -40,21 +45,25 @@ public:
|
||||
return a.value();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
void
|
||||
clear()
|
||||
{
|
||||
mutex->lock();
|
||||
map->clear();
|
||||
mutex->unlock();
|
||||
}
|
||||
|
||||
void insert(const TKey &name, const TValue &value) {
|
||||
void
|
||||
insert(const TKey &name, const TValue &value)
|
||||
{
|
||||
mutex->lock();
|
||||
map->insert(name, value);
|
||||
mutex->unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
QMutex* mutex;
|
||||
QMap<TKey, TValue>* map;
|
||||
QMutex *mutex;
|
||||
QMap<TKey, TValue> *map;
|
||||
};
|
||||
|
||||
#endif // CONCURRENTMAP_H
|
||||
#endif // CONCURRENTMAP_H
|
||||
|
||||
Reference in New Issue
Block a user