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