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
qqmltypemodule_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
4
5#ifndef QQMLTYPEMODULE_P_H
6#define QQMLTYPEMODULE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQml/qtqmlglobal.h>
20#include <QtQml/private/qstringhash_p.h>
21#include <QtQml/private/qqmltype_p.h>
22#include <QtCore/qmutex.h>
23#include <QtCore/qstring.h>
24#include <QtCore/qversionnumber.h>
25
26#include <functional>
27
28QT_BEGIN_NAMESPACE
29
30class QQmlType;
31class QQmlTypePrivate;
32struct QQmlMetaTypeData;
33
34namespace QV4 {
35struct String;
36}
37
39{
40public:
41 enum class LockLevel {
42 Open = 0,
43 Weak = 1,
45 };
46
47 QQmlTypeModule() = default;
48 QQmlTypeModule(const QString &uri, quint8 majorVersion)
50 {}
51
52 void add(QQmlTypePrivate *);
53 void remove(const QQmlTypePrivate *type);
54
55 LockLevel lockLevel() const { return LockLevel(m_lockLevel.loadRelaxed()); }
57 {
58 while (true) {
59 const int currentLock = m_lockLevel.loadAcquire();
60 if (currentLock > int(mode))
61 return false;
62 if (currentLock == int(mode) || m_lockLevel.testAndSetRelease(currentLock, int(mode)))
63 return true;
64 }
65 }
66
68 {
69 // No need to lock. m_module is const
70 return m_module;
71 }
72
74 {
75 // No need to lock. d->majorVersion is const
76 return m_majorVersion;
77 }
78
79 void addMinorVersion(quint8 minorVersion);
80 quint8 minimumMinorVersion() const { return m_minMinorVersion.loadRelaxed(); }
81 quint8 maximumMinorVersion() const { return m_maxMinorVersion.loadRelaxed(); }
82
83 QQmlType type(const QHashedStringRef &name, QTypeRevision version) const
84 {
85 QMutexLocker lock(&m_mutex);
86 return findType(m_typeHash.value(name), version);
87 }
88
89 QQmlType type(const QV4::String *name, QTypeRevision version) const
90 {
91 QMutexLocker lock(&m_mutex);
92 return findType(m_typeHash.value(name), version);
93 }
94
95 void walkCompositeSingletons(const std::function<void(const QQmlType &)> &callback) const;
96
97private:
98 static Q_QML_EXPORT QQmlType findType(
100
101 const QString m_module;
102 const quint8 m_majorVersion = 0;
103
104 // Can only ever decrease
105 QAtomicInt m_minMinorVersion = std::numeric_limits<quint8>::max();
106
107 // Can only ever increase
108 QAtomicInt m_maxMinorVersion = 0;
109
110 // LockLevel. Can only be increased.
111 QAtomicInt m_lockLevel = int(LockLevel::Open);
112
114 TypeHash m_typeHash;
115
116 mutable QMutex m_mutex;
117};
118
119QT_END_NAMESPACE
120
121#endif // QQMLTYPEMODULE_P_H
bool setLockLevel(LockLevel mode)
LockLevel lockLevel() const
quint8 majorVersion() const
QQmlType type(const QV4::String *name, QTypeRevision version) const
void walkCompositeSingletons(const std::function< void(const QQmlType &)> &callback) const
QQmlTypeModule()=default
void remove(const QQmlTypePrivate *type)
QString module() const
QQmlTypeModule(const QString &uri, quint8 majorVersion)
quint8 minimumMinorVersion() const
quint8 maximumMinorVersion() const
QQmlType type(const QHashedStringRef &name, QTypeRevision version) const
void addMinorVersion(quint8 minorVersion)
void add(QQmlTypePrivate *)
Combined button and popup list for selecting options.
Definition qjsvalue.h:24