mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 12:17:45 +02:00
Fix node persmissions hash
This commit is contained in:
parent
a38ab4ff80
commit
3e68018a12
1 changed files with 29 additions and 11 deletions
|
@ -13,18 +13,31 @@
|
||||||
#define hifi_NodePermissions_h
|
#define hifi_NodePermissions_h
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <unordered_map>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
#include <QHash>
|
||||||
|
#include <utility>
|
||||||
#include "GroupRank.h"
|
#include "GroupRank.h"
|
||||||
|
|
||||||
class NodePermissions;
|
class NodePermissions;
|
||||||
using NodePermissionsPointer = std::shared_ptr<NodePermissions>;
|
using NodePermissionsPointer = std::shared_ptr<NodePermissions>;
|
||||||
using NodePermissionsKey = QPair<QString, QUuid>; // name, rankID
|
using NodePermissionsKey = std::pair<QString, QUuid>; // name, rankID
|
||||||
using NodePermissionsKeyList = QList<QPair<QString, QUuid>>;
|
using NodePermissionsKeyList = QList<QPair<QString, QUuid>>;
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
template<>
|
||||||
|
struct hash<NodePermissionsKey> {
|
||||||
|
size_t operator()(const NodePermissionsKey& key) const {
|
||||||
|
size_t result = qHash(key.first);
|
||||||
|
result <<= 32;
|
||||||
|
result |= qHash(key.second);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
class NodePermissions {
|
class NodePermissions {
|
||||||
public:
|
public:
|
||||||
|
@ -100,27 +113,32 @@ public:
|
||||||
NodePermissionsMap() { }
|
NodePermissionsMap() { }
|
||||||
NodePermissionsPointer& operator[](const NodePermissionsKey& key) {
|
NodePermissionsPointer& operator[](const NodePermissionsKey& key) {
|
||||||
NodePermissionsKey dataKey(key.first.toLower(), key.second);
|
NodePermissionsKey dataKey(key.first.toLower(), key.second);
|
||||||
if (!_data.contains(dataKey)) {
|
if (0 == _data.count(dataKey)) {
|
||||||
_data[dataKey] = NodePermissionsPointer(new NodePermissions(key));
|
_data[dataKey] = NodePermissionsPointer(new NodePermissions(key));
|
||||||
}
|
}
|
||||||
return _data[dataKey];
|
return _data[dataKey];
|
||||||
}
|
}
|
||||||
NodePermissionsPointer operator[](const NodePermissionsKey& key) const {
|
NodePermissionsPointer operator[](const NodePermissionsKey& key) const {
|
||||||
return _data.value(NodePermissionsKey(key.first.toLower(), key.second));
|
NodePermissionsPointer result;
|
||||||
|
auto itr = _data.find(NodePermissionsKey(key.first.toLower(), key.second));
|
||||||
|
if (_data.end() != itr) {
|
||||||
|
result = itr->second;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
bool contains(const NodePermissionsKey& key) const {
|
bool contains(const NodePermissionsKey& key) const {
|
||||||
return _data.contains(NodePermissionsKey(key.first.toLower(), key.second));
|
return 0 != _data.count(NodePermissionsKey(key.first.toLower(), key.second));
|
||||||
}
|
}
|
||||||
bool contains(const QString& keyFirst, QUuid keySecond) const {
|
bool contains(const QString& keyFirst, const QUuid& keySecond) const {
|
||||||
return _data.contains(NodePermissionsKey(keyFirst.toLower(), keySecond));
|
return 0 != _data.count(NodePermissionsKey(keyFirst.toLower(), keySecond));
|
||||||
}
|
}
|
||||||
QList<NodePermissionsKey> keys() const { return _data.keys(); }
|
//QList<NodePermissionsKey> keys() const { return _data.keys(); }
|
||||||
QHash<NodePermissionsKey, NodePermissionsPointer> get() { return _data; }
|
std::unordered_map<NodePermissionsKey, NodePermissionsPointer> get() { return _data; }
|
||||||
void clear() { _data.clear(); }
|
void clear() { _data.clear(); }
|
||||||
void remove(const NodePermissionsKey& key) { _data.remove(key); }
|
void remove(const NodePermissionsKey& key) { _data.erase(key); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<NodePermissionsKey, NodePermissionsPointer> _data;
|
std::unordered_map<NodePermissionsKey, NodePermissionsPointer> _data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue