Qt 4.8
qmetatype.cpp
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 #include "qmetatype.h"
43 #include "qobjectdefs.h"
44 #include "qdatetime.h"
45 #include "qbytearray.h"
46 #include "qreadwritelock.h"
47 #include "qstring.h"
48 #include "qstringlist.h"
49 #include "qvector.h"
50 #include "qlocale.h"
51 #include "qeasingcurve.h"
52 
53 #ifdef QT_BOOTSTRAPPED
54 # ifndef QT_NO_GEOM_VARIANT
55 # define QT_NO_GEOM_VARIANT
56 # endif
57 #else
58 # include "qbitarray.h"
59 # include "qurl.h"
60 # include "qvariant.h"
61 #endif
62 
63 #ifndef QT_NO_GEOM_VARIANT
64 # include "qsize.h"
65 # include "qpoint.h"
66 # include "qrect.h"
67 # include "qline.h"
68 #endif
69 
71 
72 #define NS(x) QT_PREPEND_NAMESPACE(x)
73 
235 #define QT_ADD_STATIC_METATYPE(STR, TP) \
236  { STR, sizeof(STR) - 1, TP }
237 
238 /* Note: these MUST be in the order of the enums */
239 static const struct { const char * typeName; int typeNameLength; int type; } types[] = {
240 
241  /* All Core types */
272 
273  /* All GUI types */
274  QT_ADD_STATIC_METATYPE("QColorGroup", 63),
298 
299  /* All Metatype builtins */
311 
312  /* Type aliases - order doesn't matter */
313  QT_ADD_STATIC_METATYPE("unsigned long", QMetaType::ULong),
314  QT_ADD_STATIC_METATYPE("unsigned int", QMetaType::UInt),
315  QT_ADD_STATIC_METATYPE("unsigned short", QMetaType::UShort),
316  QT_ADD_STATIC_METATYPE("unsigned char", QMetaType::UChar),
318  QT_ADD_STATIC_METATYPE("unsigned long long", QMetaType::ULongLong),
320  QT_ADD_STATIC_METATYPE("signed char", QMetaType::Char),
329  QT_ADD_STATIC_METATYPE("QMap<QString,QVariant>", QMetaType::QVariantMap),
330  QT_ADD_STATIC_METATYPE("QHash<QString,QVariant>", QMetaType::QVariantHash),
331  // let QMetaTypeId2 figure out the type at compile time
333 
334  {0, 0, QMetaType::Void}
335 };
336 
338 {
341 #ifndef QT_NO_DATASTREAM
344 #endif
345 };
347 
349 {
350 public:
352 #ifndef QT_NO_DATASTREAM
353  , saveOp(0), loadOp(0)
354 #endif
355  {}
356 
360 #ifndef QT_NO_DATASTREAM
363 #endif
364  int alias;
365 };
366 
369 Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
370 
371 #ifndef QT_NO_DATASTREAM
372 
374 void QMetaType::registerStreamOperators(const char *typeName, SaveOperator saveOp,
375  LoadOperator loadOp)
376 {
377  int idx = type(typeName);
378  if (!idx)
379  return;
380  registerStreamOperators(idx, saveOp, loadOp);
381 }
382 
385 void QMetaType::registerStreamOperators(int idx, SaveOperator saveOp,
386  LoadOperator loadOp)
387 {
388  if (idx < User)
389  return; //builtin types should not be registered;
391  if (!ct)
392  return;
393  QWriteLocker locker(customTypesLock());
394  QCustomTypeInfo &inf = (*ct)[idx - User];
395  inf.saveOp = saveOp;
396  inf.loadOp = loadOp;
397 }
398 #endif // QT_NO_DATASTREAM
399 
406 const char *QMetaType::typeName(int type)
407 {
408  enum { GuiTypeCount = LastGuiType - FirstGuiType };
409 
410  if (type >= 0 && type <= LastCoreType) {
411  return types[type].typeName;
412  } else if (type >= FirstGuiType && type <= LastGuiType) {
413  return types[type - FirstGuiType + LastCoreType + 1].typeName;
414  } else if (type >= FirstCoreExtType && type <= LastCoreExtType) {
415  return types[type - FirstCoreExtType + GuiTypeCount + LastCoreType + 2].typeName;
416  } else if (type >= User) {
417  const QVector<QCustomTypeInfo> * const ct = customTypes();
418  QReadLocker locker(customTypesLock());
419  return ct && ct->count() > type - User && !ct->at(type - User).typeName.isEmpty()
420  ? ct->at(type - User).typeName.constData()
421  : static_cast<const char *>(0);
422  }
423 
424  return 0;
425 }
426 
433 static inline int qMetaTypeStaticType(const char *typeName, int length)
434 {
435  int i = 0;
436  while (types[i].typeName && ((length != types[i].typeNameLength)
437  || strcmp(typeName, types[i].typeName))) {
438  ++i;
439  }
440  return types[i].type;
441 }
442 
450 static int qMetaTypeCustomType_unlocked(const char *typeName, int length)
451 {
452  const QVector<QCustomTypeInfo> * const ct = customTypes();
453  if (!ct)
454  return 0;
455 
456  for (int v = 0; v < ct->count(); ++v) {
457  const QCustomTypeInfo &customInfo = ct->at(v);
458  if ((length == customInfo.typeName.size())
459  && !strcmp(typeName, customInfo.typeName.constData())) {
460  if (customInfo.alias >= 0)
461  return customInfo.alias;
462  return v + QMetaType::User;
463  }
464  }
465  return 0;
466 }
467 
477 int QMetaType::registerType(const char *typeName, Destructor destructor,
478  Constructor constructor)
479 {
481  if (!ct || !typeName || !destructor || !constructor)
482  return -1;
483 
484 #ifdef QT_NO_QOBJECT
485  NS(QByteArray) normalizedTypeName = typeName;
486 #else
487  NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName);
488 #endif
489 
490  int idx = qMetaTypeStaticType(normalizedTypeName.constData(),
491  normalizedTypeName.size());
492 
493  if (!idx) {
494  QWriteLocker locker(customTypesLock());
495  idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(),
496  normalizedTypeName.size());
497  if (!idx) {
498  QCustomTypeInfo inf;
499  inf.typeName = normalizedTypeName;
500  inf.constr = constructor;
501  inf.destr = destructor;
502  inf.alias = -1;
503  idx = ct->size() + User;
504  ct->append(inf);
505  }
506  }
507  return idx;
508 }
509 
515 int QMetaType::registerTypedef(const char* typeName, int aliasId)
516 {
518  if (!ct || !typeName)
519  return -1;
520 
521 #ifdef QT_NO_QOBJECT
522  NS(QByteArray) normalizedTypeName = typeName;
523 #else
524  NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName);
525 #endif
526 
527  int idx = qMetaTypeStaticType(normalizedTypeName.constData(),
528  normalizedTypeName.size());
529 
530  if (idx) {
531  Q_ASSERT(idx == aliasId);
532  return idx;
533  }
534 
535  QWriteLocker locker(customTypesLock());
536  idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(),
537  normalizedTypeName.size());
538 
539  if (idx)
540  return idx;
541 
542  QCustomTypeInfo inf;
543  inf.typeName = normalizedTypeName;
544  inf.alias = aliasId;
545  inf.constr = 0;
546  inf.destr = 0;
547  ct->append(inf);
548  return aliasId;
549 }
550 
562 {
564  if (!ct || !typeName)
565  return;
566 
567 #ifdef QT_NO_QOBJECT
568  NS(QByteArray) normalizedTypeName = typeName;
569 #else
570  NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName);
571 #endif
572  QWriteLocker locker(customTypesLock());
573  for (int v = 0; v < ct->count(); ++v) {
574  if (ct->at(v).typeName == typeName) {
575  QCustomTypeInfo &inf = (*ct)[v];
576  inf.typeName.clear();
577  inf.constr = 0;
578  inf.destr = 0;
579  inf.alias = -1;
580  }
581  }
582 }
583 
591 {
592  if (type >= 0 && type < User) {
593  // predefined type
594  return true;
595  }
596  QReadLocker locker(customTypesLock());
597  const QVector<QCustomTypeInfo> * const ct = customTypes();
598  return ((type >= User) && (ct && ct->count() > type - User) && !ct->at(type - User).typeName.isEmpty());
599 }
600 
607 int QMetaType::type(const char *typeName)
608 {
609  int length = qstrlen(typeName);
610  if (!length)
611  return 0;
612  int type = qMetaTypeStaticType(typeName, length);
613  if (!type) {
614  QReadLocker locker(customTypesLock());
615  type = qMetaTypeCustomType_unlocked(typeName, length);
616 #ifndef QT_NO_QOBJECT
617  if (!type) {
618  const NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName);
619  type = qMetaTypeStaticType(normalizedTypeName.constData(),
620  normalizedTypeName.size());
621  if (!type) {
622  type = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(),
623  normalizedTypeName.size());
624  }
625  }
626 #endif
627  }
628  return type;
629 }
630 
631 #ifndef QT_NO_DATASTREAM
632 
646 bool QMetaType::save(QDataStream &stream, int type, const void *data)
647 {
648  if (!data || !isRegistered(type))
649  return false;
650 
651  switch(type) {
652  case QMetaType::Void:
653  case QMetaType::VoidStar:
656  return false;
657  case QMetaType::Long:
658  stream << qlonglong(*static_cast<const long *>(data));
659  break;
660  case QMetaType::Int:
661  stream << *static_cast<const int *>(data);
662  break;
663  case QMetaType::Short:
664  stream << *static_cast<const short *>(data);
665  break;
666  case QMetaType::Char:
667  // force a char to be signed
668  stream << *static_cast<const signed char *>(data);
669  break;
670  case QMetaType::ULong:
671  stream << qulonglong(*static_cast<const ulong *>(data));
672  break;
673  case QMetaType::UInt:
674  stream << *static_cast<const uint *>(data);
675  break;
676  case QMetaType::LongLong:
677  stream << *static_cast<const qlonglong *>(data);
678  break;
680  stream << *static_cast<const qulonglong *>(data);
681  break;
682  case QMetaType::UShort:
683  stream << *static_cast<const ushort *>(data);
684  break;
685  case QMetaType::UChar:
686  stream << *static_cast<const uchar *>(data);
687  break;
688  case QMetaType::Bool:
689  stream << qint8(*static_cast<const bool *>(data));
690  break;
691  case QMetaType::Float:
692  stream << *static_cast<const float *>(data);
693  break;
694  case QMetaType::Double:
695  stream << *static_cast<const double *>(data);
696  break;
697  case QMetaType::QChar:
698  stream << *static_cast<const NS(QChar) *>(data);
699  break;
700 #ifndef QT_BOOTSTRAPPED
702  stream << *static_cast<const NS(QVariantMap)*>(data);
703  break;
705  stream << *static_cast<const NS(QVariantHash)*>(data);
706  break;
708  stream << *static_cast<const NS(QVariantList)*>(data);
709  break;
710  case QMetaType::QVariant:
711  stream << *static_cast<const NS(QVariant)*>(data);
712  break;
713 #endif
715  stream << *static_cast<const NS(QByteArray)*>(data);
716  break;
717  case QMetaType::QString:
718  stream << *static_cast<const NS(QString)*>(data);
719  break;
721  stream << *static_cast<const NS(QStringList)*>(data);
722  break;
723 #ifndef QT_BOOTSTRAPPED
725  stream << *static_cast<const NS(QBitArray)*>(data);
726  break;
727 #endif
728  case QMetaType::QDate:
729  stream << *static_cast<const NS(QDate)*>(data);
730  break;
731  case QMetaType::QTime:
732  stream << *static_cast<const NS(QTime)*>(data);
733  break;
735  stream << *static_cast<const NS(QDateTime)*>(data);
736  break;
737 #ifndef QT_BOOTSTRAPPED
738  case QMetaType::QUrl:
739  stream << *static_cast<const NS(QUrl)*>(data);
740  break;
741 #endif
742  case QMetaType::QLocale:
743  stream << *static_cast<const NS(QLocale)*>(data);
744  break;
745 #ifndef QT_NO_GEOM_VARIANT
746  case QMetaType::QRect:
747  stream << *static_cast<const NS(QRect)*>(data);
748  break;
749  case QMetaType::QRectF:
750  stream << *static_cast<const NS(QRectF)*>(data);
751  break;
752  case QMetaType::QSize:
753  stream << *static_cast<const NS(QSize)*>(data);
754  break;
755  case QMetaType::QSizeF:
756  stream << *static_cast<const NS(QSizeF)*>(data);
757  break;
758  case QMetaType::QLine:
759  stream << *static_cast<const NS(QLine)*>(data);
760  break;
761  case QMetaType::QLineF:
762  stream << *static_cast<const NS(QLineF)*>(data);
763  break;
764  case QMetaType::QPoint:
765  stream << *static_cast<const NS(QPoint)*>(data);
766  break;
767  case QMetaType::QPointF:
768  stream << *static_cast<const NS(QPointF)*>(data);
769  break;
770 #endif
771 #ifndef QT_NO_REGEXP
772  case QMetaType::QRegExp:
773  stream << *static_cast<const NS(QRegExp)*>(data);
774  break;
775 #endif
776 #ifndef QT_BOOTSTRAPPED
778  stream << *static_cast<const NS(QEasingCurve)*>(data);
779  break;
780 #endif
781 #ifdef QT3_SUPPORT
782  case QMetaType::QColorGroup:
783 #endif
784  case QMetaType::QFont:
785  case QMetaType::QPixmap:
786  case QMetaType::QBrush:
787  case QMetaType::QColor:
788  case QMetaType::QPalette:
789  case QMetaType::QIcon:
790  case QMetaType::QImage:
791  case QMetaType::QPolygon:
792  case QMetaType::QRegion:
793  case QMetaType::QBitmap:
794  case QMetaType::QCursor:
797  case QMetaType::QPen:
800  case QMetaType::QMatrix:
807  if (!qMetaTypeGuiHelper)
808  return false;
809  qMetaTypeGuiHelper[type - FirstGuiType].saveOp(stream, data);
810  break;
811  default: {
812  const QVector<QCustomTypeInfo> * const ct = customTypes();
813  if (!ct)
814  return false;
815 
816  SaveOperator saveOp = 0;
817  {
818  QReadLocker locker(customTypesLock());
819  saveOp = ct->at(type - User).saveOp;
820  }
821 
822  if (!saveOp)
823  return false;
824  saveOp(stream, data);
825  break; }
826  }
827 
828  return true;
829 }
830 
846 {
847  if (!data || !isRegistered(type))
848  return false;
849 
850  switch(type) {
851  case QMetaType::Void:
852  case QMetaType::VoidStar:
855  return false;
856  case QMetaType::Long: {
857  qlonglong l;
858  stream >> l;
859  *static_cast<long *>(data) = long(l);
860  break; }
861  case QMetaType::Int:
862  stream >> *static_cast<int *>(data);
863  break;
864  case QMetaType::Short:
865  stream >> *static_cast<short *>(data);
866  break;
867  case QMetaType::Char:
868  // force a char to be signed
869  stream >> *static_cast<signed char *>(data);
870  break;
871  case QMetaType::ULong: {
872  qulonglong ul;
873  stream >> ul;
874  *static_cast<ulong *>(data) = ulong(ul);
875  break; }
876  case QMetaType::UInt:
877  stream >> *static_cast<uint *>(data);
878  break;
879  case QMetaType::LongLong:
880  stream >> *static_cast<qlonglong *>(data);
881  break;
883  stream >> *static_cast<qulonglong *>(data);
884  break;
885  case QMetaType::UShort:
886  stream >> *static_cast<ushort *>(data);
887  break;
888  case QMetaType::UChar:
889  stream >> *static_cast<uchar *>(data);
890  break;
891  case QMetaType::Bool: {
892  qint8 b;
893  stream >> b;
894  *static_cast<bool *>(data) = b;
895  break; }
896  case QMetaType::Float:
897  stream >> *static_cast<float *>(data);
898  break;
899  case QMetaType::Double:
900  stream >> *static_cast<double *>(data);
901  break;
902  case QMetaType::QChar:
903  stream >> *static_cast< NS(QChar)*>(data);
904  break;
905 #ifndef QT_BOOTSTRAPPED
907  stream >> *static_cast< NS(QVariantMap)*>(data);
908  break;
910  stream >> *static_cast< NS(QVariantHash)*>(data);
911  break;
913  stream >> *static_cast< NS(QVariantList)*>(data);
914  break;
915  case QMetaType::QVariant:
916  stream >> *static_cast< NS(QVariant)*>(data);
917  break;
918 #endif
920  stream >> *static_cast< NS(QByteArray)*>(data);
921  break;
922  case QMetaType::QString:
923  stream >> *static_cast< NS(QString)*>(data);
924  break;
926  stream >> *static_cast< NS(QStringList)*>(data);
927  break;
928 #ifndef QT_BOOTSTRAPPED
930  stream >> *static_cast< NS(QBitArray)*>(data);
931  break;
932 #endif
933  case QMetaType::QDate:
934  stream >> *static_cast< NS(QDate)*>(data);
935  break;
936  case QMetaType::QTime:
937  stream >> *static_cast< NS(QTime)*>(data);
938  break;
940  stream >> *static_cast< NS(QDateTime)*>(data);
941  break;
942 #ifndef QT_BOOTSTRAPPED
943  case QMetaType::QUrl:
944  stream >> *static_cast< NS(QUrl)*>(data);
945  break;
946 #endif
947  case QMetaType::QLocale:
948  stream >> *static_cast< NS(QLocale)*>(data);
949  break;
950 #ifndef QT_NO_GEOM_VARIANT
951  case QMetaType::QRect:
952  stream >> *static_cast< NS(QRect)*>(data);
953  break;
954  case QMetaType::QRectF:
955  stream >> *static_cast< NS(QRectF)*>(data);
956  break;
957  case QMetaType::QSize:
958  stream >> *static_cast< NS(QSize)*>(data);
959  break;
960  case QMetaType::QSizeF:
961  stream >> *static_cast< NS(QSizeF)*>(data);
962  break;
963  case QMetaType::QLine:
964  stream >> *static_cast< NS(QLine)*>(data);
965  break;
966  case QMetaType::QLineF:
967  stream >> *static_cast< NS(QLineF)*>(data);
968  break;
969  case QMetaType::QPoint:
970  stream >> *static_cast< NS(QPoint)*>(data);
971  break;
972  case QMetaType::QPointF:
973  stream >> *static_cast< NS(QPointF)*>(data);
974  break;
975 #endif
976 #ifndef QT_NO_REGEXP
977  case QMetaType::QRegExp:
978  stream >> *static_cast< NS(QRegExp)*>(data);
979  break;
980 #endif
981 #ifndef QT_BOOTSTRAPPED
983  stream >> *static_cast< NS(QEasingCurve)*>(data);
984  break;
985 #endif
986 #ifdef QT3_SUPPORT
987  case QMetaType::QColorGroup:
988 #endif
989  case QMetaType::QFont:
990  case QMetaType::QPixmap:
991  case QMetaType::QBrush:
992  case QMetaType::QColor:
993  case QMetaType::QPalette:
994  case QMetaType::QIcon:
995  case QMetaType::QImage:
996  case QMetaType::QPolygon:
997  case QMetaType::QRegion:
998  case QMetaType::QBitmap:
999  case QMetaType::QCursor:
1002  case QMetaType::QPen:
1005  case QMetaType::QMatrix:
1006  case QMetaType::QTransform:
1007  case QMetaType::QMatrix4x4:
1008  case QMetaType::QVector2D:
1009  case QMetaType::QVector3D:
1010  case QMetaType::QVector4D:
1012  if (!qMetaTypeGuiHelper)
1013  return false;
1014  qMetaTypeGuiHelper[type - FirstGuiType].loadOp(stream, data);
1015  break;
1016  default: {
1017  const QVector<QCustomTypeInfo> * const ct = customTypes();
1018  if (!ct)
1019  return false;
1020 
1021  LoadOperator loadOp = 0;
1022  {
1023  QReadLocker locker(customTypesLock());
1024  loadOp = ct->at(type - User).loadOp;
1025  }
1026 
1027  if (!loadOp)
1028  return false;
1029  loadOp(stream, data);
1030  break; }
1031  }
1032  return true;
1033 }
1034 #endif // QT_NO_DATASTREAM
1035 
1042 void *QMetaType::construct(int type, const void *copy)
1043 {
1044  if (copy) {
1045  switch(type) {
1046  case QMetaType::VoidStar:
1049  return new void *(*static_cast<void* const *>(copy));
1050  case QMetaType::Long:
1051  return new long(*static_cast<const long*>(copy));
1052  case QMetaType::Int:
1053  return new int(*static_cast<const int*>(copy));
1054  case QMetaType::Short:
1055  return new short(*static_cast<const short*>(copy));
1056  case QMetaType::Char:
1057  return new char(*static_cast<const char*>(copy));
1058  case QMetaType::ULong:
1059  return new ulong(*static_cast<const ulong*>(copy));
1060  case QMetaType::UInt:
1061  return new uint(*static_cast<const uint*>(copy));
1062  case QMetaType::LongLong:
1063  return new qlonglong(*static_cast<const qlonglong*>(copy));
1064  case QMetaType::ULongLong:
1065  return new qulonglong(*static_cast<const qulonglong*>(copy));
1066  case QMetaType::UShort:
1067  return new ushort(*static_cast<const ushort*>(copy));
1068  case QMetaType::UChar:
1069  return new uchar(*static_cast<const uchar*>(copy));
1070  case QMetaType::Bool:
1071  return new bool(*static_cast<const bool*>(copy));
1072  case QMetaType::Float:
1073  return new float(*static_cast<const float*>(copy));
1074  case QMetaType::Double:
1075  return new double(*static_cast<const double*>(copy));
1076  case QMetaType::QChar:
1077  return new NS(QChar)(*static_cast<const NS(QChar)*>(copy));
1078 #ifndef QT_BOOTSTRAPPED
1080  return new NS(QVariantMap)(*static_cast<const NS(QVariantMap)*>(copy));
1082  return new NS(QVariantHash)(*static_cast<const NS(QVariantHash)*>(copy));
1084  return new NS(QVariantList)(*static_cast<const NS(QVariantList)*>(copy));
1085  case QMetaType::QVariant:
1086  return new NS(QVariant)(*static_cast<const NS(QVariant)*>(copy));
1087 #endif
1088  case QMetaType::QByteArray:
1089  return new NS(QByteArray)(*static_cast<const NS(QByteArray)*>(copy));
1090  case QMetaType::QString:
1091  return new NS(QString)(*static_cast<const NS(QString)*>(copy));
1093  return new NS(QStringList)(*static_cast<const NS(QStringList)*>(copy));
1094 #ifndef QT_BOOTSTRAPPED
1095  case QMetaType::QBitArray:
1096  return new NS(QBitArray)(*static_cast<const NS(QBitArray)*>(copy));
1097 #endif
1098  case QMetaType::QDate:
1099  return new NS(QDate)(*static_cast<const NS(QDate)*>(copy));
1100  case QMetaType::QTime:
1101  return new NS(QTime)(*static_cast<const NS(QTime)*>(copy));
1102  case QMetaType::QDateTime:
1103  return new NS(QDateTime)(*static_cast<const NS(QDateTime)*>(copy));
1104 #ifndef QT_BOOTSTRAPPED
1105  case QMetaType::QUrl:
1106  return new NS(QUrl)(*static_cast<const NS(QUrl)*>(copy));
1107 #endif
1108  case QMetaType::QLocale:
1109  return new NS(QLocale)(*static_cast<const NS(QLocale)*>(copy));
1110 #ifndef QT_NO_GEOM_VARIANT
1111  case QMetaType::QRect:
1112  return new NS(QRect)(*static_cast<const NS(QRect)*>(copy));
1113  case QMetaType::QRectF:
1114  return new NS(QRectF)(*static_cast<const NS(QRectF)*>(copy));
1115  case QMetaType::QSize:
1116  return new NS(QSize)(*static_cast<const NS(QSize)*>(copy));
1117  case QMetaType::QSizeF:
1118  return new NS(QSizeF)(*static_cast<const NS(QSizeF)*>(copy));
1119  case QMetaType::QLine:
1120  return new NS(QLine)(*static_cast<const NS(QLine)*>(copy));
1121  case QMetaType::QLineF:
1122  return new NS(QLineF)(*static_cast<const NS(QLineF)*>(copy));
1123  case QMetaType::QPoint:
1124  return new NS(QPoint)(*static_cast<const NS(QPoint)*>(copy));
1125  case QMetaType::QPointF:
1126  return new NS(QPointF)(*static_cast<const NS(QPointF)*>(copy));
1127 #endif
1128 #ifndef QT_NO_REGEXP
1129  case QMetaType::QRegExp:
1130  return new NS(QRegExp)(*static_cast<const NS(QRegExp)*>(copy));
1131 #endif
1132 #ifndef QT_BOOTSTRAPPED
1134  return new NS(QEasingCurve)(*static_cast<const NS(QEasingCurve)*>(copy));
1135 #endif
1136  case QMetaType::Void:
1137  return 0;
1138  default:
1139  ;
1140  }
1141  } else {
1142  switch(type) {
1143  case QMetaType::VoidStar:
1146  return new void *;
1147  case QMetaType::Long:
1148  return new long;
1149  case QMetaType::Int:
1150  return new int;
1151  case QMetaType::Short:
1152  return new short;
1153  case QMetaType::Char:
1154  return new char;
1155  case QMetaType::ULong:
1156  return new ulong;
1157  case QMetaType::UInt:
1158  return new uint;
1159  case QMetaType::LongLong:
1160  return new qlonglong;
1161  case QMetaType::ULongLong:
1162  return new qulonglong;
1163  case QMetaType::UShort:
1164  return new ushort;
1165  case QMetaType::UChar:
1166  return new uchar;
1167  case QMetaType::Bool:
1168  return new bool;
1169  case QMetaType::Float:
1170  return new float;
1171  case QMetaType::Double:
1172  return new double;
1173  case QMetaType::QChar:
1174  return new NS(QChar);
1175 #ifndef QT_BOOTSTRAPPED
1177  return new NS(QVariantMap);
1179  return new NS(QVariantHash);
1181  return new NS(QVariantList);
1182  case QMetaType::QVariant:
1183  return new NS(QVariant);
1184 #endif
1185  case QMetaType::QByteArray:
1186  return new NS(QByteArray);
1187  case QMetaType::QString:
1188  return new NS(QString);
1190  return new NS(QStringList);
1191 #ifndef QT_BOOTSTRAPPED
1192  case QMetaType::QBitArray:
1193  return new NS(QBitArray);
1194 #endif
1195  case QMetaType::QDate:
1196  return new NS(QDate);
1197  case QMetaType::QTime:
1198  return new NS(QTime);
1199  case QMetaType::QDateTime:
1200  return new NS(QDateTime);
1201 #ifndef QT_BOOTSTRAPPED
1202  case QMetaType::QUrl:
1203  return new NS(QUrl);
1204 #endif
1205  case QMetaType::QLocale:
1206  return new NS(QLocale);
1207 #ifndef QT_NO_GEOM_VARIANT
1208  case QMetaType::QRect:
1209  return new NS(QRect);
1210  case QMetaType::QRectF:
1211  return new NS(QRectF);
1212  case QMetaType::QSize:
1213  return new NS(QSize);
1214  case QMetaType::QSizeF:
1215  return new NS(QSizeF);
1216  case QMetaType::QLine:
1217  return new NS(QLine);
1218  case QMetaType::QLineF:
1219  return new NS(QLineF);
1220  case QMetaType::QPoint:
1221  return new NS(QPoint);
1222  case QMetaType::QPointF:
1223  return new NS(QPointF);
1224 #endif
1225 #ifndef QT_NO_REGEXP
1226  case QMetaType::QRegExp:
1227  return new NS(QRegExp);
1228 #endif
1229 #ifndef QT_BOOTSTRAPPED
1231  return new NS(QEasingCurve);
1232 #endif
1233  case QMetaType::Void:
1234  return 0;
1235  default:
1236  ;
1237  }
1238  }
1239 
1240  Constructor constr = 0;
1241  if (type >= FirstGuiType && type <= LastGuiType) {
1242  if (!qMetaTypeGuiHelper)
1243  return 0;
1244  constr = qMetaTypeGuiHelper[type - FirstGuiType].constr;
1245  } else {
1246  const QVector<QCustomTypeInfo> * const ct = customTypes();
1247  QReadLocker locker(customTypesLock());
1248  if (type < User || !ct || ct->count() <= type - User)
1249  return 0;
1250  if (ct->at(type - User).typeName.isEmpty())
1251  return 0;
1252  constr = ct->at(type - User).constr;
1253  }
1254 
1255  return constr(copy);
1256 }
1257 
1263 void QMetaType::destroy(int type, void *data)
1264 {
1265  if (!data)
1266  return;
1267  switch(type) {
1268  case QMetaType::VoidStar:
1271  delete static_cast<void**>(data);
1272  break;
1273  case QMetaType::Long:
1274  delete static_cast<long*>(data);
1275  break;
1276  case QMetaType::Int:
1277  delete static_cast<int*>(data);
1278  break;
1279  case QMetaType::Short:
1280  delete static_cast<short*>(data);
1281  break;
1282  case QMetaType::Char:
1283  delete static_cast<char*>(data);
1284  break;
1285  case QMetaType::ULong:
1286  delete static_cast<ulong*>(data);
1287  break;
1288  case QMetaType::LongLong:
1289  delete static_cast<qlonglong*>(data);
1290  break;
1291  case QMetaType::ULongLong:
1292  delete static_cast<qulonglong*>(data);
1293  break;
1294  case QMetaType::UInt:
1295  delete static_cast<uint*>(data);
1296  break;
1297  case QMetaType::UShort:
1298  delete static_cast<ushort*>(data);
1299  break;
1300  case QMetaType::UChar:
1301  delete static_cast<uchar*>(data);
1302  break;
1303  case QMetaType::Bool:
1304  delete static_cast<bool*>(data);
1305  break;
1306  case QMetaType::Float:
1307  delete static_cast<float*>(data);
1308  break;
1309  case QMetaType::Double:
1310  delete static_cast<double*>(data);
1311  break;
1312  case QMetaType::QChar:
1313  delete static_cast< NS(QChar)* >(data);
1314  break;
1315 #ifndef QT_BOOTSTRAPPED
1317  delete static_cast< NS(QVariantMap)* >(data);
1318  break;
1320  delete static_cast< NS(QVariantHash)* >(data);
1321  break;
1323  delete static_cast< NS(QVariantList)* >(data);
1324  break;
1325  case QMetaType::QVariant:
1326  delete static_cast< NS(QVariant)* >(data);
1327  break;
1328 #endif
1329  case QMetaType::QByteArray:
1330  delete static_cast< NS(QByteArray)* >(data);
1331  break;
1332  case QMetaType::QString:
1333  delete static_cast< NS(QString)* >(data);
1334  break;
1336  delete static_cast< NS(QStringList)* >(data);
1337  break;
1338 #ifndef QT_BOOTSTRAPPED
1339  case QMetaType::QBitArray:
1340  delete static_cast< NS(QBitArray)* >(data);
1341  break;
1342 #endif
1343  case QMetaType::QDate:
1344  delete static_cast< NS(QDate)* >(data);
1345  break;
1346  case QMetaType::QTime:
1347  delete static_cast< NS(QTime)* >(data);
1348  break;
1349  case QMetaType::QDateTime:
1350  delete static_cast< NS(QDateTime)* >(data);
1351  break;
1352 #ifndef QT_BOOTSTRAPPED
1353  case QMetaType::QUrl:
1354  delete static_cast< NS(QUrl)* >(data);
1355 #endif
1356  break;
1357  case QMetaType::QLocale:
1358  delete static_cast< NS(QLocale)* >(data);
1359  break;
1360 #ifndef QT_NO_GEOM_VARIANT
1361  case QMetaType::QRect:
1362  delete static_cast< NS(QRect)* >(data);
1363  break;
1364  case QMetaType::QRectF:
1365  delete static_cast< NS(QRectF)* >(data);
1366  break;
1367  case QMetaType::QSize:
1368  delete static_cast< NS(QSize)* >(data);
1369  break;
1370  case QMetaType::QSizeF:
1371  delete static_cast< NS(QSizeF)* >(data);
1372  break;
1373  case QMetaType::QLine:
1374  delete static_cast< NS(QLine)* >(data);
1375  break;
1376  case QMetaType::QLineF:
1377  delete static_cast< NS(QLineF)* >(data);
1378  break;
1379  case QMetaType::QPoint:
1380  delete static_cast< NS(QPoint)* >(data);
1381  break;
1382  case QMetaType::QPointF:
1383  delete static_cast< NS(QPointF)* >(data);
1384  break;
1385 #endif
1386 #ifndef QT_NO_REGEXP
1387  case QMetaType::QRegExp:
1388  delete static_cast< NS(QRegExp)* >(data);
1389  break;
1390 #endif
1391 #ifndef QT_BOOTSTRAPPED
1393  delete static_cast< NS(QEasingCurve)* >(data);
1394  break;
1395 #endif
1396  case QMetaType::Void:
1397  break;
1398  default: {
1399  const QVector<QCustomTypeInfo> * const ct = customTypes();
1400  Destructor destr = 0;
1401  if (type >= FirstGuiType && type <= LastGuiType) {
1403 
1404  if (!qMetaTypeGuiHelper)
1405  return;
1406  destr = qMetaTypeGuiHelper[type - FirstGuiType].destr;
1407  } else {
1408  QReadLocker locker(customTypesLock());
1409  if (type < User || !ct || ct->count() <= type - User)
1410  break;
1411  if (ct->at(type - User).typeName.isEmpty())
1412  break;
1413  destr = ct->at(type - User).destr;
1414  }
1415  destr(data);
1416  break; }
1417  }
1418 }
1419 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static void unregisterType(const char *typeName)
Unregisters a user type, with typeName.
Definition: qmetatype.cpp:561
const QStringList & customTypes
int type
Definition: qmetatype.cpp:239
Q_DECLARE_TYPEINFO(QCustomTypeInfo, Q_MOVABLE_TYPE)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
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
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QMetaType::Constructor constr
Definition: qmetatype.cpp:339
static int qMetaTypeStaticType(const char *typeName, int length)
Similar to QMetaType::type(), but only looks in the static set of types.
Definition: qmetatype.cpp:433
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
int typeNameLength
Definition: qmetatype.cpp:239
void *(* Constructor)(const void *)
Definition: qmetatype.h:105
The QDate class provides date functions.
Definition: qdatetime.h:55
void(* LoadOperator)(QDataStream &, void *)
Definition: qmetatype.h:109
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
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.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
static void * construct(int type, const void *copy=0)
Returns a copy of copy, assuming it is of type type.
Definition: qmetatype.cpp:1042
void(* Destructor)(void *)
Definition: qmetatype.h:104
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
QByteArray typeName
Definition: qmetatype.cpp:357
signed char qint8
Definition: qglobal.h:933
unsigned char uchar
Definition: qglobal.h:994
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
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
Q_CORE_EXPORT const QMetaTypeGuiHelper * qMetaTypeGuiHelper
Definition: qmetatype.cpp:346
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
static void destroy(int type, void *data)
Destroys the data, assuming it is of the type given.
Definition: qmetatype.cpp:1263
static void registerStreamOperators(const char *typeName, SaveOperator saveOp, LoadOperator loadOp)
Definition: qmetatype.cpp:374
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks f...
unsigned long ulong
Definition: qglobal.h:997
void(* SaveOperator)(QDataStream &, const void *)
Definition: qmetatype.h:108
QMetaType::Destructor destr
Definition: qmetatype.cpp:359
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
static int qMetaTypeCustomType_unlocked(const char *typeName, int length)
Similar to QMetaType::type(), but only looks in the custom set of types, and doesn&#39;t lock the mutex...
Definition: qmetatype.cpp:450
The QBitArray class provides an array of bits.
Definition: qbitarray.h:54
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QMetaType::SaveOperator saveOp
Definition: qmetatype.cpp:342
uint qstrlen(const char *str)
Definition: qbytearray.h:79
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
static const struct @32 types[]
static const char * typeName(int type)
Returns the type name associated with the given type, or 0 if no matching type was found...
Definition: qmetatype.cpp:406
unsigned short ushort
Definition: qglobal.h:995
The QReadWriteLock class provides read-write locking.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QFactoryLoader * l
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
static QByteArray normalizedType(const char *type)
Normalizes a type.
QMetaType::Destructor destr
Definition: qmetatype.cpp:340
#define NS(x)
Definition: qmetatype.cpp:72
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define QT_ADD_STATIC_METATYPE(STR, TP)
Definition: qmetatype.cpp:235
QMetaType::LoadOperator loadOp
Definition: qmetatype.cpp:343
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
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
QMetaType::LoadOperator loadOp
Definition: qmetatype.cpp:362
static bool load(QDataStream &stream, int type, void *data)
Reads the object of the specified type from the given stream into data.
Definition: qmetatype.cpp:845
QMetaType::SaveOperator saveOp
Definition: qmetatype.cpp:361
qint64 qlonglong
Definition: qglobal.h:951
static bool isRegistered(int type)
Returns true if the datatype with ID type is registered; otherwise returns false. ...
Definition: qmetatype.cpp:590
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
static bool save(QDataStream &stream, int type, const void *data)
Writes the object pointed to by data with the ID type to the given stream.
Definition: qmetatype.cpp:646
void clear()
Clears the contents of the byte array and makes it empty.
QMetaType::Constructor constr
Definition: qmetatype.cpp:358