1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the core module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
32
#include "QtCore/qdatastream.h"
35
#error qmetatype.h must be included before any header file that define Bool
38
class Q_CORE_EXPORT QMetaType {
41
// these are merged with QVariant
42
Void = 0, Bool = 1, Int = 2, UInt = 3, Double = 6, QChar = 7,
43
QString = 10, QByteArray = 12,
45
VoidStar = 128, Long, Short, Char, ULong,
46
UShort, UChar, Float, QObjectStar, QWidgetStar,
50
typedef void (*Destructor)(void *);
51
typedef void *(*Constructor)(const void *);
52
typedef void (*SaveOperator)(QDataStream &, const void *);
53
typedef void (*LoadOperator)(QDataStream &, void *);
55
static int registerType(const char *typeName, Destructor destructor,
56
Constructor constructor);
57
static void registerStreamOperators(const char *typeName, SaveOperator saveOp,
59
static int type(const char *typeName);
60
static const char *typeName(int type);
61
static bool isRegistered(int type);
62
static void *construct(int type, const void *copy);
63
static void destroy(int type, void *data);
64
static bool save(QDataStream &stream, int type, const void *data);
65
static bool load(QDataStream &stream, int type, void *data);
69
void qMetaTypeDeleteHelper(T *t)
75
void *qMetaTypeConstructHelper(const T *t)
79
return new T(*static_cast<const T*>(t));
83
void qMetaTypeSaveHelper(QDataStream &stream, const T *t)
89
void qMetaTypeLoadHelper(QDataStream &stream, T *t)
95
int qRegisterMetaType(const char *typeName, T * = 0)
97
typedef void*(*ConstructPtr)(const T*);
98
ConstructPtr cptr = qMetaTypeConstructHelper<T>;
99
typedef void(*DeletePtr)(T*);
100
DeletePtr dptr = qMetaTypeDeleteHelper<T>;
102
return QMetaType::registerType(typeName, reinterpret_cast<QMetaType::Destructor>(dptr),
103
reinterpret_cast<QMetaType::Constructor>(cptr));
106
template <typename T>
107
void qRegisterMetaTypeStreamOperators(const char *typeName, T * = 0)
109
typedef void(*SavePtr)(QDataStream &, const T *);
110
typedef void(*LoadPtr)(QDataStream &, T *);
111
SavePtr sptr = qMetaTypeSaveHelper<T>;
112
LoadPtr lptr = qMetaTypeLoadHelper<T>;
114
QMetaType::registerStreamOperators(typeName, reinterpret_cast<QMetaType::SaveOperator>(sptr),
115
reinterpret_cast<QMetaType::LoadOperator>(lptr));
118
template <typename T>
123
#define Q_DECLARE_METATYPE(TYPE) \
125
struct QMetaTypeId<TYPE> \
127
static int qt_metatype_id() \
129
static int id = qRegisterMetaType<TYPE>(#TYPE); \
134
template<> struct QMetaTypeId<QString>
135
{ static inline int qt_metatype_id() { return QMetaType::QString; } };
136
template<> struct QMetaTypeId<int>
137
{ static inline int qt_metatype_id() { return QMetaType::Int; } };
138
template<> struct QMetaTypeId<uint>
139
{ static inline int qt_metatype_id() { return QMetaType::UInt; } };
140
template<> struct QMetaTypeId<bool>
141
{ static inline int qt_metatype_id() { return QMetaType::Bool; } };
142
template<> struct QMetaTypeId<double>
143
{ static inline int qt_metatype_id() { return QMetaType::Double; } };
144
template<> struct QMetaTypeId<QByteArray>
145
{ static inline int qt_metatype_id() { return QMetaType::QByteArray; } };
146
template<> struct QMetaTypeId<QChar>
147
{ static inline int qt_metatype_id() { return QMetaType::QChar; } };
148
template<> struct QMetaTypeId<void>
149
{ static inline int qt_metatype_id() { return QMetaType::VoidStar; } };
150
template<> struct QMetaTypeId<long>
151
{ static inline int qt_metatype_id() { return QMetaType::Long; } };
152
template<> struct QMetaTypeId<short>
153
{ static inline int qt_metatype_id() { return QMetaType::Short; } };
154
template<> struct QMetaTypeId<char>
155
{ static inline int qt_metatype_id() { return QMetaType::Char; } };
156
template<> struct QMetaTypeId<ulong>
157
{ static inline int qt_metatype_id() { return QMetaType::ULong; } };
158
template<> struct QMetaTypeId<ushort>
159
{ static inline int qt_metatype_id() { return QMetaType::UShort; } };
160
template<> struct QMetaTypeId<uchar>
161
{ static inline int qt_metatype_id() { return QMetaType::UChar; } };
162
template<> struct QMetaTypeId<float>
163
{ static inline int qt_metatype_id() { return QMetaType::Float; } };
165
template<> struct QMetaTypeId<QObject *>
166
{ static inline int qt_metatype_id() { return QMetaType::QObjectStar; } };
168
template<> struct QMetaTypeId<QWidget *>
169
{ static inline int qt_metatype_id() { return QMetaType::QWidgetStar; } };
171
#endif // QMETATYPE_H