Cockatrice 2026-09-01-Development-3.1.0-beta.10
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
lazy_properties_hash.h
Go to the documentation of this file.
1#ifndef COCKATRICE_LAZY_PROPERTIES_HASH_H
2#define COCKATRICE_LAZY_PROPERTIES_HASH_H
3
4#include <QHash>
5#include <QMutex>
6
17{
18
19 mutable QByteArray blob;
20 mutable QHash<QString, QString> properties;
21 mutable QMutex propertiesMutex;
22 mutable bool isMaterialized = false;
23
28 void ensureMaterialized() const;
29
30public:
35
40 explicit LazyPropertiesHash(const QByteArray &blob);
41
46 explicit LazyPropertiesHash(const QHash<QString, QString> &properties);
47
48 // Override copy constructor and copy-assignment because mutex isn't copiable
51
57 QString value(const QString &key) const;
58
65 bool insert(const QString &key, const QString &value);
66
71 const QHash<QString, QString> &getProperties() const;
72};
73
74#endif // COCKATRICE_LAZY_PROPERTIES_HASH_H
LazyPropertiesHash()
Default constructor.
Definition lazy_properties_hash.cpp:5
bool isMaterialized
Whether propertiesCache is valid.
Definition lazy_properties_hash.h:22
const QHash< QString, QString > & getProperties() const
Gets a view of the materialized properties hash.
Definition lazy_properties_hash.cpp:91
LazyPropertiesHash & operator=(const LazyPropertiesHash &other)
Definition lazy_properties_hash.cpp:33
QByteArray blob
Serialized properties (load form).
Definition lazy_properties_hash.h:19
QString value(const QString &key) const
Gets the value from the materialized properties hash.
Definition lazy_properties_hash.cpp:73
QMutex propertiesMutex
Guards lazy materialization.
Definition lazy_properties_hash.h:21
void ensureMaterialized() const
Materializes properties from blob if not already done. Clears blob afterward. Safe to call from const...
Definition lazy_properties_hash.cpp:54
QHash< QString, QString > properties
Materialized properties (query form).
Definition lazy_properties_hash.h:20
bool insert(const QString &key, const QString &value)
Inserts a value into the materialized properties hash.
Definition lazy_properties_hash.cpp:79