Qt 4.8
qmetatype.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
57 
59 
60 QT_MODULE(Core)
61 
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, QEasingCurve = 29, LastCoreType = QEasingCurve,
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,
84  LastGuiType = 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  QVariant = 138,
90  LastCoreExtType = QVariant,
91 
92 // This logic must match the one in qglobal.h
93 #if defined(QT_COORD_TYPE)
94  QReal = 0,
95 #elif defined(QT_NO_FPU) || defined(QT_ARCH_ARM) || defined(QT_ARCH_WINDOWSCE) || defined(QT_ARCH_SYMBIAN)
96  QReal = Float,
97 #else
98  QReal = Double,
99 #endif
100 
101  User = 256
102  };
103 
104  typedef void (*Destructor)(void *);
105  typedef void *(*Constructor)(const void *);
106 
107 #ifndef QT_NO_DATASTREAM
108  typedef void (*SaveOperator)(QDataStream &, const void *);
109  typedef void (*LoadOperator)(QDataStream &, void *);
110  static void registerStreamOperators(const char *typeName, SaveOperator saveOp,
111  LoadOperator loadOp);
112  static void registerStreamOperators(int type, SaveOperator saveOp,
113  LoadOperator loadOp);
114 #endif
115  static int registerType(const char *typeName, Destructor destructor,
116  Constructor constructor);
117  static int registerTypedef(const char *typeName, int aliasId);
118  static int type(const char *typeName);
119  static const char *typeName(int type);
120  static bool isRegistered(int type);
121  static void *construct(int type, const void *copy = 0);
122  static void destroy(int type, void *data);
123  static void unregisterType(const char *typeName);
124 
125 #ifndef QT_NO_DATASTREAM
126  static bool save(QDataStream &stream, int type, const void *data);
127  static bool load(QDataStream &stream, int type, void *data);
128 #endif
129 };
130 
131 template <typename T>
133 {
134  delete t;
135 }
136 
137 template <typename T>
138 void *qMetaTypeConstructHelper(const T *t)
139 {
140  if (!t)
141  return new T();
142  return new T(*static_cast<const T*>(t));
143 }
144 
145 #ifndef QT_NO_DATASTREAM
146 template <typename T>
148 {
149  stream << *t;
150 }
151 
152 template <typename T>
154 {
155  stream >> *t;
156 }
157 #endif // QT_NO_DATASTREAM
158 
159 template <typename T>
161 {
162  enum { Defined = 0 };
163 };
164 
165 template <typename T>
167 {
169  static inline int qt_metatype_id() { return QMetaTypeId<T>::qt_metatype_id(); }
170 };
171 
172 namespace QtPrivate {
173  template <typename T, bool Defined = QMetaTypeId2<T>::Defined>
175  static inline int qt_metatype_id()
176  { return QMetaTypeId2<T>::qt_metatype_id(); }
177  };
178  template <typename T> struct QMetaTypeIdHelper<T, false> {
179  static inline int qt_metatype_id()
180  { return -1; }
181  };
182 }
183 
184 template <typename T>
186 #ifndef qdoc
187  , T * dummy = 0
188 #endif
189 )
190 {
191  const int typedefOf = dummy ? -1 : QtPrivate::QMetaTypeIdHelper<T>::qt_metatype_id();
192  if (typedefOf != -1)
193  return QMetaType::registerTypedef(typeName, typedefOf);
194 
195  typedef void*(*ConstructPtr)(const T*);
196  ConstructPtr cptr = qMetaTypeConstructHelper<T>;
197  typedef void(*DeletePtr)(T*);
198  DeletePtr dptr = qMetaTypeDeleteHelper<T>;
199 
200  return QMetaType::registerType(typeName, reinterpret_cast<QMetaType::Destructor>(dptr),
201  reinterpret_cast<QMetaType::Constructor>(cptr));
202 }
203 
204 #ifndef QT_NO_DATASTREAM
205 template <typename T>
207 #ifndef qdoc
208  , T * /* dummy */ = 0
209 #endif
210 )
211 {
212  typedef void(*SavePtr)(QDataStream &, const T *);
213  typedef void(*LoadPtr)(QDataStream &, T *);
214  SavePtr sptr = qMetaTypeSaveHelper<T>;
215  LoadPtr lptr = qMetaTypeLoadHelper<T>;
216 
217  qRegisterMetaType<T>(typeName);
218  QMetaType::registerStreamOperators(typeName, reinterpret_cast<QMetaType::SaveOperator>(sptr),
219  reinterpret_cast<QMetaType::LoadOperator>(lptr));
220 }
221 #endif // QT_NO_DATASTREAM
222 
223 template <typename T>
224 inline int qMetaTypeId(
225 #ifndef qdoc
226  T * /* dummy */ = 0
227 #endif
228 )
229 {
231 }
232 
233 template <typename T>
234 inline int qRegisterMetaType(
235 #if !defined(qdoc) && !defined(Q_CC_SUN)
236  T * dummy = 0
237 #endif
238 )
239 {
240 #ifdef Q_CC_SUN
241  return qMetaTypeId(static_cast<T *>(0));
242 #else
243  return qMetaTypeId(dummy);
244 #endif
245 }
246 
247 #ifndef QT_NO_DATASTREAM
248 template <typename T>
250 {
251  typedef void(*SavePtr)(QDataStream &, const T *);
252  typedef void(*LoadPtr)(QDataStream &, T *);
253  SavePtr sptr = qMetaTypeSaveHelper<T>;
254  LoadPtr lptr = qMetaTypeLoadHelper<T>;
255 
256  register int id = qMetaTypeId<T>();
258  reinterpret_cast<QMetaType::SaveOperator>(sptr),
259  reinterpret_cast<QMetaType::LoadOperator>(lptr));
260 
261  return id;
262 }
263 #endif
264 
265 #define Q_DECLARE_METATYPE(TYPE) \
266  QT_BEGIN_NAMESPACE \
267  template <> \
268  struct QMetaTypeId< TYPE > \
269  { \
270  enum { Defined = 1 }; \
271  static int qt_metatype_id() \
272  { \
273  static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
274  if (!metatype_id) \
275  metatype_id = qRegisterMetaType< TYPE >(#TYPE, \
276  reinterpret_cast< TYPE *>(quintptr(-1))); \
277  return metatype_id; \
278  } \
279  }; \
280  QT_END_NAMESPACE
281 
282 #define Q_DECLARE_BUILTIN_METATYPE(TYPE, NAME) \
283  QT_BEGIN_NAMESPACE \
284  template<> struct QMetaTypeId2<TYPE> \
285  { \
286  enum { Defined = 1, MetaType = QMetaType::NAME }; \
287  static inline int qt_metatype_id() { return QMetaType::NAME; } \
288  }; \
289  QT_END_NAMESPACE
290 
291 class QString;
292 class QByteArray;
293 class QChar;
294 class QStringList;
295 class QBitArray;
296 class QDate;
297 class QTime;
298 class QDateTime;
299 class QUrl;
300 class QLocale;
301 class QRect;
302 class QRectF;
303 class QSize;
304 class QSizeF;
305 class QLine;
306 class QLineF;
307 class QPoint;
308 class QPointF;
309 #ifndef QT_NO_REGEXP
310 class QRegExp;
311 #endif
312 class QEasingCurve;
313 class QWidget;
314 class QObject;
315 
316 #ifdef QT3_SUPPORT
317 class QColorGroup;
318 #endif
319 class QFont;
320 class QPixmap;
321 class QBrush;
322 class QColor;
323 class QPalette;
324 class QIcon;
325 class QImage;
326 class QPolygon;
327 class QRegion;
328 class QBitmap;
329 class QCursor;
330 class QSizePolicy;
331 class QKeySequence;
332 class QPen;
333 class QTextLength;
334 class QTextFormat;
335 class QMatrix;
336 class QTransform;
337 class QMatrix4x4;
338 class QVector2D;
339 class QVector3D;
340 class QVector4D;
341 class QQuaternion;
342 class QVariant;
343 
345 
354 Q_DECLARE_BUILTIN_METATYPE(short, Short)
356 Q_DECLARE_BUILTIN_METATYPE(signed char, Char)
361 Q_DECLARE_BUILTIN_METATYPE(QObject *, QObjectStar)
362 Q_DECLARE_BUILTIN_METATYPE(QWidget *, QWidgetStar)
363 Q_DECLARE_BUILTIN_METATYPE(void *, VoidStar)
381 #ifndef QT_NO_REGEXP
383 #endif
385 
386 #ifdef QT3_SUPPORT
388 #endif
413 
415 
416 #endif // QMETATYPE_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void qMetaTypeLoadHelper(QDataStream &stream, T *t)
Definition: qmetatype.h:153
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
The QVector3D class represents a vector or vertex in 3D space.
Definition: qvector3d.h:60
int type
Definition: qmetatype.cpp:239
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition: qcursor.h:89
int registerType(const QDeclarativePrivate::RegisterType &type)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
The QEasingCurve class provides easing curves for controlling animation.
Definition: qeasingcurve.h:55
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:57
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
static int qt_metatype_id()
Definition: qmetatype.h:169
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QVector4D class represents a vector or vertex in 4D space.
Definition: qvector4d.h:60
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int qMetaTypeId()
Definition: qmetatype.h:224
The QDate class provides date functions.
Definition: qdatetime.h:55
The QPolygon class provides a vector of points using integer precision.
Definition: qpolygon.h:60
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
AbstractFloat< false > Float
An instantiation of AbstractFloat suitable for xs:float.
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
#define ULong
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
static int registerTypedef(const char *typeName, int aliasId)
Definition: qmetatype.cpp:515
unsigned char uchar
Definition: qglobal.h:994
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
The QTime class provides clock time functions.
Definition: qdatetime.h:148
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static FILE * stream
const char * typeName
Definition: qmetatype.cpp:239
The QTextFormat class provides formatting information for a QTextDocument.
Definition: qtextformat.h:129
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
#define Q_DECLARE_BUILTIN_METATYPE(TYPE, NAME)
Definition: qmetatype.h:282
Type
These are the built-in types supported by QMetaType:
Definition: qmetatype.h:64
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
The QVector2D class represents a vector or vertex in 2D space.
Definition: qvector2d.h:60
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
int qRegisterMetaType(const char *typeName)
Definition: qmetatype.h:185
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
static void registerStreamOperators(const char *typeName, SaveOperator saveOp, LoadOperator loadOp)
Definition: qmetatype.cpp:374
ushort Char
unsigned long ulong
Definition: qglobal.h:997
The QMetaType class manages named types in the meta-object system.
Definition: qmetatype.h:62
The QBitArray class provides an array of bits.
Definition: qbitarray.h:54
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QKeySequence class encapsulates a key sequence as used by shortcuts.
Definition: qkeysequence.h:72
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
#define load(x)
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
static void construct(QVariant::Private *x, const void *copy)
Definition: qvariant.cpp:75
unsigned short ushort
Definition: qglobal.h:995
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QTextLength class encapsulates the different types of length used in a QTextDocument.
Definition: qtextformat.h:84
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void qMetaTypeDeleteHelper(T *t)
Definition: qmetatype.h:132
The QColorGroup class contains color groups for each widget state.
The QQuaternion class represents a quaternion consisting of a vector and scalar.
Definition: qquaternion.h:59
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
void qRegisterMetaTypeStreamOperators(const char *typeName)
Definition: qmetatype.h:206
AbstractFloat< true > Double
An instantiation of AbsbstractFloat suitable for xs:double.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
void qMetaTypeSaveHelper(QDataStream &stream, const T *t)
Definition: qmetatype.h:147
quint64 qulonglong
Definition: qglobal.h:952
static int registerType(const char *typeName, Destructor destructor, Constructor constructor)
Registers a user type for marshalling, with typeName, a destructor, and a constructor.
Definition: qmetatype.cpp:477
#define class
qint64 qlonglong
Definition: qglobal.h:951
#define QT_END_HEADER
Definition: qglobal.h:137
void * qMetaTypeConstructHelper(const T *t)
Definition: qmetatype.h:138
#define Long
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60