swift
variantmap.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_VARIANTMAP_H
7 #define SWIFT_MISC_VARIANTMAP_H
8 
9 #include <initializer_list>
10 #include <utility>
11 
12 #include <QJsonObject>
13 #include <QMap>
14 #include <QMetaType>
15 #include <QString>
16 
17 #include "misc/dictionary.h"
18 #include "misc/mixin/mixinhash.h"
19 #include "misc/swiftmiscexport.h"
20 #include "misc/variant.h"
21 
22 namespace swift::misc
23 {
24 
25  class CStatusMessageList;
26 
33  public CDictionary<QString, CVariant, QMap>,
34  public mixin::MetaType<CVariantMap>
35  {
36  public:
39 
42 
44  CVariantMap(const CVariantMap &) = default;
45 
47  CVariantMap(CVariantMap &&other) noexcept : CDictionary(std::move(other)) {}
48 
51  {
53  return *this;
54  }
55 
57  CVariantMap &operator=(CVariantMap &&other) noexcept
58  {
59  CDictionary::operator=(std::move(other));
60  return *this;
61  }
62 
64  ~CVariantMap() = default;
65 
67  QJsonObject &mergeToJson(QJsonObject &json) const;
68 
70  QJsonObject toJson() const;
71 
73  void convertFromJson(const QJsonObject &json);
74 
77  void convertFromJson(const QJsonObject &json, const QStringList &keys);
78 
80  CStatusMessageList convertFromJsonNoThrow(const QJsonObject &json, const CLogCategoryList &categories,
81  const QString &prefix);
82 
84  CStatusMessageList convertFromJsonNoThrow(const QJsonObject &json, const QStringList &keys,
85  const CLogCategoryList &categories, const QString &prefix);
86 
88  QJsonObject &mergeToMemoizedJson(QJsonObject &json) const;
89 
91  QJsonObject toMemoizedJson() const;
92 
94  void convertFromMemoizedJson(const QJsonObject &json);
95 
98  void convertFromMemoizedJson(const QJsonObject &json, const QStringList &keys);
99 
101  CStatusMessageList convertFromMemoizedJsonNoThrow(const QJsonObject &json, const CLogCategoryList &categories,
102  const QString &prefix);
103 
105  CStatusMessageList convertFromMemoizedJsonNoThrow(const QJsonObject &json, const QStringList &keys,
106  const CLogCategoryList &categories, const QString &prefix);
107  };
108 
109 } // namespace swift::misc
110 
111 Q_DECLARE_METATYPE(swift::misc::CVariantMap)
112 
113 #endif // SWIFT_MISC_VARIANTMAP_H
Associative container with value semantics, chooses a sensible default implementation container type.
Definition: dictionary.h:83
CDictionary & operator=(const CDictionary &other)
Copy assignment.
Definition: dictionary.h:413
CDictionary()
Default constructor.
Definition: dictionary.h:281
A sequence of log categories.
Status messages, e.g. from Core -> GUI.
Map of { QString, CVariant } pairs.
Definition: variantmap.h:35
CVariantMap & operator=(CVariantMap &&other) noexcept
Move assignment operator.
Definition: variantmap.h:57
CVariantMap(const CVariantMap &)=default
Copy constructor.
CVariantMap()
Default constructor.
Definition: variantmap.h:41
~CVariantMap()=default
Destructor.
CVariantMap & operator=(const CVariantMap &other)
Copy assignment operator.
Definition: variantmap.h:50
CVariantMap(CVariantMap &&other) noexcept
Move constructor.
Definition: variantmap.h:47
CRTP class template from which a derived class can inherit common methods dealing with the metatype o...
Definition: mixinmetatype.h:29
#define SWIFT_MISC_DECLARE_USING_MIXIN_METATYPE(DERIVED)
When a derived class and a base class both inherit from mixin::MetaType, the derived class uses this ...
Free functions in swift::misc.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.