Remove duplicated template code.
[profile/ivi/qtbase.git] / src / corelib / kernel / qmetatype_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QMETATYPE_P_H
43 #define QMETATYPE_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include "qmetatype.h"
57
58 QT_BEGIN_NAMESPACE
59
60 namespace QModulesPrivate {
61 enum Names { Core, Gui, Widgets, Unknown, ModulesCount /* ModulesCount has to be at the end */ };
62
63 static inline int moduleForType(const int typeId)
64 {
65     if (typeId <= QMetaType::LastCoreType)
66         return Core;
67     if (typeId <= QMetaType::LastGuiType)
68         return Gui;
69     if (typeId <= QMetaType::LastWidgetsType)
70         return Widgets;
71     return Unknown;
72 }
73 }
74
75 template <typename T>
76 class QTypeModuleInfo
77 {
78 public:
79     enum Module {
80         IsCore = !QTypeInfo<T>::isComplex, // Primitive types are in Core
81         IsWidget = false,
82         IsGui = false,
83         IsUnknown = !IsCore
84     };
85 };
86
87 #define QT_ASSIGN_TYPE_TO_MODULE(TYPE, MODULE) \
88 template<> \
89 class QTypeModuleInfo<TYPE > \
90 { \
91 public: \
92     enum Module { \
93         IsCore = (((MODULE) == (QModulesPrivate::Core))), \
94         IsWidget = (((MODULE) == (QModulesPrivate::Widgets))), \
95         IsGui = (((MODULE) == (QModulesPrivate::Gui))), \
96         IsUnknown = !(IsCore || IsWidget || IsGui) \
97     }; \
98     static inline int module() { return MODULE; } \
99     Q_STATIC_ASSERT((IsUnknown && !(IsCore || IsWidget || IsGui)) \
100                  || (IsCore && !(IsUnknown || IsWidget || IsGui)) \
101                  || (IsWidget && !(IsUnknown || IsCore || IsGui)) \
102                  || (IsGui && !(IsUnknown || IsCore || IsWidget))); \
103 };
104
105
106 #define QT_DECLARE_CORE_MODULE_TYPES_ITER(TypeName, TypeId, Name) \
107     QT_ASSIGN_TYPE_TO_MODULE(Name, QModulesPrivate::Core);
108 #define QT_DECLARE_GUI_MODULE_TYPES_ITER(TypeName, TypeId, Name) \
109     QT_ASSIGN_TYPE_TO_MODULE(Name, QModulesPrivate::Gui);
110 #define QT_DECLARE_WIDGETS_MODULE_TYPES_ITER(TypeName, TypeId, Name) \
111     QT_ASSIGN_TYPE_TO_MODULE(Name, QModulesPrivate::Widgets);
112
113 QT_FOR_EACH_STATIC_CORE_CLASS(QT_DECLARE_CORE_MODULE_TYPES_ITER)
114 QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_DECLARE_CORE_MODULE_TYPES_ITER)
115 QT_FOR_EACH_STATIC_GUI_CLASS(QT_DECLARE_GUI_MODULE_TYPES_ITER)
116 QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_DECLARE_WIDGETS_MODULE_TYPES_ITER)
117
118 #undef QT_DECLARE_CORE_MODULE_TYPES_ITER
119 #undef QT_DECLARE_GUI_MODULE_TYPES_ITER
120 #undef QT_DECLARE_WIDGETS_MODULE_TYPES_ITER
121
122 class QMetaTypeInterface
123 {
124 public:
125     QMetaType::Creator creator;
126     QMetaType::Deleter deleter;
127     QMetaType::SaveOperator saveOp;
128     QMetaType::LoadOperator loadOp;
129     QMetaType::Constructor constructor;
130     QMetaType::Destructor destructor;
131     int size;
132     quint32 flags; // same as QMetaType::TypeFlags
133 };
134
135 #ifndef QT_NO_DATASTREAM
136 #  define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
137     /*saveOp*/(qMetaTypeSaveHelper<Type>), \
138     /*loadOp*/(qMetaTypeLoadHelper<Type>),
139 #  define QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type) \
140     /*saveOp*/ 0, \
141     /*loadOp*/ 0,
142 #else
143 #  define QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type) \
144     /*saveOp*/ 0, \
145     /*loadOp*/ 0,
146 #  define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
147     QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type)
148 #endif
149
150 #define QT_METATYPE_INTERFACE_INIT_IMPL(Type, DATASTREAM_DELEGATE) \
151 { \
152     /*creator*/(qMetaTypeCreateHelper<Type>), \
153     /*deleter*/(qMetaTypeDeleteHelper<Type>), \
154     DATASTREAM_DELEGATE(Type) \
155     /*constructor*/(qMetaTypeConstructHelper<Type>), \
156     /*destructor*/(qMetaTypeDestructHelper<Type>), \
157     /*size*/(QTypeInfo<Type>::sizeOf), \
158     /*flags*/QtPrivate::QMetaTypeTypeFlags<Type>::Flags \
159 }
160
161
162 /* These  QT_METATYPE_INTERFACE_INIT* macros are used to initialize QMetaTypeInterface instance.
163
164  - QT_METATYPE_INTERFACE_INIT(Type) -> It takes Type argument and creates all necessary wrapper functions for the Type,
165    it detects if QT_NO_DATASTREAM was defined. Probably it is the macro that you want to use.
166
167  - QT_METATYPE_INTERFACE_INIT_EMPTY() -> It initializes an empty QMetaTypeInterface instance.
168
169  - QT_METATYPE_INTERFACE_INIT_NO_DATASTREAM(Type) -> Temporary workaround for missing auto-detection of data stream
170    operators. It creates same instance as QT_METATYPE_INTERFACE_INIT(Type) but with null stream operators callbacks.
171  */
172 #define QT_METATYPE_INTERFACE_INIT(Type) QT_METATYPE_INTERFACE_INIT_IMPL(Type, QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL)
173 #define QT_METATYPE_INTERFACE_INIT_NO_DATASTREAM(Type) QT_METATYPE_INTERFACE_INIT_IMPL(Type, QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL)
174 #define QT_METATYPE_INTERFACE_INIT_EMPTY() \
175 { \
176     /*creator*/ 0, \
177     /*deleter*/ 0, \
178     QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL() \
179     /*constructor*/ 0, \
180     /*destructor*/ 0, \
181     /*size*/ 0, \
182     /*flags*/ 0 \
183 }
184
185 namespace QtMetaTypePrivate {
186 template<typename T>
187 struct TypeDefinition {
188     static const bool IsAvailable = true;
189 };
190
191 // Ignore these types, as incomplete
192 #ifdef QT_BOOTSTRAPPED
193 template<> struct TypeDefinition<QBitArray> { static const bool IsAvailable = false; };
194 template<> struct TypeDefinition<QEasingCurve> { static const bool IsAvailable = false; };
195 template<> struct TypeDefinition<QJsonArray> { static const bool IsAvailable = false; };
196 template<> struct TypeDefinition<QJsonDocument> { static const bool IsAvailable = false; };
197 template<> struct TypeDefinition<QJsonObject> { static const bool IsAvailable = false; };
198 template<> struct TypeDefinition<QJsonValue> { static const bool IsAvailable = false; };
199 template<> struct TypeDefinition<QModelIndex> { static const bool IsAvailable = false; };
200 template<> struct TypeDefinition<QUrl> { static const bool IsAvailable = false; };
201 #endif
202 #ifdef QT_NO_GEOM_VARIANT
203 template<> struct TypeDefinition<QRect> { static const bool IsAvailable = false; };
204 template<> struct TypeDefinition<QRectF> { static const bool IsAvailable = false; };
205 template<> struct TypeDefinition<QSize> { static const bool IsAvailable = false; };
206 template<> struct TypeDefinition<QSizeF> { static const bool IsAvailable = false; };
207 template<> struct TypeDefinition<QLine> { static const bool IsAvailable = false; };
208 template<> struct TypeDefinition<QLineF> { static const bool IsAvailable = false; };
209 template<> struct TypeDefinition<QPoint> { static const bool IsAvailable = false; };
210 template<> struct TypeDefinition<QPointF> { static const bool IsAvailable = false; };
211 #endif
212 #ifdef QT_NO_REGEXP
213 template<> struct TypeDefinition<QRegExp> { static const bool IsAvailable = false; };
214 #endif
215 #if defined(QT_BOOTSTRAPPED) || defined(QT_NO_REGEXP)
216 template<> struct TypeDefinition<QRegularExpression> { static const bool IsAvailable = false; };
217 #endif
218 #ifdef QT_NO_SHORTCUT
219 template<> struct TypeDefinition<QKeySequence> { static const bool IsAvailable = false; };
220 #endif
221 #ifdef QT_NO_CURSOR
222 template<> struct TypeDefinition<QCursor> { static const bool IsAvailable = false; };
223 #endif
224 #ifdef QT_NO_MATRIX4X4
225 template<> struct TypeDefinition<QMatrix4x4> { static const bool IsAvailable = false; };
226 #endif
227 #ifdef QT_NO_VECTOR2D
228 template<> struct TypeDefinition<QVector2D> { static const bool IsAvailable = false; };
229 #endif
230 #ifdef QT_NO_VECTOR3D
231 template<> struct TypeDefinition<QVector3D> { static const bool IsAvailable = false; };
232 #endif
233 #ifdef QT_NO_VECTOR4D
234 template<> struct TypeDefinition<QVector4D> { static const bool IsAvailable = false; };
235 #endif
236 #ifdef QT_NO_QUATERNION
237 template<> struct TypeDefinition<QQuaternion> { static const bool IsAvailable = false; };
238 #endif
239 } //namespace QtMetaTypePrivate
240
241 QT_END_NAMESPACE
242
243 #endif // QMETATYPE_P_H