Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qmetatypesjsonprocessor_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef METATYPESJSONPROCESSOR_P_H
5#define METATYPESJSONPROCESSOR_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qcbormap.h>
19#include <QtCore/qstring.h>
20#include <QtCore/qtyperevision.h>
21#include <QtCore/qvarlengtharray.h>
22#include <QtCore/qvector.h>
23
24QT_BEGIN_NAMESPACE
25
26// With all the QAnyStringViews in this file we rely on the Cbor data to stay
27// in place if you don't change the Cbor contents. We assume that Cbor data
28// is implicitly shared so that merely copying const Cbor objects does not copy
29// the contents.
30
31enum class Access { Public, Protected, Private };
32
34{
36
37 BaseType() = default;
38 BaseType(const QCborMap &cbor);
39
41 Access access;
42};
43
45{
47
48 ClassInfo() = default;
49 ClassInfo(const QCborMap &cbor);
50
53};
54
56{
58
59 Interface() = default;
60 Interface(const QCborValue &cbor);
61
63};
64
92
94{
96
97 Argument() = default;
98 Argument(const QCborMap &cbor);
99
102};
103
104struct Method
105{
107 static constexpr int InvalidIndex = std::numeric_limits<int>::min();
108
109 Method() = default;
110 Method(const QCborMap &cbor, bool isConstructor);
111
113
116
118
120
121 Access access = Access::Public;
122
123 bool isCloned = false;
125 bool isConstructor = false;
126};
127
128struct Enum
129{
131
132 Enum() = default;
133 Enum(const QCborMap &cbor);
134
138
140
141 bool isFlag = false;
142 bool isClass = false;
143};
144
174
176{
177public:
179
180 MetaType() = default;
181 MetaType(const QCborMap &cbor, const QString &inputFile);
182
183 bool isEmpty() const { return d == &s_empty; }
184
185 QString inputFile() const { return d->inputFile; }
186 int lineNumber() const { return d->lineNumber; }
187 QAnyStringView className() const { return d->className; }
188 QAnyStringView qualifiedClassName() const { return d->qualifiedClassName; }
189 const BaseType::Container &superClasses() const { return d->superClasses; }
190 const ClassInfo::Container &classInfos() const { return d->classInfos; }
191 const Interface::Container &ifaces() const { return d->ifaces; }
192
193 const Property::Container &properties() const { return d->properties; }
194 const Method::Container &methods() const { return d->methods; }
195 const Method::Container &sigs() const { return d->sigs; }
196 const Method::Container &constructors() const { return d->constructors; }
197
198 const Enum::Container &enums() const { return d->enums; }
199
200 Kind kind() const { return d->kind; }
201
202private:
203 friend bool operator==(const MetaType &a, const MetaType &b) noexcept
204 {
205 return a.d == b.d;
206 }
207
208 friend bool operator!=(const MetaType &a, const MetaType &b) noexcept
209 {
210 return !(a == b);
211 }
212
213 static const MetaTypePrivate s_empty;
214 const MetaTypePrivate *d = &s_empty;
215};
216
220
221 bool isValid() const { return !alias.isEmpty() && !original.isEmpty(); }
222private:
223 friend bool comparesEqual(const UsingDeclaration &a, const UsingDeclaration &b) noexcept
224 {
225 return std::tie(a.alias, a.original) == std::tie(b.alias, b.original);
226 }
227
229 const UsingDeclaration &a, const UsingDeclaration &b) noexcept
230 {
231 return a.alias != b.alias
232 ? compareThreeWay(a.alias, b.alias)
233 : compareThreeWay(a.original, b.original);
234 }
236};
237
239{
240public:
241 static QList<QAnyStringView> namespaces(const MetaType &classDef);
242
243 MetaTypesJsonProcessor(bool privateIncludes) : m_privateIncludes(privateIncludes) {}
244
245 bool processTypes(const QStringList &files);
246
247 bool processForeignTypes(const QString &foreignTypesFile);
248 bool processForeignTypes(const QStringList &foreignTypesFiles);
249
250 void postProcessTypes();
252
253 QVector<MetaType> types() const { return m_types; }
254 QVector<MetaType> foreignTypes() const { return m_foreignTypes; }
255 QList<QAnyStringView> referencedTypes() const { return m_referencedTypes; }
256 QList<UsingDeclaration> usingDeclarations() const { return m_usingDeclarations; }
257 QList<QString> includes() const { return m_includes; }
258
260
261private:
262 enum RegistrationMode {
263 NoRegistration,
264 ObjectRegistration,
265 GadgetRegistration,
266 NamespaceRegistration
267 };
268
269 struct PreProcessResult {
270 QList<QAnyStringView> primitiveAliases;
271 UsingDeclaration usingDeclaration;
272 QAnyStringView foreignPrimitive;
273 RegistrationMode mode;
274 };
275
276 enum class PopulateMode { No, Yes };
277 static PreProcessResult preProcess(const MetaType &classDef, PopulateMode populateMode);
278 void addRelatedTypes();
279
280 void sortTypes(QVector<MetaType> &types);
281 QString resolvedInclude(QAnyStringView include);
282 void processTypes(const QCborMap &types);
283 void processForeignTypes(const QCborMap &types);
284
285 bool isPrimitive(QAnyStringView type) const
286 {
287 return std::binary_search(m_primitiveTypes.begin(), m_primitiveTypes.end(), type);
288 }
289
290 QList<QString> m_includes;
291 QList<QAnyStringView> m_referencedTypes;
292 QList<QAnyStringView> m_primitiveTypes;
293 QList<UsingDeclaration> m_usingDeclarations;
294 QVector<MetaType> m_types;
295 QVector<MetaType> m_foreignTypes;
296 bool m_privateIncludes = false;
297};
298
299QT_END_NAMESPACE
300
301#endif // METATYPESJSONPROCESSOR_P_H
const Method::Container & constructors() const
const Enum::Container & enums() const
QAnyStringView qualifiedClassName() const
const Method::Container & sigs() const
const Method::Container & methods() const
const ClassInfo::Container & classInfos() const
friend bool operator!=(const MetaType &a, const MetaType &b) noexcept
const BaseType::Container & superClasses() const
MetaType()=default
QAnyStringView className() const
QString inputFile() const
const Interface::Container & ifaces() const
const Property::Container & properties() const
MetaType(const QCborMap &cbor, const QString &inputFile)
friend bool operator==(const MetaType &a, const MetaType &b) noexcept
bool processForeignTypes(const QString &foreignTypesFile)
static QList< QAnyStringView > namespaces(const MetaType &classDef)
QList< QString > includes() const
bool processTypes(const QStringList &files)
QList< UsingDeclaration > usingDeclarations() const
QVector< MetaType > foreignTypes() const
QList< QAnyStringView > referencedTypes() const
QVector< MetaType > types() const
MetaTypesJsonProcessor(bool privateIncludes)
Combined button and popup list for selecting options.
static Access getAccess(const QCborMap &cbor)
static QCborValue fromJson(const QByteArray &json, QJsonParseError *error)
static QLatin1StringView typeRelationString(TypeRelation relation)
static void sortStringList(QList< String > *list)
static QTypeRevision getRevision(const QCborMap &cbor)
static bool qualifiedClassNameLessThan(const MetaType &a, const MetaType &b)
static size_t qHash(QAnyStringView string, size_t seed=0)
QDebug warning(const MetaType &classDef)
QAnyStringView name
Argument(const QCborMap &cbor)
Argument()=default
QAnyStringView type
BaseType()=default
QAnyStringView name
BaseType(const QCborMap &cbor)
ClassInfo()=default
QAnyStringView value
QAnyStringView name
ClassInfo(const QCborMap &cbor)
QAnyStringView alias
QAnyStringView name
QList< QAnyStringView > values
Enum(const QCborMap &cbor)
Enum()=default
QAnyStringView type
Interface(const QCborValue &cbor)
QAnyStringView className
Interface()=default
MetaTypePrivate()=default
MetaTypePrivate(const QCborMap &cbor, const QString &inputFile)
ClassInfo::Container classInfos
BaseType::Container superClasses
Property::Container properties
Interface::Container ifaces
QAnyStringView qualifiedClassName
Method::Container constructors
QAnyStringView name
Method()=default
QAnyStringView returnType
Argument::Container arguments
Method(const QCborMap &cbor, bool isConstructor)
QTypeRevision revision
static constexpr int InvalidIndex
QAnyStringView write
QAnyStringView notify
QAnyStringView read
QAnyStringView privateClass
Property(const QCborMap &cbor)
QAnyStringView name
QAnyStringView member
QAnyStringView type
Property()=default
QAnyStringView reset
QAnyStringView bindable
QTypeRevision revision
friend bool comparesEqual(const UsingDeclaration &a, const UsingDeclaration &b) noexcept
friend Qt::strong_ordering compareThreeWay(const UsingDeclaration &a, const UsingDeclaration &b) noexcept