author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 0 | 1918ee327afb |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtCore module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#ifndef QMETATYPE_H |
|
43 |
#define QMETATYPE_H |
|
44 |
||
45 |
#include <QtCore/qglobal.h> |
|
46 |
#include <QtCore/qatomic.h> |
|
47 |
||
48 |
#ifndef QT_NO_DATASTREAM |
|
49 |
#include <QtCore/qdatastream.h> |
|
50 |
#endif |
|
51 |
||
52 |
#ifdef Bool |
|
53 |
#error qmetatype.h must be included before any header file that defines Bool |
|
54 |
#endif |
|
55 |
||
56 |
QT_BEGIN_HEADER |
|
57 |
||
58 |
QT_BEGIN_NAMESPACE |
|
59 |
||
60 |
QT_MODULE(Core) |
|
61 |
||
62 |
class Q_CORE_EXPORT QMetaType { |
|
63 |
public: |
|
64 |
enum Type { |
|
65 |
// these are merged with QVariant |
|
66 |
Void = 0, Bool = 1, Int = 2, UInt = 3, LongLong = 4, ULongLong = 5, |
|
67 |
Double = 6, QChar = 7, QVariantMap = 8, QVariantList = 9, |
|
68 |
QString = 10, QStringList = 11, QByteArray = 12, |
|
69 |
QBitArray = 13, QDate = 14, QTime = 15, QDateTime = 16, QUrl = 17, |
|
70 |
QLocale = 18, QRect = 19, QRectF = 20, QSize = 21, QSizeF = 22, |
|
71 |
QLine = 23, QLineF = 24, QPoint = 25, QPointF = 26, QRegExp = 27, |
|
72 |
QVariantHash = 28, LastCoreType = 28 /* QVariantHash */, |
|
73 |
||
74 |
FirstGuiType = 63 /* QColorGroup */, |
|
75 |
#ifdef QT3_SUPPORT |
|
76 |
QColorGroup = 63, |
|
77 |
#endif |
|
78 |
QFont = 64, QPixmap = 65, QBrush = 66, QColor = 67, QPalette = 68, |
|
79 |
QIcon = 69, QImage = 70, QPolygon = 71, QRegion = 72, QBitmap = 73, |
|
80 |
QCursor = 74, QSizePolicy = 75, QKeySequence = 76, QPen = 77, |
|
81 |
QTextLength = 78, QTextFormat = 79, QMatrix = 80, QTransform = 81, |
|
82 |
QMatrix4x4 = 82, QVector2D = 83, QVector3D = 84, QVector4D = 85, |
|
83 |
QQuaternion = 86, |
|
84 |
LastGuiType = 86 /* QQuaternion */, |
|
85 |
||
86 |
FirstCoreExtType = 128 /* VoidStar */, |
|
87 |
VoidStar = 128, Long = 129, Short = 130, Char = 131, ULong = 132, |
|
88 |
UShort = 133, UChar = 134, Float = 135, QObjectStar = 136, QWidgetStar = 137, |
|
89 |
LastCoreExtType = 137 /* QWidgetStar */, |
|
90 |
||
91 |
// This logic must match the one in qglobal.h |
|
92 |
#if defined(QT_COORD_TYPE) |
|
93 |
QReal = 0, |
|
94 |
#elif defined(QT_NO_FPU) || defined(QT_ARCH_ARM) || defined(QT_ARCH_WINDOWSCE) || defined(QT_ARCH_SYMBIAN) |
|
95 |
QReal = Float, |
|
96 |
#else |
|
97 |
QReal = Double, |
|
98 |
#endif |
|
99 |
||
100 |
User = 256 |
|
101 |
}; |
|
102 |
||
103 |
typedef void (*Destructor)(void *); |
|
104 |
typedef void *(*Constructor)(const void *); |
|
105 |
||
106 |
#ifndef QT_NO_DATASTREAM |
|
107 |
typedef void (*SaveOperator)(QDataStream &, const void *); |
|
108 |
typedef void (*LoadOperator)(QDataStream &, void *); |
|
109 |
static void registerStreamOperators(const char *typeName, SaveOperator saveOp, |
|
110 |
LoadOperator loadOp); |
|
111 |
#endif |
|
112 |
static int registerType(const char *typeName, Destructor destructor, |
|
113 |
Constructor constructor); |
|
114 |
static int type(const char *typeName); |
|
115 |
static const char *typeName(int type); |
|
116 |
static bool isRegistered(int type); |
|
117 |
static void *construct(int type, const void *copy = 0); |
|
118 |
static void destroy(int type, void *data); |
|
119 |
static void unregisterType(const char *typeName); |
|
120 |
||
121 |
#ifndef QT_NO_DATASTREAM |
|
122 |
static bool save(QDataStream &stream, int type, const void *data); |
|
123 |
static bool load(QDataStream &stream, int type, void *data); |
|
124 |
#endif |
|
125 |
}; |
|
126 |
||
127 |
template <typename T> |
|
128 |
void qMetaTypeDeleteHelper(T *t) |
|
129 |
{ |
|
130 |
delete t; |
|
131 |
} |
|
132 |
||
133 |
template <typename T> |
|
134 |
void *qMetaTypeConstructHelper(const T *t) |
|
135 |
{ |
|
136 |
if (!t) |
|
137 |
return new T; |
|
138 |
return new T(*static_cast<const T*>(t)); |
|
139 |
} |
|
140 |
||
141 |
#ifndef QT_NO_DATASTREAM |
|
142 |
template <typename T> |
|
143 |
void qMetaTypeSaveHelper(QDataStream &stream, const T *t) |
|
144 |
{ |
|
145 |
stream << *t; |
|
146 |
} |
|
147 |
||
148 |
template <typename T> |
|
149 |
void qMetaTypeLoadHelper(QDataStream &stream, T *t) |
|
150 |
{ |
|
151 |
stream >> *t; |
|
152 |
} |
|
153 |
#endif // QT_NO_DATASTREAM |
|
154 |
||
155 |
template <typename T> |
|
156 |
int qRegisterMetaType(const char *typeName |
|
157 |
#ifndef qdoc |
|
158 |
, T * /* dummy */ = 0 |
|
159 |
#endif |
|
160 |
) |
|
161 |
{ |
|
162 |
typedef void*(*ConstructPtr)(const T*); |
|
163 |
ConstructPtr cptr = qMetaTypeConstructHelper<T>; |
|
164 |
typedef void(*DeletePtr)(T*); |
|
165 |
DeletePtr dptr = qMetaTypeDeleteHelper<T>; |
|
166 |
||
167 |
return QMetaType::registerType(typeName, reinterpret_cast<QMetaType::Destructor>(dptr), |
|
168 |
reinterpret_cast<QMetaType::Constructor>(cptr)); |
|
169 |
} |
|
170 |
||
171 |
#ifndef QT_NO_DATASTREAM |
|
172 |
template <typename T> |
|
173 |
void qRegisterMetaTypeStreamOperators(const char *typeName |
|
174 |
#ifndef qdoc |
|
175 |
, T * /* dummy */ = 0 |
|
176 |
#endif |
|
177 |
) |
|
178 |
{ |
|
179 |
typedef void(*SavePtr)(QDataStream &, const T *); |
|
180 |
typedef void(*LoadPtr)(QDataStream &, T *); |
|
181 |
SavePtr sptr = qMetaTypeSaveHelper<T>; |
|
182 |
LoadPtr lptr = qMetaTypeLoadHelper<T>; |
|
183 |
||
184 |
qRegisterMetaType<T>(typeName); |
|
185 |
QMetaType::registerStreamOperators(typeName, reinterpret_cast<QMetaType::SaveOperator>(sptr), |
|
186 |
reinterpret_cast<QMetaType::LoadOperator>(lptr)); |
|
187 |
} |
|
188 |
#endif // QT_NO_DATASTREAM |
|
189 |
||
190 |
template <typename T> |
|
191 |
struct QMetaTypeId |
|
192 |
{ |
|
193 |
enum { Defined = 0 }; |
|
194 |
}; |
|
195 |
||
196 |
template <typename T> |
|
197 |
struct QMetaTypeId2 |
|
198 |
{ |
|
199 |
enum { Defined = QMetaTypeId<T>::Defined }; |
|
200 |
static inline int qt_metatype_id() { return QMetaTypeId<T>::qt_metatype_id(); } |
|
201 |
}; |
|
202 |
||
203 |
template <typename T> |
|
204 |
inline int qMetaTypeId( |
|
205 |
#ifndef qdoc |
|
206 |
T * /* dummy */ = 0 |
|
207 |
#endif |
|
208 |
) |
|
209 |
{ |
|
210 |
return QMetaTypeId2<T>::qt_metatype_id(); |
|
211 |
} |
|
212 |
||
213 |
template <typename T> |
|
214 |
inline int qRegisterMetaType( |
|
215 |
#if !defined(qdoc) && !defined(Q_CC_SUN) |
|
216 |
T * dummy = 0 |
|
217 |
#endif |
|
218 |
) |
|
219 |
{ |
|
220 |
#ifdef Q_CC_SUN |
|
221 |
return qMetaTypeId(static_cast<T *>(0)); |
|
222 |
#else |
|
223 |
return qMetaTypeId(dummy); |
|
224 |
#endif |
|
225 |
} |
|
226 |
||
227 |
#define Q_DECLARE_METATYPE(TYPE) \ |
|
228 |
QT_BEGIN_NAMESPACE \ |
|
229 |
template <> \ |
|
230 |
struct QMetaTypeId< TYPE > \ |
|
231 |
{ \ |
|
232 |
enum { Defined = 1 }; \ |
|
233 |
static int qt_metatype_id() \ |
|
234 |
{ \ |
|
235 |
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \ |
|
236 |
if (!metatype_id) \ |
|
237 |
metatype_id = qRegisterMetaType< TYPE >(#TYPE); \ |
|
238 |
return metatype_id; \ |
|
239 |
} \ |
|
240 |
}; \ |
|
241 |
QT_END_NAMESPACE |
|
242 |
||
243 |
#define Q_DECLARE_BUILTIN_METATYPE(TYPE, NAME) \ |
|
244 |
QT_BEGIN_NAMESPACE \ |
|
245 |
template<> struct QMetaTypeId2<TYPE> \ |
|
246 |
{ \ |
|
247 |
enum { Defined = 1, MetaType = QMetaType::NAME }; \ |
|
248 |
static inline int qt_metatype_id() { return QMetaType::NAME; } \ |
|
249 |
}; \ |
|
250 |
QT_END_NAMESPACE |
|
251 |
||
252 |
class QString; |
|
253 |
class QByteArray; |
|
254 |
class QChar; |
|
255 |
class QStringList; |
|
256 |
class QBitArray; |
|
257 |
class QDate; |
|
258 |
class QTime; |
|
259 |
class QDateTime; |
|
260 |
class QUrl; |
|
261 |
class QLocale; |
|
262 |
class QRect; |
|
263 |
class QRectF; |
|
264 |
class QSize; |
|
265 |
class QSizeF; |
|
266 |
class QLine; |
|
267 |
class QLineF; |
|
268 |
class QPoint; |
|
269 |
class QPointF; |
|
270 |
#ifndef QT_NO_REGEXP |
|
271 |
class QRegExp; |
|
272 |
#endif |
|
273 |
class QWidget; |
|
274 |
class QObject; |
|
275 |
||
276 |
#ifdef QT3_SUPPORT |
|
277 |
class QColorGroup; |
|
278 |
#endif |
|
279 |
class QFont; |
|
280 |
class QPixmap; |
|
281 |
class QBrush; |
|
282 |
class QColor; |
|
283 |
class QPalette; |
|
284 |
class QIcon; |
|
285 |
class QImage; |
|
286 |
class QPolygon; |
|
287 |
class QRegion; |
|
288 |
class QBitmap; |
|
289 |
class QCursor; |
|
290 |
class QSizePolicy; |
|
291 |
class QKeySequence; |
|
292 |
class QPen; |
|
293 |
class QTextLength; |
|
294 |
class QTextFormat; |
|
295 |
class QMatrix; |
|
296 |
class QTransform; |
|
297 |
class QMatrix4x4; |
|
298 |
class QVector2D; |
|
299 |
class QVector3D; |
|
300 |
class QVector4D; |
|
301 |
class QQuaternion; |
|
302 |
||
303 |
QT_END_NAMESPACE |
|
304 |
||
305 |
Q_DECLARE_BUILTIN_METATYPE(QString, QString) |
|
306 |
Q_DECLARE_BUILTIN_METATYPE(int, Int) |
|
307 |
Q_DECLARE_BUILTIN_METATYPE(uint, UInt) |
|
308 |
Q_DECLARE_BUILTIN_METATYPE(bool, Bool) |
|
309 |
Q_DECLARE_BUILTIN_METATYPE(double, Double) |
|
310 |
Q_DECLARE_BUILTIN_METATYPE(QByteArray, QByteArray) |
|
311 |
Q_DECLARE_BUILTIN_METATYPE(QChar, QChar) |
|
312 |
Q_DECLARE_BUILTIN_METATYPE(long, Long) |
|
313 |
Q_DECLARE_BUILTIN_METATYPE(short, Short) |
|
314 |
Q_DECLARE_BUILTIN_METATYPE(char, Char) |
|
315 |
Q_DECLARE_BUILTIN_METATYPE(ulong, ULong) |
|
316 |
Q_DECLARE_BUILTIN_METATYPE(ushort, UShort) |
|
317 |
Q_DECLARE_BUILTIN_METATYPE(uchar, UChar) |
|
318 |
Q_DECLARE_BUILTIN_METATYPE(float, Float) |
|
319 |
Q_DECLARE_BUILTIN_METATYPE(QObject *, QObjectStar) |
|
320 |
Q_DECLARE_BUILTIN_METATYPE(QWidget *, QWidgetStar) |
|
321 |
Q_DECLARE_BUILTIN_METATYPE(void *, VoidStar) |
|
322 |
Q_DECLARE_BUILTIN_METATYPE(qlonglong, LongLong) |
|
323 |
Q_DECLARE_BUILTIN_METATYPE(qulonglong, ULongLong) |
|
324 |
Q_DECLARE_BUILTIN_METATYPE(QStringList, QStringList) |
|
325 |
Q_DECLARE_BUILTIN_METATYPE(QBitArray, QBitArray) |
|
326 |
Q_DECLARE_BUILTIN_METATYPE(QDate, QDate) |
|
327 |
Q_DECLARE_BUILTIN_METATYPE(QTime, QTime) |
|
328 |
Q_DECLARE_BUILTIN_METATYPE(QDateTime, QDateTime) |
|
329 |
Q_DECLARE_BUILTIN_METATYPE(QUrl, QUrl) |
|
330 |
Q_DECLARE_BUILTIN_METATYPE(QLocale, QLocale) |
|
331 |
Q_DECLARE_BUILTIN_METATYPE(QRect, QRect) |
|
332 |
Q_DECLARE_BUILTIN_METATYPE(QRectF, QRectF) |
|
333 |
Q_DECLARE_BUILTIN_METATYPE(QSize, QSize) |
|
334 |
Q_DECLARE_BUILTIN_METATYPE(QSizeF, QSizeF) |
|
335 |
Q_DECLARE_BUILTIN_METATYPE(QLine, QLine) |
|
336 |
Q_DECLARE_BUILTIN_METATYPE(QLineF, QLineF) |
|
337 |
Q_DECLARE_BUILTIN_METATYPE(QPoint, QPoint) |
|
338 |
Q_DECLARE_BUILTIN_METATYPE(QPointF, QPointF) |
|
339 |
#ifndef QT_NO_REGEXP |
|
340 |
Q_DECLARE_BUILTIN_METATYPE(QRegExp, QRegExp) |
|
341 |
#endif |
|
342 |
||
343 |
#ifdef QT3_SUPPORT |
|
344 |
Q_DECLARE_BUILTIN_METATYPE(QColorGroup, QColorGroup) |
|
345 |
#endif |
|
346 |
Q_DECLARE_BUILTIN_METATYPE(QFont, QFont) |
|
347 |
Q_DECLARE_BUILTIN_METATYPE(QPixmap, QPixmap) |
|
348 |
Q_DECLARE_BUILTIN_METATYPE(QBrush, QBrush) |
|
349 |
Q_DECLARE_BUILTIN_METATYPE(QColor, QColor) |
|
350 |
Q_DECLARE_BUILTIN_METATYPE(QPalette, QPalette) |
|
351 |
Q_DECLARE_BUILTIN_METATYPE(QIcon, QIcon) |
|
352 |
Q_DECLARE_BUILTIN_METATYPE(QImage, QImage) |
|
353 |
Q_DECLARE_BUILTIN_METATYPE(QPolygon, QPolygon) |
|
354 |
Q_DECLARE_BUILTIN_METATYPE(QRegion, QRegion) |
|
355 |
Q_DECLARE_BUILTIN_METATYPE(QBitmap, QBitmap) |
|
356 |
Q_DECLARE_BUILTIN_METATYPE(QCursor, QCursor) |
|
357 |
Q_DECLARE_BUILTIN_METATYPE(QSizePolicy, QSizePolicy) |
|
358 |
Q_DECLARE_BUILTIN_METATYPE(QKeySequence, QKeySequence) |
|
359 |
Q_DECLARE_BUILTIN_METATYPE(QPen, QPen) |
|
360 |
Q_DECLARE_BUILTIN_METATYPE(QTextLength, QTextLength) |
|
361 |
Q_DECLARE_BUILTIN_METATYPE(QTextFormat, QTextFormat) |
|
362 |
Q_DECLARE_BUILTIN_METATYPE(QMatrix, QMatrix) |
|
363 |
Q_DECLARE_BUILTIN_METATYPE(QTransform, QTransform) |
|
364 |
Q_DECLARE_BUILTIN_METATYPE(QMatrix4x4, QMatrix4x4) |
|
365 |
Q_DECLARE_BUILTIN_METATYPE(QVector2D, QVector2D) |
|
366 |
Q_DECLARE_BUILTIN_METATYPE(QVector3D, QVector3D) |
|
367 |
Q_DECLARE_BUILTIN_METATYPE(QVector4D, QVector4D) |
|
368 |
Q_DECLARE_BUILTIN_METATYPE(QQuaternion, QQuaternion) |
|
369 |
||
370 |
QT_END_HEADER |
|
371 |
||
372 |
#endif // QMETATYPE_H |