Advertisement
Guest User

qmetatype.h

a guest
Apr 17th, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.40 KB | None | 0 0
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
  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. ** 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.
  17. **
  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.
  21. **
  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.
  29. **
  30. ** Other Usage
  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.
  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, 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,
  83.         QQuaternion = 86,
  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>
  132. void qMetaTypeDeleteHelper(T *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>
  147. void qMetaTypeSaveHelper(QDataStream &stream, const T *t)
  148. {
  149.     stream << *t;
  150. }
  151.  
  152. template <typename T>
  153. void qMetaTypeLoadHelper(QDataStream &stream, T *t)
  154. {
  155.     stream >> *t;
  156. }
  157. #endif // QT_NO_DATASTREAM
  158.  
  159. template <typename T>
  160. struct QMetaTypeId
  161. {
  162.     enum { Defined = 0 };
  163. };
  164.  
  165. template <typename T>
  166. struct QMetaTypeId2
  167. {
  168.     enum { Defined = QMetaTypeId<T>::Defined };
  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>
  174.     struct QMetaTypeIdHelper {
  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>
  185. int qRegisterMetaType(const char *typeName
  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>
  206. void qRegisterMetaTypeStreamOperators(const char *typeName
  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. {
  230.     return QMetaTypeId2<T>::qt_metatype_id();
  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>
  249. inline int qRegisterMetaTypeStreamOperators()
  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>();
  257.     QMetaType::registerStreamOperators(id,
  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.  
  344. QT_END_NAMESPACE
  345.  
  346. Q_DECLARE_BUILTIN_METATYPE(QString, QString)
  347. Q_DECLARE_BUILTIN_METATYPE(int, Int)
  348. Q_DECLARE_BUILTIN_METATYPE(uint, UInt)
  349. Q_DECLARE_BUILTIN_METATYPE(bool, Bool)
  350. Q_DECLARE_BUILTIN_METATYPE(double, Double)
  351. Q_DECLARE_BUILTIN_METATYPE(QByteArray, QByteArray)
  352. Q_DECLARE_BUILTIN_METATYPE(QChar, QChar)
  353. Q_DECLARE_BUILTIN_METATYPE(long, Long)
  354. Q_DECLARE_BUILTIN_METATYPE(short, Short)
  355. Q_DECLARE_BUILTIN_METATYPE(char, Char)
  356. Q_DECLARE_BUILTIN_METATYPE(signed char, Char)
  357. Q_DECLARE_BUILTIN_METATYPE(ulong, ULong)
  358. Q_DECLARE_BUILTIN_METATYPE(ushort, UShort)
  359. Q_DECLARE_BUILTIN_METATYPE(uchar, UChar)
  360. Q_DECLARE_BUILTIN_METATYPE(float, Float)
  361. Q_DECLARE_BUILTIN_METATYPE(QObject *, QObjectStar)
  362. Q_DECLARE_BUILTIN_METATYPE(QWidget *, QWidgetStar)
  363. Q_DECLARE_BUILTIN_METATYPE(void *, VoidStar)
  364. Q_DECLARE_BUILTIN_METATYPE(qlonglong, LongLong)
  365. Q_DECLARE_BUILTIN_METATYPE(qulonglong, ULongLong)
  366. Q_DECLARE_BUILTIN_METATYPE(QStringList, QStringList)
  367. Q_DECLARE_BUILTIN_METATYPE(QBitArray, QBitArray)
  368. Q_DECLARE_BUILTIN_METATYPE(QDate, QDate)
  369. Q_DECLARE_BUILTIN_METATYPE(QTime, QTime)
  370. Q_DECLARE_BUILTIN_METATYPE(QDateTime, QDateTime)
  371. Q_DECLARE_BUILTIN_METATYPE(QUrl, QUrl)
  372. Q_DECLARE_BUILTIN_METATYPE(QLocale, QLocale)
  373. Q_DECLARE_BUILTIN_METATYPE(QRect, QRect)
  374. Q_DECLARE_BUILTIN_METATYPE(QRectF, QRectF)
  375. Q_DECLARE_BUILTIN_METATYPE(QSize, QSize)
  376. Q_DECLARE_BUILTIN_METATYPE(QSizeF, QSizeF)
  377. Q_DECLARE_BUILTIN_METATYPE(QLine, QLine)
  378. Q_DECLARE_BUILTIN_METATYPE(QLineF, QLineF)
  379. Q_DECLARE_BUILTIN_METATYPE(QPoint, QPoint)
  380. Q_DECLARE_BUILTIN_METATYPE(QPointF, QPointF)
  381. #ifndef QT_NO_REGEXP
  382. Q_DECLARE_BUILTIN_METATYPE(QRegExp, QRegExp)
  383. #endif
  384. Q_DECLARE_BUILTIN_METATYPE(QEasingCurve, QEasingCurve)
  385.  
  386. #ifdef QT3_SUPPORT
  387. Q_DECLARE_BUILTIN_METATYPE(QColorGroup, QColorGroup)
  388. #endif
  389. Q_DECLARE_BUILTIN_METATYPE(QFont, QFont)
  390. Q_DECLARE_BUILTIN_METATYPE(QPixmap, QPixmap)
  391. Q_DECLARE_BUILTIN_METATYPE(QBrush, QBrush)
  392. Q_DECLARE_BUILTIN_METATYPE(QColor, QColor)
  393. Q_DECLARE_BUILTIN_METATYPE(QPalette, QPalette)
  394. Q_DECLARE_BUILTIN_METATYPE(QIcon, QIcon)
  395. Q_DECLARE_BUILTIN_METATYPE(QImage, QImage)
  396. Q_DECLARE_BUILTIN_METATYPE(QPolygon, QPolygon)
  397. Q_DECLARE_BUILTIN_METATYPE(QRegion, QRegion)
  398. Q_DECLARE_BUILTIN_METATYPE(QBitmap, QBitmap)
  399. Q_DECLARE_BUILTIN_METATYPE(QCursor, QCursor)
  400. Q_DECLARE_BUILTIN_METATYPE(QSizePolicy, QSizePolicy)
  401. Q_DECLARE_BUILTIN_METATYPE(QKeySequence, QKeySequence)
  402. Q_DECLARE_BUILTIN_METATYPE(QPen, QPen)
  403. Q_DECLARE_BUILTIN_METATYPE(QTextLength, QTextLength)
  404. Q_DECLARE_BUILTIN_METATYPE(QTextFormat, QTextFormat)
  405. Q_DECLARE_BUILTIN_METATYPE(QMatrix, QMatrix)
  406. Q_DECLARE_BUILTIN_METATYPE(QTransform, QTransform)
  407. Q_DECLARE_BUILTIN_METATYPE(QMatrix4x4, QMatrix4x4)
  408. Q_DECLARE_BUILTIN_METATYPE(QVector2D, QVector2D)
  409. Q_DECLARE_BUILTIN_METATYPE(QVector3D, QVector3D)
  410. Q_DECLARE_BUILTIN_METATYPE(QVector4D, QVector4D)
  411. Q_DECLARE_BUILTIN_METATYPE(QQuaternion, QQuaternion)
  412. Q_DECLARE_BUILTIN_METATYPE(QVariant, QVariant)
  413.  
  414. QT_END_HEADER
  415.  
  416. #endif // QMETATYPE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement