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
qmetatype_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 reason:default
4
5#ifndef QMETATYPE_P_H
6#define QMETATYPE_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 <QtCore/private/qglobal_p.h>
20#include "qmetatype.h"
21
23
24#define QMETATYPE_CONVERTER(To, From, assign_and_return)
25 case makePair(QMetaType::To, QMetaType::From):
26 if constexpr (QMetaType::To == QMetaType::From)
27 Q_UNREACHABLE(); /* can never get here */
28 if (onlyCheck)
29 return true;
30 {
31 const From &source = *static_cast<const From *>(from);
32 To &result = *static_cast<To *>(to);
33 assign_and_return
34 }
35#define QMETATYPE_CONVERTER_ASSIGN(To, From)
36 QMETATYPE_CONVERTER(To, From, result = To(source); return true;)
37
38#define QMETATYPE_CONVERTER_FUNCTION(To, assign_and_return)
39 {
40 To &result = *static_cast<To *>(r);
41 assign_and_return
42 }
43
45{
46 static constexpr auto makePair(int from, int to) -> quint64
47 {
48 return (quint64(from) << 32) + quint64(to);
49 }
50
52 {
53 return nullptr;
54 }
55
56 static bool convert_dummy(const void *, int, void *, int)
57 {
58 return false;
59 }
60
63};
64
65extern Q_CORE_EXPORT QMetaTypeModuleHelper qMetaTypeGuiHelper;
66extern Q_CORE_EXPORT QMetaTypeModuleHelper qMetaTypeWidgetsHelper;
67
68namespace QtMetaTypePrivate {
69template<typename T>
71{
72 static const bool IsAvailable = true;
73};
74
75// Ignore these types, as incomplete
76#ifdef QT_BOOTSTRAPPED
77template<> struct TypeDefinition<qfloat16> { static const bool IsAvailable = false; };
78template<> struct TypeDefinition<QBitArray> { static const bool IsAvailable = false; };
79template<> struct TypeDefinition<QByteArrayList> { static const bool IsAvailable = false; };
80template<> struct TypeDefinition<QCborArray> { static const bool IsAvailable = false; };
81template<> struct TypeDefinition<QCborMap> { static const bool IsAvailable = false; };
82template<> struct TypeDefinition<QCborSimpleType> { static const bool IsAvailable = false; };
83template<> struct TypeDefinition<QCborValue> { static const bool IsAvailable = false; };
84#if QT_CONFIG(easingcurve)
85template<> struct TypeDefinition<QEasingCurve> { static const bool IsAvailable = false; };
86#endif
87template<> struct TypeDefinition<QJsonArray> { static const bool IsAvailable = false; };
88template<> struct TypeDefinition<QJsonDocument> { static const bool IsAvailable = false; };
89template<> struct TypeDefinition<QJsonObject> { static const bool IsAvailable = false; };
90template<> struct TypeDefinition<QJsonValue> { static const bool IsAvailable = false; };
91template<> struct TypeDefinition<QUrl> { static const bool IsAvailable = false; };
92template<> struct TypeDefinition<QUuid> { static const bool IsAvailable = false; };
93template<> struct TypeDefinition<QRect> { static const bool IsAvailable = false; };
94template<> struct TypeDefinition<QRectF> { static const bool IsAvailable = false; };
95template<> struct TypeDefinition<QSize> { static const bool IsAvailable = false; };
96template<> struct TypeDefinition<QSizeF> { static const bool IsAvailable = false; };
97template<> struct TypeDefinition<QLine> { static const bool IsAvailable = false; };
98template<> struct TypeDefinition<QLineF> { static const bool IsAvailable = false; };
99template<> struct TypeDefinition<QPoint> { static const bool IsAvailable = false; };
100template<> struct TypeDefinition<QPointF> { static const bool IsAvailable = false; };
101#endif
102#if !QT_CONFIG(regularexpression)
103template<> struct TypeDefinition<QRegularExpression> { static const bool IsAvailable = false; };
104#endif
105#ifdef QT_NO_CURSOR
106template<> struct TypeDefinition<QCursor> { static const bool IsAvailable = false; };
107#endif
108#ifdef QT_NO_MATRIX4X4
109template<> struct TypeDefinition<QMatrix4x4> { static const bool IsAvailable = false; };
110#endif
111#ifdef QT_NO_VECTOR2D
112template<> struct TypeDefinition<QVector2D> { static const bool IsAvailable = false; };
113#endif
114#ifdef QT_NO_VECTOR3D
115template<> struct TypeDefinition<QVector3D> { static const bool IsAvailable = false; };
116#endif
117#ifdef QT_NO_VECTOR4D
118template<> struct TypeDefinition<QVector4D> { static const bool IsAvailable = false; };
119#endif
120#ifdef QT_NO_QUATERNION
121template<> struct TypeDefinition<QQuaternion> { static const bool IsAvailable = false; };
122#endif
123#ifdef QT_NO_ICON
124template<> struct TypeDefinition<QIcon> { static const bool IsAvailable = false; };
125#endif
126
127template <typename T> inline bool isInterfaceFor(const QtPrivate::QMetaTypeInterface *iface)
128{
129 // typeId for built-in types are fixed and require no registration
130 static_assert(QMetaTypeId2<T>::IsBuiltIn, "This function only works for built-in types");
131 static constexpr int typeId = QtPrivate::BuiltinMetaType<T>::value;
132 return iface->typeId.loadRelaxed() == typeId;
133}
134
135template <typename FPointer>
136inline bool checkMetaTypeFlagOrPointer(const QtPrivate::QMetaTypeInterface *iface, FPointer ptr, QMetaType::TypeFlag Flag)
137{
138 // helper to the isXxxConstructible & isDestructible functions below: a
139 // meta type has the trait if the trait is trivial or we have the pointer
140 // to perform the operation
141 Q_ASSERT(!isInterfaceFor<void>(iface));
142 Q_ASSERT(iface->size);
143 return ptr != nullptr || (iface->flags & Flag) == 0;
144}
145
146inline bool isDefaultConstructible(const QtPrivate::QMetaTypeInterface *iface) noexcept
147{
148 return checkMetaTypeFlagOrPointer(iface, iface->defaultCtr, QMetaType::NeedsConstruction);
149}
150
151inline bool isCopyConstructible(const QtPrivate::QMetaTypeInterface *iface) noexcept
152{
153 return checkMetaTypeFlagOrPointer(iface, iface->copyCtr, QMetaType::NeedsCopyConstruction);
154}
155
156inline bool isMoveConstructible(const QtPrivate::QMetaTypeInterface *iface) noexcept
157{
158 return checkMetaTypeFlagOrPointer(iface, iface->moveCtr, QMetaType::NeedsMoveConstruction);
159}
160
161inline bool isDestructible(const QtPrivate::QMetaTypeInterface *iface) noexcept
162{
163 /* For metatypes of revision 1, the NeedsDestruction was set even for trivially
164 destructible types, but their dtor pointer would be null.
165 For that reason, we need the additional check here.
166 */
167 return iface->revision < 1 ||
168 checkMetaTypeFlagOrPointer(iface, iface->dtor, QMetaType::NeedsDestruction);
169}
170
171inline void defaultConstruct(const QtPrivate::QMetaTypeInterface *iface, void *where)
172{
173 Q_ASSERT(isDefaultConstructible(iface));
174 if (iface->defaultCtr)
175 iface->defaultCtr(iface, where);
176 else
177 memset(where, 0, iface->size);
178}
179
180inline void copyConstruct(const QtPrivate::QMetaTypeInterface *iface, void *where, const void *copy)
181{
182 Q_ASSERT(isCopyConstructible(iface));
183 if (iface->copyCtr)
184 iface->copyCtr(iface, where, copy);
185 else
186 memcpy(where, copy, iface->size);
187}
188
189inline void moveConstruct(const QtPrivate::QMetaTypeInterface *iface, void *where, void *copy)
190{
191 Q_ASSERT(isMoveConstructible(iface));
192 if (iface->moveCtr)
193 iface->moveCtr(iface, where, copy);
194 else
195 memcpy(where, copy, iface->size);
196}
197
198inline void construct(const QtPrivate::QMetaTypeInterface *iface, void *where, const void *copy)
199{
200 if (copy)
201 copyConstruct(iface, where, copy);
202 else
203 defaultConstruct(iface, where);
204}
205
206inline void destruct(const QtPrivate::QMetaTypeInterface *iface, void *where)
207{
208 Q_ASSERT(isDestructible(iface));
209 if (iface->dtor)
210 iface->dtor(iface, where);
211}
212
213const char *typedefNameForType(const QtPrivate::QMetaTypeInterface *type_d);
214
215template<typename T>
223
224#define QT_METATYPE_CONVERT_ID_TO_TYPE(MetaTypeName, MetaTypeId, RealName)
225 case QMetaType::MetaTypeName:
226 return QtMetaTypePrivate::getInterfaceFromType<RealName>();
227
228} //namespace QtMetaTypePrivate
229
230QT_END_NAMESPACE
231
232#endif // QMETATYPE_P_H
QByteArray signature() const
\macro Q_METAMETHOD_INVOKE_MAX_ARGS
\inmodule QtCore
Definition qmetatype.h:383
Combined button and popup list for selecting options.
bool isDestructible(const QtPrivate::QMetaTypeInterface *iface) noexcept
bool isMoveConstructible(const QtPrivate::QMetaTypeInterface *iface) noexcept
bool checkMetaTypeFlagOrPointer(const QtPrivate::QMetaTypeInterface *iface, FPointer ptr, QMetaType::TypeFlag Flag)
bool isDefaultConstructible(const QtPrivate::QMetaTypeInterface *iface) noexcept
bool isCopyConstructible(const QtPrivate::QMetaTypeInterface *iface) noexcept
void defaultConstruct(const QtPrivate::QMetaTypeInterface *iface, void *where)
static const QT_PREPEND_NAMESPACE(QtPrivate::QMetaTypeInterface) *getInterfaceFromType()
void copyConstruct(const QtPrivate::QMetaTypeInterface *iface, void *where, const void *copy)
bool isInterfaceFor(const QtPrivate::QMetaTypeInterface *iface)
void destruct(const QtPrivate::QMetaTypeInterface *iface, void *where)
void construct(const QtPrivate::QMetaTypeInterface *iface, void *where, const void *copy)
void moveConstruct(const QtPrivate::QMetaTypeInterface *iface, void *where, void *copy)
const char * typedefNameForType(const QtPrivate::QMetaTypeInterface *type_d)
static int indexOfSlot_helper(const QMetaObject *m, const char *slot)
static int indexOfMethod_helper(const QMetaObject *m, const char *method)
static QByteArrayView objectClassName(const QMetaObject *m)
static QByteArrayView stringDataView(const QMetaObject *mo, int index)
static bool isScopeMatch(QByteArrayView scope, const QMetaEnum *e)
static QByteArray stringData(const QMetaObject *mo, QByteArrayView view)
#define INDEXOF_COMPAT(what, arg)
static auto parse_scope(QByteArrayView qualifiedKey) noexcept
static const char * trimSpacesFromLeft(QByteArrayView in)
@ MaximumParamCount
static const char * rawStringData(const QMetaObject *mo, int index)
static int indexOfSignal_helper(const QMetaObject *m, const char *signal)
static int typeFromTypeInfo(const QMetaObject *mo, uint typeInfo)
EnumExtendMode
@ Use64Bit
@ SignExtend
@ ZeroExtend
static constexpr bool isEnumValueSuitable(quint64 value, EnumExtendMode mode)
static const QMetaObject * QMetaObject_findMetaObject(const QMetaObject *self, QByteArrayView name)
static int indexOfConstructor_helper(const QMetaObject *mo, const char *constructor)
static const QMetaObjectPrivate * priv(const uint *data)
static const char * qNormalizeType(QByteArrayView in, int &templdepth, QByteArray &result)
static Q_DECL_COLD_FUNCTION bool printMethodNotFoundWarning(const QMetaObject *meta, QByteArrayView name, qsizetype paramCount, const char *const *names, const QtPrivate::QMetaTypeInterface *const *metaTypes)
static QByteArrayView trimSpacesFromRight(QByteArrayView in)
static bool parseEnumFlags(QByteArrayView v, QVarLengthArray< QByteArrayView, 10 > &list)
static QByteArrayView typeNameFromTypeInfo(const QMetaObject *mo, uint typeInfo)
static bool is_ident_char(char s)
static bool is_space(char s)
QVarLengthArray< QArgumentType, 10 > QArgumentTypeArray
#define QT_FOR_EACH_STATIC_PRIMITIVE_NON_VOID_TYPE(F)
Definition qmetatype.h:51
#define QMETATYPE_CONVERTER(To, From, assign_and_return)
Definition qmetatype_p.h:24
static bool checkConnectArgs(const QMetaMethodPrivate *signal, const QMetaMethodPrivate *method)
decltype(&convert_dummy) convert
Definition qmetatype_p.h:62
static const QtPrivate::QMetaTypeInterface * interfaceForType_dummy(int)
Definition qmetatype_p.h:51
static bool convert_dummy(const void *, int, void *, int)
Definition qmetatype_p.h:56
decltype(&interfaceForType_dummy) interfaceForType
Definition qmetatype_p.h:61
static constexpr auto makePair(int from, int to) -> quint64
Definition qmetatype_p.h:46