1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtCore module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** 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 enum { /* TYPEMODULEINFO flags */
71 IsCore = !QTypeInfo<T>::isComplex, // Primitive types are in Core
76 static inline int module() { return IsCore ? Q_CORE_TYPE : 0; }
79 #define QT_ASSIGN_TYPE_TO_MODULE(TYPE, MODULE) \
81 class QTypeModuleInfo<TYPE > \
85 IsCore = (((MODULE) == (Q_CORE_TYPE))), \
86 IsWidget = (((MODULE) == (Q_WIDGET_TYPE))), \
87 IsGui = (((MODULE) == (Q_GUI_TYPE))), \
88 IsUnknown = !(IsCore || IsWidget || IsGui) \
90 static inline int module() { return MODULE; } \
91 Q_STATIC_ASSERT((IsUnknown && !(IsCore || IsWidget || IsGui)) \
92 || (IsCore && !(IsUnknown || IsWidget || IsGui)) \
93 || (IsWidget && !(IsUnknown || IsCore || IsGui)) \
94 || (IsGui && !(IsUnknown || IsCore || IsWidget))); \
98 #define QT_DECLARE_CORE_MODULE_TYPES_ITER(TypeName, TypeId, Name) \
99 QT_ASSIGN_TYPE_TO_MODULE(Name, Q_CORE_TYPE);
100 #define QT_DECLARE_GUI_MODULE_TYPES_ITER(TypeName, TypeId, Name) \
101 QT_ASSIGN_TYPE_TO_MODULE(Name, Q_GUI_TYPE);
102 #define QT_DECLARE_WIDGETS_MODULE_TYPES_ITER(TypeName, TypeId, Name) \
103 QT_ASSIGN_TYPE_TO_MODULE(Name, Q_WIDGET_TYPE);
105 QT_FOR_EACH_STATIC_CORE_CLASS(QT_DECLARE_CORE_MODULE_TYPES_ITER)
106 QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_DECLARE_CORE_MODULE_TYPES_ITER)
107 QT_FOR_EACH_STATIC_GUI_CLASS(QT_DECLARE_GUI_MODULE_TYPES_ITER)
108 QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_DECLARE_WIDGETS_MODULE_TYPES_ITER)
110 #undef QT_DECLARE_CORE_MODULE_TYPES_ITER
111 #undef QT_DECLARE_GUI_MODULE_TYPES_ITER
112 #undef QT_DECLARE_WIDGETS_MODULE_TYPES_ITER
114 class QMetaTypeInterface
119 static void *creator(const T *t)
126 static void deleter(T *t) { delete t; }
127 #ifndef QT_NO_DATASTREAM
128 static void saver(QDataStream &stream, const T *t) { stream << *t; }
129 static void loader(QDataStream &stream, T *t) { stream >> *t; }
130 #endif // QT_NO_DATASTREAM
131 static void destructor(T *t)
133 Q_UNUSED(t) // Silence MSVC that warns for POD types.
136 static void *constructor(void *where, const T *t)
139 return new (where) T(*static_cast<const T*>(t));
140 return new (where) T;
144 QMetaType::Creator creator;
145 QMetaType::Deleter deleter;
146 #ifndef QT_NO_DATASTREAM
147 QMetaType::SaveOperator saveOp;
148 QMetaType::LoadOperator loadOp;
150 QMetaType::Constructor constructor;
151 QMetaType::Destructor destructor;
155 #ifndef QT_NO_DATASTREAM
156 # define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
157 /*saveOp*/(reinterpret_cast<QMetaType::SaveOperator>(QMetaTypeInterface::Impl<Type>::saver)), \
158 /*loadOp*/(reinterpret_cast<QMetaType::LoadOperator>(QMetaTypeInterface::Impl<Type>::loader)),
160 # define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type)
163 #define QT_METATYPE_INTERFACE_INIT(Type) \
165 /*creator*/(reinterpret_cast<QMetaType::Creator>(QMetaTypeInterface::Impl<Type>::creator)), \
166 /*deleter*/(reinterpret_cast<QMetaType::Deleter>(QMetaTypeInterface::Impl<Type>::deleter)), \
167 QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
168 /*constructor*/(reinterpret_cast<QMetaType::Constructor>(QMetaTypeInterface::Impl<Type>::constructor)), \
169 /*destructor*/(reinterpret_cast<QMetaType::Destructor>(QMetaTypeInterface::Impl<Type>::destructor)), \
170 /*size*/(sizeof(Type)) \
175 #endif // QMETATYPE_P_H