Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 (onlyCheck) \
26 return true; \
27 { \
28 const From &source = *static_cast<const From *>(from); \
29 To &result = *static_cast<To *>(to); \
30 assign_and_return \
31 }
32#define QMETATYPE_CONVERTER_ASSIGN(To, From) \
33 QMETATYPE_CONVERTER(To, From, result = To(source); return true;)
34
35#define QMETATYPE_CONVERTER_FUNCTION(To, assign_and_return) \
36 { \
37 To &result = *static_cast<To *>(r); \
38 assign_and_return \
39 }
40
41class Q_CORE_EXPORT QMetaTypeModuleHelper
42{
43 Q_DISABLE_COPY_MOVE(QMetaTypeModuleHelper)
44protected:
47public:
48 Q_WEAK_OVERLOAD // prevent it from entering the ABI and rendering constexpr useless
49 static constexpr auto makePair(int from, int to) -> quint64
50 {
51 return (quint64(from) << 32) + quint64(to);
52 }
53
54 virtual const QtPrivate::QMetaTypeInterface *interfaceForType(int) const = 0;
55 virtual bool convert(const void *, int, void *, int) const;
56};
57
58extern Q_CORE_EXPORT const QMetaTypeModuleHelper *qMetaTypeGuiHelper;
59extern Q_CORE_EXPORT const QMetaTypeModuleHelper *qMetaTypeWidgetsHelper;
60
61namespace QtMetaTypePrivate {
62template<typename T>
64{
65 static const bool IsAvailable = true;
66};
67
68// Ignore these types, as incomplete
69#ifdef QT_BOOTSTRAPPED
70template<> struct TypeDefinition<QBitArray> { static const bool IsAvailable = false; };
71template<> struct TypeDefinition<QCborArray> { static const bool IsAvailable = false; };
72template<> struct TypeDefinition<QCborMap> { static const bool IsAvailable = false; };
73template<> struct TypeDefinition<QCborSimpleType> { static const bool IsAvailable = false; };
74template<> struct TypeDefinition<QCborValue> { static const bool IsAvailable = false; };
75#if QT_CONFIG(easingcurve)
76template<> struct TypeDefinition<QEasingCurve> { static const bool IsAvailable = false; };
77#endif
78template<> struct TypeDefinition<QJsonArray> { static const bool IsAvailable = false; };
79template<> struct TypeDefinition<QJsonDocument> { static const bool IsAvailable = false; };
80template<> struct TypeDefinition<QJsonObject> { static const bool IsAvailable = false; };
81template<> struct TypeDefinition<QJsonValue> { static const bool IsAvailable = false; };
82template<> struct TypeDefinition<QUrl> { static const bool IsAvailable = false; };
83template<> struct TypeDefinition<QByteArrayList> { static const bool IsAvailable = false; };
84#endif
85#ifdef QT_NO_GEOM_VARIANT
86template<> struct TypeDefinition<QRect> { static const bool IsAvailable = false; };
87template<> struct TypeDefinition<QRectF> { static const bool IsAvailable = false; };
88template<> struct TypeDefinition<QSize> { static const bool IsAvailable = false; };
89template<> struct TypeDefinition<QSizeF> { static const bool IsAvailable = false; };
90template<> struct TypeDefinition<QLine> { static const bool IsAvailable = false; };
91template<> struct TypeDefinition<QLineF> { static const bool IsAvailable = false; };
92template<> struct TypeDefinition<QPoint> { static const bool IsAvailable = false; };
93template<> struct TypeDefinition<QPointF> { static const bool IsAvailable = false; };
94#endif
95#if !QT_CONFIG(regularexpression)
96template<> struct TypeDefinition<QRegularExpression> { static const bool IsAvailable = false; };
97#endif
98#ifdef QT_NO_CURSOR
99template<> struct TypeDefinition<QCursor> { static const bool IsAvailable = false; };
100#endif
101#ifdef QT_NO_MATRIX4X4
102template<> struct TypeDefinition<QMatrix4x4> { static const bool IsAvailable = false; };
103#endif
104#ifdef QT_NO_VECTOR2D
105template<> struct TypeDefinition<QVector2D> { static const bool IsAvailable = false; };
106#endif
107#ifdef QT_NO_VECTOR3D
108template<> struct TypeDefinition<QVector3D> { static const bool IsAvailable = false; };
109#endif
110#ifdef QT_NO_VECTOR4D
111template<> struct TypeDefinition<QVector4D> { static const bool IsAvailable = false; };
112#endif
113#ifdef QT_NO_QUATERNION
114template<> struct TypeDefinition<QQuaternion> { static const bool IsAvailable = false; };
115#endif
116#ifdef QT_NO_ICON
117template<> struct TypeDefinition<QIcon> { static const bool IsAvailable = false; };
118#endif
119
120template <typename T> inline bool isInterfaceFor(const QtPrivate::QMetaTypeInterface *iface)
121{
122 // typeId for built-in types are fixed and require no registration
123 static_assert(QMetaTypeId2<T>::IsBuiltIn, "This function only works for built-in types");
124 static constexpr int typeId = QtPrivate::BuiltinMetaType<T>::value;
125 return iface->typeId.loadRelaxed() == typeId;
126}
127
128template <typename FPointer>
130{
131 // helper to the isXxxConstructible & isDestructible functions below: a
132 // meta type has the trait if the trait is trivial or we have the pointer
133 // to perform the operation
134 Q_ASSERT(!isInterfaceFor<void>(iface));
135 Q_ASSERT(iface->size);
136 return ptr != nullptr || (iface->flags & Flag) == 0;
137}
138
140{
141 return checkMetaTypeFlagOrPointer(iface, iface->defaultCtr, QMetaType::NeedsConstruction);
142}
143
144inline bool isCopyConstructible(const QtPrivate::QMetaTypeInterface *iface) noexcept
145{
147}
148
149inline bool isMoveConstructible(const QtPrivate::QMetaTypeInterface *iface) noexcept
150{
152}
153
154inline bool isDestructible(const QtPrivate::QMetaTypeInterface *iface) noexcept
155{
156 /* For metatypes of revision 1, the NeedsDestruction was set even for trivially
157 destructible types, but their dtor pointer would be null.
158 For that reason, we need the additional check here.
159 */
160 return iface->revision < 1 ||
162}
163
164inline void defaultConstruct(const QtPrivate::QMetaTypeInterface *iface, void *where)
165{
167 if (iface->defaultCtr)
168 iface->defaultCtr(iface, where);
169 else
170 memset(where, 0, iface->size);
171}
172
173inline void copyConstruct(const QtPrivate::QMetaTypeInterface *iface, void *where, const void *copy)
174{
176 if (iface->copyCtr)
177 iface->copyCtr(iface, where, copy);
178 else
179 memcpy(where, copy, iface->size);
180}
181
182inline void moveConstruct(const QtPrivate::QMetaTypeInterface *iface, void *where, void *copy)
183{
185 if (iface->moveCtr)
186 iface->moveCtr(iface, where, copy);
187 else
188 memcpy(where, copy, iface->size);
189}
190
191inline void construct(const QtPrivate::QMetaTypeInterface *iface, void *where, const void *copy)
192{
193 if (copy)
194 copyConstruct(iface, where, copy);
195 else
196 defaultConstruct(iface, where);
197}
198
199inline void destruct(const QtPrivate::QMetaTypeInterface *iface, void *where)
200{
201 Q_ASSERT(isDestructible(iface));
202 if (iface->dtor)
203 iface->dtor(iface, where);
204}
205
206const char *typedefNameForType(const QtPrivate::QMetaTypeInterface *type_d);
207
208template<typename T>
209static const QT_PREPEND_NAMESPACE(QtPrivate::QMetaTypeInterface) *getInterfaceFromType()
210{
212 return &QT_PREPEND_NAMESPACE(QtPrivate::QMetaTypeInterfaceWrapper)<T>::metaType;
213 }
214 return nullptr;
215}
216
217#define QT_METATYPE_CONVERT_ID_TO_TYPE(MetaTypeName, MetaTypeId, RealName) \
218 case QMetaType::MetaTypeName: \
219 return QtMetaTypePrivate::getInterfaceFromType<RealName>();
220
221} //namespace QtMetaTypePrivate
222
224
225#endif // QMETATYPE_P_H
\inmodule QtCore
Definition qbitarray.h:13
\inmodule QtCore
\inmodule QtCore\reentrant
Definition qcborarray.h:20
\inmodule QtCore\reentrant
Definition qcbormap.h:21
\inmodule QtCore\reentrant
Definition qcborvalue.h:47
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition qcursor.h:45
\inmodule QtCore
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
\inmodule QtCore\reentrant
Definition qjsonarray.h:18
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
Definition qjsonobject.h:20
\inmodule QtCore\reentrant
Definition qjsonvalue.h:25
\inmodule QtCore\compares equality \compareswith equality QLine \endcompareswith
Definition qline.h:192
\inmodule QtCore\compares equality \compareswith equality QLineF \endcompareswith
Definition qline.h:18
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
static Q_WEAK_OVERLOAD constexpr auto makePair(int from, int to) -> quint64
Definition qmetatype_p.h:49
QMetaTypeModuleHelper()=default
~QMetaTypeModuleHelper()=default
virtual const QtPrivate::QMetaTypeInterface * interfaceForType(int) const =0
TypeFlag
The enum describes attributes of a type supported by QMetaType.
Definition qmetatype.h:399
@ NeedsDestruction
Definition qmetatype.h:401
@ NeedsCopyConstruction
Definition qmetatype.h:418
@ NeedsMoveConstruction
Definition qmetatype.h:419
@ NeedsConstruction
Definition qmetatype.h:400
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qpoint.h:25
The QQuaternion class represents a quaternion consisting of a vector and scalar.
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtCore \reentrant
\inmodule QtCore
Definition qsize.h:208
\inmodule QtCore
Definition qsize.h:25
\inmodule QtCore
Definition qurl.h:94
The QVector2D class represents a vector or vertex in 2D space.
Definition qvectornd.h:31
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
The QVector4D class represents a vector or vertex in 4D space.
Definition qvectornd.h:330
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)
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 jboolean copy(JNIEnv *, jobject)
QCborSimpleType
Definition qcborcommon.h:23
#define Q_WEAK_OVERLOAD
static ControlElement< T > * ptr(QWidget *widget)
Q_CORE_EXPORT const QMetaTypeModuleHelper * qMetaTypeWidgetsHelper
Q_CORE_EXPORT const QMetaTypeModuleHelper * qMetaTypeGuiHelper
static constexpr To convert(const std::array< Mapping, N > &mapping, From Mapping::*from, To Mapping::*to, From value, To defaultValue)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
unsigned long long quint64
Definition qtypes.h:61