swift
Loading...
Searching...
No Matches
valuecacheprivate.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_MISC_VALUECACHE_PRIVATE_H
7#define SWIFT_MISC_VALUECACHE_PRIVATE_H
8
9#include <QMap>
10#include <QObject>
11
12#include "misc/statusmessage.h"
13#include "misc/variantmap.h"
14
15namespace swift::misc
16{
17 class CIdentifier;
18 class CValueCache;
20
21 namespace private_ns
22 {
23
28 template <typename T>
29 struct TClassOfPointerToMember
30 {
31 using type = QObject;
32 };
34 template <typename T, typename M>
35 struct TClassOfPointerToMember<M T::*>
36 {
37 using type = T;
38 };
40
44 template <typename T, typename... Args>
45 void reconstruct(T *object, Args &&...args)
46 {
47 object->~T();
48 new (object) T(std::forward<Args>(args)...);
49 }
50
56 class SWIFT_MISC_EXPORT CValuePage : public QObject
57 {
58 Q_OBJECT
59
60 public:
62 static const QStringList &getLogCategories();
63
65 static CValuePage &getPageFor(QObject *parent, CValueCache *cache);
66
68 struct Element;
69
71 using Validator = std::function<bool(const CVariant &, QString &)>;
72
74 using NotifySlot = std::pair<std::function<void(QObject *)>, void (QObject::*)()>;
75
82 Element &createElement(const QString &key, const QString &name, int metaType, const Validator &validator,
83 const CVariant &defaultValue);
84
86 void setNotifySlot(Element &element, const NotifySlot &slot);
87
89 bool isInitialized(const Element &element) const;
90
93 bool isValid(const Element &element, int typeId) const;
94
96 const CVariant &getValue(const Element &element) const;
97
100 CVariant getValueCopy(const Element &element) const;
101
103 CStatusMessage setValue(Element &element, CVariant value, qint64 timestamp, bool save = false);
104
106 const QString &getKey(const Element &element) const;
107
109 qint64 getTimestamp(const Element &element) const;
110
112 bool isSaved(const Element &element) const;
113
115 bool isSaving(const Element &element) const;
116
122 void setValuesFromCache(const swift::misc::CValueCachePacket &values, QObject *changedBy);
123
125 void beginBatch();
126
128 void abandonBatch();
129
131 void endBatch();
132
133 signals:
136 void valuesWantToCache(const swift::misc::CValueCachePacket &values);
137
138 private:
139 using ElementPtr = QSharedPointer<Element>; // QMap doesn't support move-only types
140
141 CValueCache *m_cache = nullptr;
142 QMap<QString, ElementPtr> m_elements;
143 int m_batchMode = 0;
144 CVariantMap m_batchedValues;
145
146 CValuePage(QObject *parent, CValueCache *cache);
147 CStatusMessage validate(const Element &element, const CVariant &value,
148 CStatusMessage::StatusSeverity invalidSeverity) const;
149 };
150
151 } // namespace private_ns
152
153} // namespace swift::misc
154
155#endif // SWIFT_MISC_VALUECACHE_PRIVATE_H
Value object encapsulating information identifying a component of a modular distributed swift process...
Definition identifier.h:29
Manages a map of { QString, CVariant } pairs, which can be distributed among multiple processes.
Definition valuecache.h:154
Value class used for signalling changed values in the cache.
Definition valuecache.h:67
Free functions in swift::misc.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.