1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtCore module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
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.
56 #include "qmetatype.h"
60 namespace QModulesPrivate {
61 enum Names { Core, Gui, Widgets, Unknown, ModulesCount /* ModulesCount has to be at the end */ };
63 static inline int moduleForType(const int typeId)
65 if (typeId <= QMetaType::LastCoreType)
67 if (typeId <= QMetaType::LastGuiType)
69 if (typeId <= QMetaType::LastWidgetsType)
80 IsCore = !QTypeInfo<T>::isComplex, // Primitive types are in Core
87 #define QT_ASSIGN_TYPE_TO_MODULE(TYPE, MODULE) \
89 class QTypeModuleInfo<TYPE > \
93 IsCore = (((MODULE) == (QModulesPrivate::Core))), \
94 IsWidget = (((MODULE) == (QModulesPrivate::Widgets))), \
95 IsGui = (((MODULE) == (QModulesPrivate::Gui))), \
96 IsUnknown = !(IsCore || IsWidget || IsGui) \
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))); \
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);
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)
118 #undef QT_DECLARE_CORE_MODULE_TYPES_ITER
119 #undef QT_DECLARE_GUI_MODULE_TYPES_ITER
120 #undef QT_DECLARE_WIDGETS_MODULE_TYPES_ITER
122 class QMetaTypeInterface
125 QMetaType::Creator creator;
126 QMetaType::Deleter deleter;
127 QMetaType::SaveOperator saveOp;
128 QMetaType::LoadOperator loadOp;
129 QMetaType::Constructor constructor;
130 QMetaType::Destructor destructor;
132 quint32 flags; // same as QMetaType::TypeFlags
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) \
143 # define QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type) \
146 # define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
147 QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type)
150 #define QT_METATYPE_INTERFACE_INIT_IMPL(Type, DATASTREAM_DELEGATE) \
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*/(!QTypeInfo<Type>::isStatic * QMetaType::MovableType) \
159 | (QTypeInfo<Type>::isComplex * QMetaType::NeedsConstruction) \
160 | (QTypeInfo<Type>::isComplex * QMetaType::NeedsDestruction) \
164 /* These QT_METATYPE_INTERFACE_INIT* macros are used to initialize QMetaTypeInterface instance.
166 - QT_METATYPE_INTERFACE_INIT(Type) -> It takes Type argument and creates all necessary wrapper functions for the Type,
167 it detects if QT_NO_DATASTREAM was defined. Probably it is the macro that you want to use.
169 - QT_METATYPE_INTERFACE_INIT_EMPTY() -> It initializes an empty QMetaTypeInterface instance.
171 - QT_METATYPE_INTERFACE_INIT_NO_DATASTREAM(Type) -> Temporary workaround for missing auto-detection of data stream
172 operators. It creates same instance as QT_METATYPE_INTERFACE_INIT(Type) but with null stream operators callbacks.
174 #define QT_METATYPE_INTERFACE_INIT(Type) QT_METATYPE_INTERFACE_INIT_IMPL(Type, QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL)
175 #define QT_METATYPE_INTERFACE_INIT_NO_DATASTREAM(Type) QT_METATYPE_INTERFACE_INIT_IMPL(Type, QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL)
176 #define QT_METATYPE_INTERFACE_INIT_EMPTY() \
180 QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL() \
189 #endif // QMETATYPE_P_H