| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| | ** | |
| | ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). | |
| | ** Contact: http://www.qt-project.org/legal | |
| | ** | |
| | ** This file is part of the QtCore module of the Qt Toolkit. | |
| | ** | |
| | ** $QT_BEGIN_LICENSE:LGPL$ | |
| | ** Commercial License Usage | |
| | ** Licensees holding valid commercial Qt licenses may use this file in | |
| | ** accordance with the commercial license agreement provided with the | |
| | ** Software or, alternatively, in accordance with the terms contained in | |
| | ** a written agreement between you and Digia. For licensing terms and | |
| | ** conditions see http://qt.digia.com/licensing. For further information | |
| | ** use the contact form at http://qt.digia.com/contact-us. | |
| | ** | |
| | ** GNU Lesser General Public License Usage | |
| | ** Alternatively, this file may be used under the terms of the GNU Lesser | |
| | ** General Public License version 2.1 as published by the Free Software | |
| | ** Foundation and appearing in the file LICENSE.LGPL included in the | |
| | ** packaging of this file. Please review the following information to | |
| | ** ensure the GNU Lesser General Public License version 2.1 requirements | |
| | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
| | ** | |
| | ** In addition, as a special exception, Digia gives you certain additional | |
| | ** rights. These rights are described in the Digia Qt LGPL Exception | |
| | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
| | ** | |
| | ** GNU General Public License Usage | |
| | ** Alternatively, this file may be used under the terms of the GNU | |
| | ** General Public License version 3.0 as published by the Free Software | |
| | ** Foundation and appearing in the file LICENSE.GPL included in the | |
| | ** packaging of this file. Please review the following information to | |
| | ** ensure the GNU General Public License version 3.0 requirements will be | |
| | ** met: http://www.gnu.org/copyleft/gpl.html. | |
| | ** | |
| | ** | |
| | ** $QT_END_LICENSE$ | |
| | ** | |
| | ****************************************************************************/**************************************************************************** | |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 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 "qmetatype_p.h" | - |
| 44 | #include "qobjectdefs.h" | - |
| 45 | #include "qdatetime.h" | - |
| 46 | #include "qbytearray.h" | - |
| 47 | #include "qreadwritelock.h" | - |
| 48 | #include "qstring.h" | - |
| 49 | #include "qstringlist.h" | - |
| 50 | #include "qvector.h" | - |
| 51 | #include "qlocale.h" | - |
| 52 | #include "qeasingcurve.h" | - |
| 53 | #include "quuid.h" | - |
| 54 | #include "qvariant.h" | - |
| 55 | #include "qmetatypeswitcher_p.h" | - |
| 56 | | - |
| 57 | #ifndef QT_BOOTSTRAPPED | - |
| 58 | # include "qbitarray.h" | - |
| 59 | # include "qurl.h" | - |
| 60 | # include "qvariant.h" | - |
| 61 | # include "qabstractitemmodel.h" | - |
| 62 | # include "qregularexpression.h" | - |
| 63 | # include "qjsonvalue.h" | - |
| 64 | # include "qjsonobject.h" | - |
| 65 | # include "qjsonarray.h" | - |
| 66 | # include "qjsondocument.h" | - |
| 67 | #endif | - |
| 68 | | - |
| 69 | #ifndef QT_NO_GEOM_VARIANT | - |
| 70 | # include "qsize.h" | - |
| 71 | # include "qpoint.h" | - |
| 72 | # include "qrect.h" | - |
| 73 | # include "qline.h" | - |
| 74 | #endif | - |
| 75 | | - |
| 76 | QT_BEGIN_NAMESPACE | - |
| 77 | | - |
| 78 | #define NS(x) QT_PREPEND_NAMESPACE(x) | - |
| 79 | | - |
| 80 | | - |
| 81 | namespace { | - |
| 82 | struct DefinedTypesFilter { | - |
| 83 | template<typename T> | - |
| 84 | struct Acceptor { | - |
| 85 | static const bool IsAccepted = QtMetaTypePrivate::TypeDefinition<T>::IsAvailable && QModulesPrivate::QTypeModuleInfo<T>::IsCore; | - |
| 86 | }; | - |
| 87 | }; | - |
| 88 | } // namespace | - |
| 89 | | - |
| 90 | /*! | - |
| 91 | \macro Q_DECLARE_OPAQUE_POINTER(PointerType) | - |
| 92 | \relates QMetaType | - |
| 93 | | - |
| 94 | This macro enables pointers to forward-declared types (\a PointerType) | - |
| 95 | to be registered with QMetaType using either Q_DECLARE_METATYPE() | - |
| 96 | or qRegisterMetaType(). | - |
| 97 | | - |
| 98 | \sa Q_DECLARE_METATYPE(), qRegisterMetaType() | - |
| 99 | */ | - |
| 100 | | - |
| 101 | /*! | - |
| 102 | \macro Q_DECLARE_METATYPE(Type) | - |
| 103 | \relates QMetaType | - |
| 104 | | - |
| 105 | This macro makes the type \a Type known to QMetaType as long as it | - |
| 106 | provides a public default constructor, a public copy constructor and | - |
| 107 | a public destructor. | - |
| 108 | It is needed to use the type \a Type as a custom type in QVariant. | - |
| 109 | | - |
| 110 | This macro requires that \a Type is a fully defined type at the point where | - |
| 111 | it is used. For pointer types, it also requires that the pointed to type is | - |
| 112 | fully defined. Use in conjunction with Q_DECLARE_OPAQUE_POINTER() to | - |
| 113 | register pointers to forward declared types. | - |
| 114 | | - |
| 115 | Ideally, this macro should be placed below the declaration of | - |
| 116 | the class or struct. If that is not possible, it can be put in | - |
| 117 | a private header file which has to be included every time that | - |
| 118 | type is used in a QVariant. | - |
| 119 | | - |
| 120 | Adding a Q_DECLARE_METATYPE() makes the type known to all template | - |
| 121 | based functions, including QVariant. Note that if you intend to | - |
| 122 | use the type in \e queued signal and slot connections or in | - |
| 123 | QObject's property system, you also have to call | - |
| 124 | qRegisterMetaType() since the names are resolved at runtime. | - |
| 125 | | - |
| 126 | This example shows a typical use case of Q_DECLARE_METATYPE(): | - |
| 127 | | - |
| 128 | \snippet code/src_corelib_kernel_qmetatype.cpp 0 | - |
| 129 | | - |
| 130 | If \c MyStruct is in a namespace, the Q_DECLARE_METATYPE() macro | - |
| 131 | has to be outside the namespace: | - |
| 132 | | - |
| 133 | \snippet code/src_corelib_kernel_qmetatype.cpp 1 | - |
| 134 | | - |
| 135 | Since \c{MyStruct} is now known to QMetaType, it can be used in QVariant: | - |
| 136 | | - |
| 137 | \snippet code/src_corelib_kernel_qmetatype.cpp 2 | - |
| 138 | | - |
| 139 | \sa qRegisterMetaType() | - |
| 140 | */ | - |
| 141 | | - |
| 142 | /*! | - |
| 143 | \enum QMetaType::Type | - |
| 144 | | - |
| 145 | These are the built-in types supported by QMetaType: | - |
| 146 | | - |
| 147 | \value Void \c void | - |
| 148 | \value Bool \c bool | - |
| 149 | \value Int \c int | - |
| 150 | \value UInt \c{unsigned int} | - |
| 151 | \value Double \c double | - |
| 152 | \value QChar QChar | - |
| 153 | \value QString QString | - |
| 154 | \value QByteArray QByteArray | - |
| 155 | | - |
| 156 | \value VoidStar \c{void *} | - |
| 157 | \value Long \c{long} | - |
| 158 | \value LongLong LongLong | - |
| 159 | \value Short \c{short} | - |
| 160 | \value Char \c{char} | - |
| 161 | \value ULong \c{unsigned long} | - |
| 162 | \value ULongLong ULongLong | - |
| 163 | \value UShort \c{unsigned short} | - |
| 164 | \value SChar \c{signed char} | - |
| 165 | \value UChar \c{unsigned char} | - |
| 166 | \value Float \c float | - |
| 167 | \value QObjectStar QObject * | - |
| 168 | \value QVariant QVariant | - |
| 169 | | - |
| 170 | \value QCursor QCursor | - |
| 171 | \value QDate QDate | - |
| 172 | \value QSize QSize | - |
| 173 | \value QTime QTime | - |
| 174 | \value QVariantList QVariantList | - |
| 175 | \value QPolygon QPolygon | - |
| 176 | \value QPolygonF QPolygonF | - |
| 177 | \value QColor QColor | - |
| 178 | \value QSizeF QSizeF | - |
| 179 | \value QRectF QRectF | - |
| 180 | \value QLine QLine | - |
| 181 | \value QTextLength QTextLength | - |
| 182 | \value QStringList QStringList | - |
| 183 | \value QVariantMap QVariantMap | - |
| 184 | \value QVariantHash QVariantHash | - |
| 185 | \value QIcon QIcon | - |
| 186 | \value QPen QPen | - |
| 187 | \value QLineF QLineF | - |
| 188 | \value QTextFormat QTextFormat | - |
| 189 | \value QRect QRect | - |
| 190 | \value QPoint QPoint | - |
| 191 | \value QUrl QUrl | - |
| 192 | \value QRegExp QRegExp | - |
| 193 | \value QRegularExpression QRegularExpression | - |
| 194 | \value QDateTime QDateTime | - |
| 195 | \value QPointF QPointF | - |
| 196 | \value QPalette QPalette | - |
| 197 | \value QFont QFont | - |
| 198 | \value QBrush QBrush | - |
| 199 | \value QRegion QRegion | - |
| 200 | \value QBitArray QBitArray | - |
| 201 | \value QImage QImage | - |
| 202 | \value QKeySequence QKeySequence | - |
| 203 | \value QSizePolicy QSizePolicy | - |
| 204 | \value QPixmap QPixmap | - |
| 205 | \value QLocale QLocale | - |
| 206 | \value QBitmap QBitmap | - |
| 207 | \value QMatrix QMatrix | - |
| 208 | \value QTransform QTransform | - |
| 209 | \value QMatrix4x4 QMatrix4x4 | - |
| 210 | \value QVector2D QVector2D | - |
| 211 | \value QVector3D QVector3D | - |
| 212 | \value QVector4D QVector4D | - |
| 213 | \value QQuaternion QQuaternion | - |
| 214 | \value QEasingCurve QEasingCurve | - |
| 215 | \value QJsonValue QJsonValue | - |
| 216 | \value QJsonObject QJsonObject | - |
| 217 | \value QJsonArray QJsonArray | - |
| 218 | \value QJsonDocument QJsonDocument | - |
| 219 | \value QModelIndex QModelIndex | - |
| 220 | \value QUuid QUuid | - |
| 221 | | - |
| 222 | \value User Base value for user types | - |
| 223 | \value UnknownType This is an invalid type id. It is returned from QMetaType for types that are not registered | - |
| 224 | | - |
| 225 | Additional types can be registered using Q_DECLARE_METATYPE(). | - |
| 226 | | - |
| 227 | \sa type(), typeName() | - |
| 228 | */ | - |
| 229 | | - |
| 230 | /*! | - |
| 231 | \enum QMetaType::TypeFlag | - |
| 232 | | - |
| 233 | The enum describes attributes of a type supported by QMetaType. | - |
| 234 | | - |
| 235 | \value NeedsConstruction This type has non-trivial constructors. If the flag is not set instances can be safely initialized with memset to 0. | - |
| 236 | \value NeedsDestruction This type has a non-trivial destructor. If the flag is not set calls to the destructor are not necessary before discarding objects. | - |
| 237 | \value MovableType An instance of a type having this attribute can be safely moved by memcpy. | - |
| 238 | \omitvalue SharedPointerToQObject | - |
| 239 | \omitvalue IsEnumeration | - |
| 240 | \omitvalue PointerToQObject | - |
| 241 | \omitvalue WeakPointerToQObject | - |
| 242 | \omitvalue TrackingPointerToQObject | - |
| 243 | \omitvalue WasDeclaredAsMetaType | - |
| 244 | */ | - |
| 245 | | - |
| 246 | /*! | - |
| 247 | \class QMetaType | - |
| 248 | \inmodule QtCore | - |
| 249 | \brief The QMetaType class manages named types in the meta-object system. | - |
| 250 | | - |
| 251 | \ingroup objectmodel | - |
| 252 | \threadsafe | - |
| 253 | | - |
| 254 | The class is used as a helper to marshall types in QVariant and | - |
| 255 | in queued signals and slots connections. It associates a type | - |
| 256 | name to a type so that it can be created and destructed | - |
| 257 | dynamically at run-time. Declare new types with Q_DECLARE_METATYPE() | - |
| 258 | to make them available to QVariant and other template-based functions. | - |
| 259 | Call qRegisterMetaType() to make type available to non-template based | - |
| 260 | functions, such as the queued signal and slot connections. | - |
| 261 | | - |
| 262 | Any class or struct that has a public default | - |
| 263 | constructor, a public copy constructor, and a public destructor | - |
| 264 | can be registered. | - |
| 265 | | - |
| 266 | The following code allocates and destructs an instance of | - |
| 267 | \c{MyClass}: | - |
| 268 | | - |
| 269 | \snippet code/src_corelib_kernel_qmetatype.cpp 3 | - |
| 270 | | - |
| 271 | If we want the stream operators \c operator<<() and \c | - |
| 272 | operator>>() to work on QVariant objects that store custom types, | - |
| 273 | the custom type must provide \c operator<<() and \c operator>>() | - |
| 274 | operators. | - |
| 275 | | - |
| 276 | \sa Q_DECLARE_METATYPE(), QVariant::setValue(), QVariant::value(), QVariant::fromValue() | - |
| 277 | */ | - |
| 278 | | - |
| 279 | /*! | - |
| 280 | \fn bool QMetaType::isValid() const | - |
| 281 | \since 5.0 | - |
| 282 | | - |
| 283 | Returns true if this QMetaType object contains valid | - |
| 284 | information about a type, false otherwise. | - |
| 285 | */ | - |
| 286 | | - |
| 287 | /*! | - |
| 288 | \fn bool QMetaType::isRegistered() const | - |
| 289 | \since 5.0 | - |
| 290 | | - |
| 291 | Returns true if this QMetaType object contains valid | - |
| 292 | information about a type, false otherwise. | - |
| 293 | */ | - |
| 294 | | - |
| 295 | /*! | - |
| 296 | \fn bool QMetaType::sizeOf() const | - |
| 297 | \since 5.0 | - |
| 298 | | - |
| 299 | Returns the size of the type in bytes (i.e. sizeof(T), | - |
| 300 | where T is the actual type for which this QMetaType instance | - |
| 301 | was constructed for). | - |
| 302 | | - |
| 303 | This function is typically used together with construct() | - |
| 304 | to perform low-level management of the memory used by a type. | - |
| 305 | | - |
| 306 | \sa QMetaType::construct(void *where, const void *copy), QMetaType::sizeOf(int) | - |
| 307 | */ | - |
| 308 | | - |
| 309 | /*! | - |
| 310 | \fn TypeFlags QMetaType::flags() const | - |
| 311 | \since 5.0 | - |
| 312 | | - |
| 313 | Returns flags of the type for which this QMetaType instance was constructed. | - |
| 314 | | - |
| 315 | \sa QMetaType::TypeFlags, QMetaType::typeFlags(int type) | - |
| 316 | */ | - |
| 317 | | - |
| 318 | /*! | - |
| 319 | \fn const QMetaObject *QMetaType::metaObject() const | - |
| 320 | \since 5.0 | - |
| 321 | \internal | - |
| 322 | */ | - |
| 323 | | - |
| 324 | /*! | - |
| 325 | \fn void *QMetaType::create(const void *copy = 0) const | - |
| 326 | \since 5.0 | - |
| 327 | | - |
| 328 | Returns a copy of \a copy, assuming it is of the type that this | - |
| 329 | QMetaType instance was created for. If \a copy is null, creates | - |
| 330 | a default constructed instance. | - |
| 331 | | - |
| 332 | \sa QMetaType::destroy(void*) | - |
| 333 | */ | - |
| 334 | | - |
| 335 | /*! | - |
| 336 | \fn void QMetaType::destroy(void *data) const | - |
| 337 | \since 5.0 | - |
| 338 | | - |
| 339 | Destroys the \a data, assuming it is of the type that this | - |
| 340 | QMetaType instance was created for. | - |
| 341 | | - |
| 342 | \sa QMetaType::create(const void *) | - |
| 343 | */ | - |
| 344 | | - |
| 345 | /*! | - |
| 346 | \fn void *QMetaType::construct(void *where, const void *copy = 0) const | - |
| 347 | \since 5.0 | - |
| 348 | | - |
| 349 | Constructs a value of the type that this QMetaType instance | - |
| 350 | was constructed for in the existing memory addressed by \a where, | - |
| 351 | that is a copy of \a copy, and returns \a where. If \a copy is | - |
| 352 | zero, the value is default constructed. | - |
| 353 | | - |
| 354 | This is a low-level function for explicitly managing the memory | - |
| 355 | used to store the type. Consider calling create() if you don't | - |
| 356 | need this level of control (that is, use "new" rather than | - |
| 357 | "placement new"). | - |
| 358 | | - |
| 359 | You must ensure that \a where points to a location where the new | - |
| 360 | value can be stored and that \a where is suitably aligned. | - |
| 361 | The type's size can be queried by calling sizeOf(). | - |
| 362 | | - |
| 363 | The rule of thumb for alignment is that a type is aligned to its | - |
| 364 | natural boundary, which is the smallest power of 2 that is bigger | - |
| 365 | than the type, unless that alignment is larger than the maximum | - |
| 366 | useful alignment for the platform. For practical purposes, | - |
| 367 | alignment larger than 2 * sizeof(void*) is only necessary for | - |
| 368 | special hardware instructions (e.g., aligned SSE loads and stores | - |
| 369 | on x86). | - |
| 370 | */ | - |
| 371 | | - |
| 372 | /*! | - |
| 373 | \fn void QMetaType::destruct(void *data) const | - |
| 374 | \since 5.0 | - |
| 375 | | - |
| 376 | Destructs the value, located at \a data, assuming that it is | - |
| 377 | of the type for which this QMetaType instance was constructed for. | - |
| 378 | | - |
| 379 | Unlike destroy(), this function only invokes the type's | - |
| 380 | destructor, it doesn't invoke the delete operator. | - |
| 381 | \sa QMetaType::construct() | - |
| 382 | */ | - |
| 383 | | - |
| 384 | /*! | - |
| 385 | \fn QMetaType::~QMetaType() | - |
| 386 | | - |
| 387 | Destructs this object. | - |
| 388 | */ | - |
| 389 | | - |
| 390 | #define QT_ADD_STATIC_METATYPE(MetaTypeName, MetaTypeId, RealName) \ | - |
| 391 | { #RealName, sizeof(#RealName) - 1, MetaTypeId }, | - |
| 392 | | - |
| 393 | #define QT_ADD_STATIC_METATYPE_ALIASES_ITER(MetaTypeName, MetaTypeId, AliasingName, RealNameStr) \ | - |
| 394 | { RealNameStr, sizeof(RealNameStr) - 1, QMetaType::MetaTypeName }, | - |
| 395 | | - |
| 396 | #define QT_ADD_STATIC_METATYPE_HACKS_ITER(MetaTypeName, TypeId, Name) \ | - |
| 397 | QT_ADD_STATIC_METATYPE(MetaTypeName, MetaTypeName, Name) | - |
| 398 | | - |
| 399 | static const struct { const char * typeName; int typeNameLength; int type; } types[] = { | - |
| 400 | QT_FOR_EACH_STATIC_TYPE(QT_ADD_STATIC_METATYPE) | - |
| 401 | QT_FOR_EACH_STATIC_ALIAS_TYPE(QT_ADD_STATIC_METATYPE_ALIASES_ITER) | - |
| 402 | QT_FOR_EACH_STATIC_HACKS_TYPE(QT_ADD_STATIC_METATYPE_HACKS_ITER) | - |
| 403 | {0, 0, QMetaType::UnknownType} | - |
| 404 | }; | - |
| 405 | | - |
| 406 | Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeGuiHelper = 0; | - |
| 407 | Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeWidgetsHelper = 0; | - |
| 408 | Q_CORE_EXPORT const QMetaObject *qMetaObjectWidgetsHelper = 0; | - |
| 409 | | - |
| 410 | class QCustomTypeInfo : public QMetaTypeInterface | - |
| 411 | { | - |
| 412 | public: | - |
| 413 | QCustomTypeInfo() | - |
| 414 | : alias(-1) | - |
| 415 | { | - |
| 416 | QMetaTypeInterface empty = QT_METATYPE_INTERFACE_INIT(void); | - |
| 417 | *static_cast<QMetaTypeInterface*>(this) = empty; | - |
| 418 | } | - |
| 419 | QByteArray typeName; | - |
| 420 | int alias; | - |
| 421 | }; | - |
| 422 | | - |
| 423 | namespace | - |
| 424 | { | - |
| 425 | union CheckThatItIsPod | - |
| 426 | { // This should break if QMetaTypeInterface is not a POD type | - |
| 427 | QMetaTypeInterface iface; | - |
| 428 | }; | - |
| 429 | } | - |
| 430 | | - |
| 431 | Q_DECLARE_TYPEINFO(QCustomTypeInfo, Q_MOVABLE_TYPE); | - |
| 432 | Q_GLOBAL_STATIC(QVector<QCustomTypeInfo>, customTypes) | - |
| 433 | Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock) | - |
| 434 | | - |
| 435 | #ifndef QT_NO_DATASTREAM | - |
| 436 | /*! | - |
| 437 | \internal | - |
| 438 | */ | - |
| 439 | void QMetaType::registerStreamOperators(const char *typeName, SaveOperator saveOp, | - |
| 440 | LoadOperator loadOp) | - |
| 441 | { | - |
| 442 | registerStreamOperators(type(typeName), saveOp, loadOp); | - |
| 443 | } | - |
| 444 | | - |
| 445 | /*! | - |
| 446 | \internal | - |
| 447 | */ | - |
| 448 | void QMetaType::registerStreamOperators(int idx, SaveOperator saveOp, | - |
| 449 | LoadOperator loadOp) | - |
| 450 | { | - |
| 451 | if (idx < User) | - |
| 452 | return; //builtin types should not be registered; | - |
| 453 | QVector<QCustomTypeInfo> *ct = customTypes(); | - |
| 454 | if (!ct) | - |
| 455 | return; | - |
| 456 | QWriteLocker locker(customTypesLock()); | - |
| 457 | QCustomTypeInfo &inf = (*ct)[idx - User]; | - |
| 458 | inf.saveOp = saveOp; | - |
| 459 | inf.loadOp = loadOp; | - |
| 460 | } | - |
| 461 | #endif // QT_NO_DATASTREAM | - |
| 462 | | - |
| 463 | /*! | - |
| 464 | Returns the type name associated with the given \a typeId, or 0 if no | - |
| 465 | matching type was found. The returned pointer must not be deleted. | - |
| 466 | | - |
| 467 | \sa type(), isRegistered(), Type | - |
| 468 | */ | - |
| 469 | const char *QMetaType::typeName(int typeId) | - |
| 470 | { | - |
| 471 | const uint type = typeId; | - |
| 472 | // In theory it can be filled during compilation time, but for some reason template code | - |
| 473 | // that is able to do it causes GCC 4.6 to generate additional 3K of executable code. Probably | - |
| 474 | // it is not worth of it. | - |
| 475 | static const char *namesCache[QMetaType::HighestInternalId + 1]; | - |
| 476 | | - |
| 477 | const char *result; | - |
| 478 | if (type <= QMetaType::HighestInternalId && ((result = namesCache[type]))) | - |
| 479 | return result; | - |
| 480 | | - |
| 481 | #define QT_METATYPE_TYPEID_TYPENAME_CONVERTER(MetaTypeName, TypeId, RealName) \ | - |
| 482 | case QMetaType::MetaTypeName: result = #RealName; break; | - |
| 483 | | - |
| 484 | switch (QMetaType::Type(type)) { | - |
| 485 | QT_FOR_EACH_STATIC_TYPE(QT_METATYPE_TYPEID_TYPENAME_CONVERTER) | - |
| 486 | | - |
| 487 | default: { | - |
| 488 | if (Q_UNLIKELY(type < QMetaType::User)) { | - |
| 489 | return 0; // It can happen when someone cast int to QVariant::Type, we should not crash... | - |
| 490 | } else { | - |
| 491 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - |
| 492 | QReadLocker locker(customTypesLock()); | - |
| 493 | return ct && uint(ct->count()) > type - QMetaType::User && !ct->at(type - QMetaType::User).typeName.isEmpty() | - |
| 494 | ? ct->at(type - QMetaType::User).typeName.constData() | - |
| 495 | : 0; | - |
| 496 | } | - |
| 497 | } | - |
| 498 | } | - |
| 499 | #undef QT_METATYPE_TYPEID_TYPENAME_CONVERTER | - |
| 500 | | - |
| 501 | Q_ASSERT(type <= QMetaType::HighestInternalId); | - |
| 502 | namesCache[type] = result; | - |
| 503 | return result; | - |
| 504 | } | - |
| 505 | | - |
| 506 | /*! | - |
| 507 | \internal | - |
| 508 | Similar to QMetaType::type(), but only looks in the static set of types. | - |
| 509 | */ | - |
| 510 | static inline int qMetaTypeStaticType(const char *typeName, int length) | - |
| 511 | { | - |
| 512 | int i = 0; | - |
| 513 | while (types[i].typeName && ((length != types[i].typeNameLength) | - |
| 514 | || strcmp(typeName, types[i].typeName))) { | - |
| 515 | ++i; | - |
| 516 | } | - |
| 517 | return types[i].type; | - |
| 518 | } | - |
| 519 | | - |
| 520 | /*! | - |
| 521 | \internal | - |
| 522 | Similar to QMetaType::type(), but only looks in the custom set of | - |
| 523 | types, and doesn't lock the mutex. | - |
| 524 | */ | - |
| 525 | static int qMetaTypeCustomType_unlocked(const char *typeName, int length) | - |
| 526 | { | - |
| 527 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - |
| 528 | if (!ct) | - |
| 529 | return QMetaType::UnknownType; | - |
| 530 | | - |
| 531 | for (int v = 0; v < ct->count(); ++v) { | - |
| 532 | const QCustomTypeInfo &customInfo = ct->at(v); | - |
| 533 | if ((length == customInfo.typeName.size()) | - |
| 534 | && !strcmp(typeName, customInfo.typeName.constData())) { | - |
| 535 | if (customInfo.alias >= 0) | - |
| 536 | return customInfo.alias; | - |
| 537 | return v + QMetaType::User; | - |
| 538 | } | - |
| 539 | } | - |
| 540 | return QMetaType::UnknownType; | - |
| 541 | } | - |
| 542 | | - |
| 543 | /*! | - |
| 544 | \internal | - |
| 545 | | - |
| 546 | This function is needed until existing code outside of qtbase | - |
| 547 | has been changed to call the new version of registerType(). | - |
| 548 | */ | - |
| 549 | int QMetaType::registerType(const char *typeName, Deleter deleter, | - |
| 550 | Creator creator) | - |
| 551 | { | - |
| 552 | return registerType(typeName, deleter, creator, | - |
| 553 | QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Destruct, | - |
| 554 | QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Construct, 0, TypeFlags(), 0); | - |
| 555 | } | - |
| 556 | | - |
| 557 | /*! | - |
| 558 | \internal | - |
| 559 | \since 5.0 | - |
| 560 | | - |
| 561 | Registers a user type for marshalling, with \a typeName, a \a | - |
| 562 | deleter, a \a creator, a \a destructor, a \a constructor, and | - |
| 563 | a \a size. Returns the type's handle, or -1 if the type could | - |
| 564 | not be registered. | - |
| 565 | */ | - |
| 566 | int QMetaType::registerType(const char *typeName, Deleter deleter, | - |
| 567 | Creator creator, | - |
| 568 | Destructor destructor, | - |
| 569 | Constructor constructor, | - |
| 570 | int size, TypeFlags flags, const QMetaObject *metaObject) | - |
| 571 | { | - |
| 572 | #ifdef QT_NO_QOBJECT | - |
| 573 | NS(QByteArray) normalizedTypeName = typeName; | - |
| 574 | #else | - |
| 575 | NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName); | - |
| 576 | #endif | - |
| 577 | | - |
| 578 | return registerNormalizedType(normalizedTypeName, deleter, creator, destructor, constructor, size, flags, metaObject); | - |
| 579 | } | - |
| 580 | | - |
| 581 | | - |
| 582 | /*! | - |
| 583 | \internal | - |
| 584 | \since 5.0 | - |
| 585 | | - |
| 586 | Registers a user type for marshalling, with \a normalizedTypeName, a \a | - |
| 587 | deleter, a \a creator, a \a destructor, a \a constructor, and | - |
| 588 | a \a size. Returns the type's handle, or -1 if the type could | - |
| 589 | not be registered. Note that normalizedTypeName is not checked for | - |
| 590 | conformance with Qt's normalized format, so it must already | - |
| 591 | conform. | - |
| 592 | */ | - |
| 593 | int QMetaType::registerNormalizedType(const NS(QByteArray) &normalizedTypeName, Deleter deleter, | - |
| 594 | Creator creator, | - |
| 595 | Destructor destructor, | - |
| 596 | Constructor constructor, | - |
| 597 | int size, TypeFlags flags, const QMetaObject *metaObject) | - |
| 598 | { | - |
| 599 | QVector<QCustomTypeInfo> *ct = customTypes(); executed (the execution status of this line is deduced): QVector<QCustomTypeInfo> *ct = customTypes(); | - |
| 600 | if (!ct || normalizedTypeName.isEmpty() || !deleter || !creator || !destructor || !constructor) partially evaluated: !ct| no Evaluation Count:0 | yes Evaluation Count:16253 |
partially evaluated: normalizedTypeName.isEmpty()| no Evaluation Count:0 | yes Evaluation Count:16259 |
partially evaluated: !deleter| no Evaluation Count:0 | yes Evaluation Count:16258 |
partially evaluated: !creator| no Evaluation Count:0 | yes Evaluation Count:16259 |
partially evaluated: !destructor| no Evaluation Count:0 | yes Evaluation Count:16260 |
partially evaluated: !constructor| no Evaluation Count:0 | yes Evaluation Count:16263 |
| 0-16263 |
| 601 | return -1; never executed: return -1; | 0 |
| 602 | | - |
| 603 | int idx = qMetaTypeStaticType(normalizedTypeName.constData(), executed (the execution status of this line is deduced): int idx = qMetaTypeStaticType(normalizedTypeName.constData(), | - |
| 604 | normalizedTypeName.size()); executed (the execution status of this line is deduced): normalizedTypeName.size()); | - |
| 605 | | - |
| 606 | int previousSize = 0; executed (the execution status of this line is deduced): int previousSize = 0; | - |
| 607 | int previousFlags = 0; executed (the execution status of this line is deduced): int previousFlags = 0; | - |
| 608 | if (idx == UnknownType) { partially evaluated: idx == UnknownType| yes Evaluation Count:16077 | no Evaluation Count:0 |
| 0-16077 |
| 609 | QWriteLocker locker(customTypesLock()); executed (the execution status of this line is deduced): QWriteLocker locker(customTypesLock()); | - |
| 610 | idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(), executed (the execution status of this line is deduced): idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(), | - |
| 611 | normalizedTypeName.size()); executed (the execution status of this line is deduced): normalizedTypeName.size()); | - |
| 612 | if (idx == UnknownType) { evaluated: idx == UnknownType| yes Evaluation Count:4153 | yes Evaluation Count:12127 |
| 4153-12127 |
| 613 | QCustomTypeInfo inf; executed (the execution status of this line is deduced): QCustomTypeInfo inf; | - |
| 614 | inf.typeName = normalizedTypeName; executed (the execution status of this line is deduced): inf.typeName = normalizedTypeName; | - |
| 615 | inf.creator = creator; executed (the execution status of this line is deduced): inf.creator = creator; | - |
| 616 | inf.deleter = deleter; executed (the execution status of this line is deduced): inf.deleter = deleter; | - |
| 617 | #ifndef QT_NO_DATASTREAM | - |
| 618 | inf.loadOp = 0; executed (the execution status of this line is deduced): inf.loadOp = 0; | - |
| 619 | inf.saveOp = 0; executed (the execution status of this line is deduced): inf.saveOp = 0; | - |
| 620 | #endif | - |
| 621 | inf.alias = -1; executed (the execution status of this line is deduced): inf.alias = -1; | - |
| 622 | inf.constructor = constructor; executed (the execution status of this line is deduced): inf.constructor = constructor; | - |
| 623 | inf.destructor = destructor; executed (the execution status of this line is deduced): inf.destructor = destructor; | - |
| 624 | inf.size = size; executed (the execution status of this line is deduced): inf.size = size; | - |
| 625 | inf.flags = flags; executed (the execution status of this line is deduced): inf.flags = flags; | - |
| 626 | inf.metaObject = metaObject; executed (the execution status of this line is deduced): inf.metaObject = metaObject; | - |
| 627 | idx = ct->size() + User; executed (the execution status of this line is deduced): idx = ct->size() + User; | - |
| 628 | ct->append(inf); executed (the execution status of this line is deduced): ct->append(inf); | - |
| 629 | return idx; executed: return idx;Execution Count:4153 | 4153 |
| 630 | } | - |
| 631 | | - |
| 632 | if (idx >= User) { partially evaluated: idx >= User| yes Evaluation Count:12127 | no Evaluation Count:0 |
| 0-12127 |
| 633 | previousSize = ct->at(idx - User).size; executed (the execution status of this line is deduced): previousSize = ct->at(idx - User).size; | - |
| 634 | previousFlags = ct->at(idx - User).flags; executed (the execution status of this line is deduced): previousFlags = ct->at(idx - User).flags; | - |
| 635 | } executed: }Execution Count:12127 | 12127 |
| 636 | } executed: }Execution Count:12127 | 12127 |
| 637 | | - |
| 638 | if (idx < User) { partially evaluated: idx < User| no Evaluation Count:0 | yes Evaluation Count:12127 |
| 0-12127 |
| 639 | previousSize = QMetaType::sizeOf(idx); never executed (the execution status of this line is deduced): previousSize = QMetaType::sizeOf(idx); | - |
| 640 | previousFlags = QMetaType::typeFlags(idx); never executed (the execution status of this line is deduced): previousFlags = QMetaType::typeFlags(idx); | - |
| 641 | } | 0 |
| 642 | | - |
| 643 | if (previousSize != size) { partially evaluated: previousSize != size| no Evaluation Count:0 | yes Evaluation Count:12127 |
| 0-12127 |
| 644 | qFatal("QMetaType::registerType: Binary compatibility break " never executed (the execution status of this line is deduced): QMessageLogger("kernel/qmetatype.cpp", 644, __PRETTY_FUNCTION__).fatal("QMetaType::registerType: Binary compatibility break " | - |
| 645 | "-- Size mismatch for type '%s' [%i]. Previously registered " never executed (the execution status of this line is deduced): "-- Size mismatch for type '%s' [%i]. Previously registered " | - |
| 646 | "size %i, now registering size %i.", never executed (the execution status of this line is deduced): "size %i, now registering size %i.", | - |
| 647 | normalizedTypeName.constData(), idx, previousSize, size); never executed (the execution status of this line is deduced): normalizedTypeName.constData(), idx, previousSize, size); | - |
| 648 | } | 0 |
| 649 | | - |
| 650 | // Ignore WasDeclaredAsMetaType inconsitency, to many users were hitting the problem | - |
| 651 | previousFlags |= WasDeclaredAsMetaType; executed (the execution status of this line is deduced): previousFlags |= WasDeclaredAsMetaType; | - |
| 652 | flags |= WasDeclaredAsMetaType; executed (the execution status of this line is deduced): flags |= WasDeclaredAsMetaType; | - |
| 653 | | - |
| 654 | if (previousFlags != flags) { partially evaluated: previousFlags != flags| no Evaluation Count:0 | yes Evaluation Count:12127 |
| 0-12127 |
| 655 | qFatal(const int maskForTypeInfo = NeedsConstruction | NeedsDestruction | MovableType; never executed (the execution status of this line is deduced): const int maskForTypeInfo = NeedsConstruction | NeedsDestruction | MovableType; | - |
| 656 | const char *msg = "QMetaType::registerType: Binary compatibility break" | - |
| | . "-- Type never executed (the execution status of this line is deduced): const char *msg = "QMetaType::registerType: Binary compatibility break. " | |
| 657 | "\nType flags for type '%s' [%i] don't match. Previously " | - |
| | never executed (the execution status of this line is deduced): "\nType flags for type '%s' [%i] don't match. Previously " | |
| 658 | "registered TypeFlags(0x%x), now registering TypeFlags(0x%x). " never executed (the execution status of this line is deduced): "registered TypeFlags(0x%x), now registering TypeFlags(0x%x). " | - |
| 659 | "This is an ODR break, which means that your application depends on a C++ undefined behavior." never executed (the execution status of this line is deduced): "This is an ODR break, which means that your application depends on a C++ undefined behavior." | - |
| 660 | "\nHint: %s"; never executed (the execution status of this line is deduced): "\nHint: %s"; | - |
| 661 | QT_PREPEND_NAMESPACE(QByteArray) hint; never executed (the execution status of this line is deduced): ::QByteArray hint; | - |
| 662 | if ((previousFlags & maskForTypeInfo) != (flags & maskForTypeInfo)) { never evaluated: (previousFlags & maskForTypeInfo) != (flags & maskForTypeInfo) | 0 |
| 663 | hint += "\nIt seems that the type was registered at least twice in a different translation units, " never executed (the execution status of this line is deduced): hint += "\nIt seems that the type was registered at least twice in a different translation units, " | - |
| 664 | "but Q_DECLARE_TYPEINFO is not visible from all the translations unit or different flags were used." never executed (the execution status of this line is deduced): "but Q_DECLARE_TYPEINFO is not visible from all the translations unit or different flags were used." | - |
| 665 | "Remember that Q_DECLARE_TYPEINFO should be declared before QMetaType registration, " never executed (the execution status of this line is deduced): "Remember that Q_DECLARE_TYPEINFO should be declared before QMetaType registration, " | - |
| 666 | "preferably it should be placed just after the type declaration and before Q_DECLARE_METATYPE"; never executed (the execution status of this line is deduced): "preferably it should be placed just after the type declaration and before Q_DECLARE_METATYPE"; | - |
| 667 | } | 0 |
| 668 | qFatal(msg, normalizedTypeName.constData(), idx, previousFlags, int(flags));), hint.constData()); never executed (the execution status of this line is deduced): QMessageLogger("kernel/qmetatype.cpp", 668, __PRETTY_FUNCTION__).fatal(msg, normalizedTypeName.constData(), idx, previousFlags, int(flags), hint.constData()); | - |
| 669 | } | 0 |
| 670 | | - |
| 671 | return idx; executed: return idx;Execution Count:12127 | 12127 |
| 672 | } | - |
| 673 | | - |
| 674 | /*! | - |
| 675 | \internal | - |
| 676 | \since 4.7 | - |
| 677 | | - |
| 678 | Registers a user type for marshalling, as an alias of another type (typedef) | - |
| 679 | */ | - |
| 680 | int QMetaType::registerTypedef(const char* typeName, int aliasId) | - |
| 681 | { | - |
| 682 | #ifdef QT_NO_QOBJECT | - |
| 683 | NS(QByteArray) normalizedTypeName = typeName; | - |
| 684 | #else | - |
| 685 | NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName); | - |
| 686 | #endif | - |
| 687 | | - |
| 688 | return registerNormalizedTypedef(normalizedTypeName, aliasId); | - |
| 689 | } | - |
| 690 | | - |
| 691 | /*! | - |
| 692 | \internal | - |
| 693 | \since 5.0 | - |
| 694 | | - |
| 695 | Registers a user type for marshalling, as an alias of another type (typedef). | - |
| 696 | Note that normalizedTypeName is not checked for conformance with Qt's normalized format, | - |
| 697 | so it must already conform. | - |
| 698 | */ | - |
| 699 | int QMetaType::registerNormalizedTypedef(const NS(QByteArray) &normalizedTypeName, int aliasId) | - |
| 700 | { | - |
| 701 | QVector<QCustomTypeInfo> *ct = customTypes(); | - |
| 702 | if (!ct || normalizedTypeName.isEmpty()) | - |
| 703 | return -1; | - |
| 704 | | - |
| 705 | int idx = qMetaTypeStaticType(normalizedTypeName.constData(), | - |
| 706 | normalizedTypeName.size()); | - |
| 707 | | - |
| 708 | if (idx == UnknownType) { | - |
| 709 | QWriteLocker locker(customTypesLock()); | - |
| 710 | idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(), | - |
| 711 | normalizedTypeName.size()); | - |
| 712 | | - |
| 713 | if (idx == UnknownType) { | - |
| 714 | QCustomTypeInfo inf; | - |
| 715 | inf.typeName = normalizedTypeName; | - |
| 716 | inf.alias = aliasId; | - |
| 717 | inf.creator = 0; | - |
| 718 | inf.deleter = 0; | - |
| 719 | ct->append(inf); | - |
| 720 | return aliasId; | - |
| 721 | } | - |
| 722 | } | - |
| 723 | | - |
| 724 | if (idx != aliasId) { | - |
| 725 | qFatal("QMetaType::registerTypedef: Binary compatibility break " | - |
| 726 | "-- Type name '%s' previously registered as typedef of '%s' [%i], " | - |
| 727 | "now registering as typedef of '%s' [%i].", | - |
| 728 | normalizedTypeName.constData(), QMetaType::typeName(idx), idx, | - |
| 729 | QMetaType::typeName(aliasId), aliasId); | - |
| 730 | } | - |
| 731 | return idx; | - |
| 732 | } | - |
| 733 | | - |
| 734 | /*! | - |
| 735 | Returns true if the datatype with ID \a type is registered; | - |
| 736 | otherwise returns false. | - |
| 737 | | - |
| 738 | \sa type(), typeName(), Type | - |
| 739 | */ | - |
| 740 | bool QMetaType::isRegistered(int type) | - |
| 741 | { | - |
| 742 | // predefined type | - |
| 743 | if ((type >= FirstCoreType && type <= LastCoreType) | - |
| 744 | || (type >= FirstGuiType && type <= LastGuiType) | - |
| 745 | || (type >= FirstWidgetsType && type <= LastWidgetsType)) { | - |
| 746 | return true; | - |
| 747 | } | - |
| 748 | | - |
| 749 | QReadLocker locker(customTypesLock()); | - |
| 750 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - |
| 751 | return ((type >= User) && (ct && ct->count() > type - User) && !ct->at(type - User).typeName.isEmpty()); | - |
| 752 | } | - |
| 753 | | - |
| 754 | /*! | - |
| 755 | \fn int qMetaTypeTypeImpl(const char *typeName) | - |
| 756 | \internal | - |
| 757 | | - |
| 758 | Implementation of QMetaType::type(). | - |
| 759 | */ | - |
| 760 | template <bool tryNormalizedType> | - |
| 761 | static inline int qMetaTypeTypeImpl(const char *typeName) | - |
| 762 | { | - |
| 763 | int length = qstrlen(typeName); | - |
| 764 | if (!length) | - |
| 765 | return QMetaType::UnknownType; | - |
| 766 | int type = qMetaTypeStaticType(typeName, length); | - |
| 767 | if (type == QMetaType::UnknownType) { | - |
| 768 | QReadLocker locker(customTypesLock()); | - |
| 769 | type = qMetaTypeCustomType_unlocked(typeName, length); | - |
| 770 | #ifndef QT_NO_QOBJECT | - |
| 771 | if ((type == QMetaType::UnknownType) && tryNormalizedType) { | - |
| 772 | const NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName); | - |
| 773 | type = qMetaTypeStaticType(normalizedTypeName.constData(), | - |
| 774 | normalizedTypeName.size()); | - |
| 775 | if (type == QMetaType::UnknownType) { | - |
| 776 | type = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(), | - |
| 777 | normalizedTypeName.size()); | - |
| 778 | } | - |
| 779 | } | - |
| 780 | #endif | - |
| 781 | } | - |
| 782 | return type; | - |
| 783 | } | - |
| 784 | | - |
| 785 | /*! | - |
| 786 | Returns a handle to the type called \a typeName, or QMetaType::UnknownType if there is | - |
| 787 | no such type. | - |
| 788 | | - |
| 789 | \sa isRegistered(), typeName(), Type | - |
| 790 | */ | - |
| 791 | int QMetaType::type(const char *typeName) | - |
| 792 | { | - |
| 793 | return qMetaTypeTypeImpl</*tryNormalizedType=*/true>(typeName); | - |
| 794 | } | - |
| 795 | | - |
| 796 | /*! | - |
| 797 | \a internal | - |
| 798 | | - |
| 799 | Similar to QMetaType::type(); the only difference is that this function | - |
| 800 | doesn't attempt to normalize the type name (i.e., the lookup will fail | - |
| 801 | for type names in non-normalized form). | - |
| 802 | */ | - |
| 803 | int qMetaTypeTypeInternal(const char *typeName) | - |
| 804 | { | - |
| 805 | return qMetaTypeTypeImpl</*tryNormalizedType=*/false>(typeName); | - |
| 806 | } | - |
| 807 | | - |
| 808 | #ifndef QT_NO_DATASTREAM | - |
| 809 | /*! | - |
| 810 | Writes the object pointed to by \a data with the ID \a type to | - |
| 811 | the given \a stream. Returns true if the object is saved | - |
| 812 | successfully; otherwise returns false. | - |
| 813 | | - |
| 814 | The type must have been registered with qRegisterMetaType() and | - |
| 815 | qRegisterMetaTypeStreamOperators() beforehand. | - |
| 816 | | - |
| 817 | Normally, you should not need to call this function directly. | - |
| 818 | Instead, use QVariant's \c operator<<(), which relies on save() | - |
| 819 | to stream custom types. | - |
| 820 | | - |
| 821 | \sa load(), qRegisterMetaTypeStreamOperators() | - |
| 822 | */ | - |
| 823 | bool QMetaType::save(QDataStream &stream, int type, const void *data) | - |
| 824 | { | - |
| 825 | if (!data || !isRegistered(type)) | - |
| 826 | return false; | - |
| 827 | | - |
| 828 | switch(type) { | - |
| 829 | case QMetaType::UnknownType: | - |
| 830 | case QMetaType::Void: | - |
| 831 | case QMetaType::VoidStar: | - |
| 832 | case QMetaType::QObjectStar: | - |
| 833 | case QMetaType::QModelIndex: | - |
| 834 | case QMetaType::QJsonValue: | - |
| 835 | case QMetaType::QJsonObject: | - |
| 836 | case QMetaType::QJsonArray: | - |
| 837 | case QMetaType::QJsonDocument: | - |
| 838 | return false; | - |
| 839 | case QMetaType::Long: | - |
| 840 | stream << qlonglong(*static_cast<const long *>(data)); | - |
| 841 | break; | - |
| 842 | case QMetaType::Int: | - |
| 843 | stream << *static_cast<const int *>(data); | - |
| 844 | break; | - |
| 845 | case QMetaType::Short: | - |
| 846 | stream << *static_cast<const short *>(data); | - |
| 847 | break; | - |
| 848 | case QMetaType::Char: | - |
| 849 | // force a char to be signed | - |
| 850 | stream << *static_cast<const signed char *>(data); | - |
| 851 | break; | - |
| 852 | case QMetaType::ULong: | - |
| 853 | stream << qulonglong(*static_cast<const ulong *>(data)); | - |
| 854 | break; | - |
| 855 | case QMetaType::UInt: | - |
| 856 | stream << *static_cast<const uint *>(data); | - |
| 857 | break; | - |
| 858 | case QMetaType::LongLong: | - |
| 859 | stream << *static_cast<const qlonglong *>(data); | - |
| 860 | break; | - |
| 861 | case QMetaType::ULongLong: | - |
| 862 | stream << *static_cast<const qulonglong *>(data); | - |
| 863 | break; | - |
| 864 | case QMetaType::UShort: | - |
| 865 | stream << *static_cast<const ushort *>(data); | - |
| 866 | break; | - |
| 867 | case QMetaType::SChar: | - |
| 868 | stream << *static_cast<const signed char *>(data); | - |
| 869 | break; | - |
| 870 | case QMetaType::UChar: | - |
| 871 | stream << *static_cast<const uchar *>(data); | - |
| 872 | break; | - |
| 873 | case QMetaType::Bool: | - |
| 874 | stream << qint8(*static_cast<const bool *>(data)); | - |
| 875 | break; | - |
| 876 | case QMetaType::Float: | - |
| 877 | stream << *static_cast<const float *>(data); | - |
| 878 | break; | - |
| 879 | case QMetaType::Double: | - |
| 880 | stream << *static_cast<const double *>(data); | - |
| 881 | break; | - |
| 882 | case QMetaType::QChar: | - |
| 883 | stream << *static_cast<const NS(QChar) *>(data); | - |
| 884 | break; | - |
| 885 | #ifndef QT_BOOTSTRAPPED | - |
| 886 | case QMetaType::QVariantMap: | - |
| 887 | stream << *static_cast<const NS(QVariantMap)*>(data); | - |
| 888 | break; | - |
| 889 | case QMetaType::QVariantHash: | - |
| 890 | stream << *static_cast<const NS(QVariantHash)*>(data); | - |
| 891 | break; | - |
| 892 | case QMetaType::QVariantList: | - |
| 893 | stream << *static_cast<const NS(QVariantList)*>(data); | - |
| 894 | break; | - |
| 895 | case QMetaType::QVariant: | - |
| 896 | stream << *static_cast<const NS(QVariant)*>(data); | - |
| 897 | break; | - |
| 898 | #endif | - |
| 899 | case QMetaType::QByteArray: | - |
| 900 | stream << *static_cast<const NS(QByteArray)*>(data); | - |
| 901 | break; | - |
| 902 | case QMetaType::QString: | - |
| 903 | stream << *static_cast<const NS(QString)*>(data); | - |
| 904 | break; | - |
| 905 | case QMetaType::QStringList: | - |
| 906 | stream << *static_cast<const NS(QStringList)*>(data); | - |
| 907 | break; | - |
| 908 | #ifndef QT_BOOTSTRAPPED | - |
| 909 | case QMetaType::QBitArray: | - |
| 910 | stream << *static_cast<const NS(QBitArray)*>(data); | - |
| 911 | break; | - |
| 912 | #endif | - |
| 913 | case QMetaType::QDate: | - |
| 914 | stream << *static_cast<const NS(QDate)*>(data); | - |
| 915 | break; | - |
| 916 | case QMetaType::QTime: | - |
| 917 | stream << *static_cast<const NS(QTime)*>(data); | - |
| 918 | break; | - |
| 919 | case QMetaType::QDateTime: | - |
| 920 | stream << *static_cast<const NS(QDateTime)*>(data); | - |
| 921 | break; | - |
| 922 | #ifndef QT_BOOTSTRAPPED | - |
| 923 | case QMetaType::QUrl: | - |
| 924 | stream << *static_cast<const NS(QUrl)*>(data); | - |
| 925 | break; | - |
| 926 | #endif | - |
| 927 | case QMetaType::QLocale: | - |
| 928 | stream << *static_cast<const NS(QLocale)*>(data); | - |
| 929 | break; | - |
| 930 | #ifndef QT_NO_GEOM_VARIANT | - |
| 931 | case QMetaType::QRect: | - |
| 932 | stream << *static_cast<const NS(QRect)*>(data); | - |
| 933 | break; | - |
| 934 | case QMetaType::QRectF: | - |
| 935 | stream << *static_cast<const NS(QRectF)*>(data); | - |
| 936 | break; | - |
| 937 | case QMetaType::QSize: | - |
| 938 | stream << *static_cast<const NS(QSize)*>(data); | - |
| 939 | break; | - |
| 940 | case QMetaType::QSizeF: | - |
| 941 | stream << *static_cast<const NS(QSizeF)*>(data); | - |
| 942 | break; | - |
| 943 | case QMetaType::QLine: | - |
| 944 | stream << *static_cast<const NS(QLine)*>(data); | - |
| 945 | break; | - |
| 946 | case QMetaType::QLineF: | - |
| 947 | stream << *static_cast<const NS(QLineF)*>(data); | - |
| 948 | break; | - |
| 949 | case QMetaType::QPoint: | - |
| 950 | stream << *static_cast<const NS(QPoint)*>(data); | - |
| 951 | break; | - |
| 952 | case QMetaType::QPointF: | - |
| 953 | stream << *static_cast<const NS(QPointF)*>(data); | - |
| 954 | break; | - |
| 955 | #endif | - |
| 956 | #ifndef QT_NO_REGEXP | - |
| 957 | case QMetaType::QRegExp: | - |
| 958 | stream << *static_cast<const NS(QRegExp)*>(data); | - |
| 959 | break; | - |
| 960 | #endif | - |
| 961 | #ifndef QT_BOOTSTRAPPED | - |
| 962 | #ifndef QT_NO_REGEXP | - |
| 963 | case QMetaType::QRegularExpression: | - |
| 964 | stream << *static_cast<const NS(QRegularExpression)*>(data); | - |
| 965 | break; | - |
| 966 | #endif // QT_NO_REGEXP | - |
| 967 | case QMetaType::QEasingCurve: | - |
| 968 | stream << *static_cast<const NS(QEasingCurve)*>(data); | - |
| 969 | break; | - |
| 970 | #endif // QT_BOOTSTRAPPED | - |
| 971 | case QMetaType::QFont: | - |
| 972 | case QMetaType::QPixmap: | - |
| 973 | case QMetaType::QBrush: | - |
| 974 | case QMetaType::QColor: | - |
| 975 | case QMetaType::QPalette: | - |
| 976 | case QMetaType::QImage: | - |
| 977 | case QMetaType::QPolygon: | - |
| 978 | case QMetaType::QPolygonF: | - |
| 979 | case QMetaType::QRegion: | - |
| 980 | case QMetaType::QBitmap: | - |
| 981 | case QMetaType::QCursor: | - |
| 982 | case QMetaType::QKeySequence: | - |
| 983 | case QMetaType::QPen: | - |
| 984 | case QMetaType::QTextLength: | - |
| 985 | case QMetaType::QTextFormat: | - |
| 986 | case QMetaType::QMatrix: | - |
| 987 | case QMetaType::QTransform: | - |
| 988 | case QMetaType::QMatrix4x4: | - |
| 989 | case QMetaType::QVector2D: | - |
| 990 | case QMetaType::QVector3D: | - |
| 991 | case QMetaType::QVector4D: | - |
| 992 | case QMetaType::QQuaternion: | - |
| 993 | case QMetaType::QIcon: | - |
| 994 | if (!qMetaTypeGuiHelper) | - |
| 995 | return false; | - |
| 996 | qMetaTypeGuiHelper[type - FirstGuiType].saveOp(stream, data); | - |
| 997 | break; | - |
| 998 | case QMetaType::QSizePolicy: | - |
| 999 | if (!qMetaTypeWidgetsHelper) | - |
| 1000 | return false; | - |
| 1001 | qMetaTypeWidgetsHelper[type - FirstWidgetsType].saveOp(stream, data); | - |
| 1002 | break; | - |
| 1003 | case QMetaType::QUuid: | - |
| 1004 | stream << *static_cast<const NS(QUuid)*>(data); | - |
| 1005 | break; | - |
| 1006 | default: { | - |
| 1007 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - |
| 1008 | if (!ct) | - |
| 1009 | return false; | - |
| 1010 | | - |
| 1011 | SaveOperator saveOp = 0; | - |
| 1012 | { | - |
| 1013 | QReadLocker locker(customTypesLock()); | - |
| 1014 | saveOp = ct->at(type - User).saveOp; | - |
| 1015 | } | - |
| 1016 | | - |
| 1017 | if (!saveOp) | - |
| 1018 | return false; | - |
| 1019 | saveOp(stream, data); | - |
| 1020 | break; } | - |
| 1021 | } | - |
| 1022 | | - |
| 1023 | return true; | - |
| 1024 | } | - |
| 1025 | | - |
| 1026 | /*! | - |
| 1027 | Reads the object of the specified \a type from the given \a | - |
| 1028 | stream into \a data. Returns true if the object is loaded | - |
| 1029 | successfully; otherwise returns false. | - |
| 1030 | | - |
| 1031 | The type must have been registered with qRegisterMetaType() and | - |
| 1032 | qRegisterMetaTypeStreamOperators() beforehand. | - |
| 1033 | | - |
| 1034 | Normally, you should not need to call this function directly. | - |
| 1035 | Instead, use QVariant's \c operator>>(), which relies on load() | - |
| 1036 | to stream custom types. | - |
| 1037 | | - |
| 1038 | \sa save(), qRegisterMetaTypeStreamOperators() | - |
| 1039 | */ | - |
| 1040 | bool QMetaType::load(QDataStream &stream, int type, void *data) | - |
| 1041 | { | - |
| 1042 | if (!data || !isRegistered(type)) | - |
| 1043 | return false; | - |
| 1044 | | - |
| 1045 | switch(type) { | - |
| 1046 | case QMetaType::UnknownType: | - |
| 1047 | case QMetaType::Void: | - |
| 1048 | case QMetaType::VoidStar: | - |
| 1049 | case QMetaType::QObjectStar: | - |
| 1050 | case QMetaType::QModelIndex: | - |
| 1051 | case QMetaType::QJsonValue: | - |
| 1052 | case QMetaType::QJsonObject: | - |
| 1053 | case QMetaType::QJsonArray: | - |
| 1054 | case QMetaType::QJsonDocument: | - |
| 1055 | return false; | - |
| 1056 | case QMetaType::Long: { | - |
| 1057 | qlonglong l; | - |
| 1058 | stream >> l; | - |
| 1059 | *static_cast<long *>(data) = long(l); | - |
| 1060 | break; } | - |
| 1061 | case QMetaType::Int: | - |
| 1062 | stream >> *static_cast<int *>(data); | - |
| 1063 | break; | - |
| 1064 | case QMetaType::Short: | - |
| 1065 | stream >> *static_cast<short *>(data); | - |
| 1066 | break; | - |
| 1067 | case QMetaType::Char: | - |
| 1068 | // force a char to be signed | - |
| 1069 | stream >> *static_cast<signed char *>(data); | - |
| 1070 | break; | - |
| 1071 | case QMetaType::ULong: { | - |
| 1072 | qulonglong ul; | - |
| 1073 | stream >> ul; | - |
| 1074 | *static_cast<ulong *>(data) = ulong(ul); | - |
| 1075 | break; } | - |
| 1076 | case QMetaType::UInt: | - |
| 1077 | stream >> *static_cast<uint *>(data); | - |
| 1078 | break; | - |
| 1079 | case QMetaType::LongLong: | - |
| 1080 | stream >> *static_cast<qlonglong *>(data); | - |
| 1081 | break; | - |
| 1082 | case QMetaType::ULongLong: | - |
| 1083 | stream >> *static_cast<qulonglong *>(data); | - |
| 1084 | break; | - |
| 1085 | case QMetaType::UShort: | - |
| 1086 | stream >> *static_cast<ushort *>(data); | - |
| 1087 | break; | - |
| 1088 | case QMetaType::SChar: | - |
| 1089 | stream >> *static_cast<signed char *>(data); | - |
| 1090 | break; | - |
| 1091 | case QMetaType::UChar: | - |
| 1092 | stream >> *static_cast<uchar *>(data); | - |
| 1093 | break; | - |
| 1094 | case QMetaType::Bool: { | - |
| 1095 | qint8 b; | - |
| 1096 | stream >> b; | - |
| 1097 | *static_cast<bool *>(data) = b; | - |
| 1098 | break; } | - |
| 1099 | case QMetaType::Float: | - |
| 1100 | stream >> *static_cast<float *>(data); | - |
| 1101 | break; | - |
| 1102 | case QMetaType::Double: | - |
| 1103 | stream >> *static_cast<double *>(data); | - |
| 1104 | break; | - |
| 1105 | case QMetaType::QChar: | - |
| 1106 | stream >> *static_cast< NS(QChar)*>(data); | - |
| 1107 | break; | - |
| 1108 | #ifndef QT_BOOTSTRAPPED | - |
| 1109 | case QMetaType::QVariantMap: | - |
| 1110 | stream >> *static_cast< NS(QVariantMap)*>(data); | - |
| 1111 | break; | - |
| 1112 | case QMetaType::QVariantHash: | - |
| 1113 | stream >> *static_cast< NS(QVariantHash)*>(data); | - |
| 1114 | break; | - |
| 1115 | case QMetaType::QVariantList: | - |
| 1116 | stream >> *static_cast< NS(QVariantList)*>(data); | - |
| 1117 | break; | - |
| 1118 | case QMetaType::QVariant: | - |
| 1119 | stream >> *static_cast< NS(QVariant)*>(data); | - |
| 1120 | break; | - |
| 1121 | #endif | - |
| 1122 | case QMetaType::QByteArray: | - |
| 1123 | stream >> *static_cast< NS(QByteArray)*>(data); | - |
| 1124 | break; | - |
| 1125 | case QMetaType::QString: | - |
| 1126 | stream >> *static_cast< NS(QString)*>(data); | - |
| 1127 | break; | - |
| 1128 | case QMetaType::QStringList: | - |
| 1129 | stream >> *static_cast< NS(QStringList)*>(data); | - |
| 1130 | break; | - |
| 1131 | #ifndef QT_BOOTSTRAPPED | - |
| 1132 | case QMetaType::QBitArray: | - |
| 1133 | stream >> *static_cast< NS(QBitArray)*>(data); | - |
| 1134 | break; | - |
| 1135 | #endif | - |
| 1136 | case QMetaType::QDate: | - |
| 1137 | stream >> *static_cast< NS(QDate)*>(data); | - |
| 1138 | break; | - |
| 1139 | case QMetaType::QTime: | - |
| 1140 | stream >> *static_cast< NS(QTime)*>(data); | - |
| 1141 | break; | - |
| 1142 | case QMetaType::QDateTime: | - |
| 1143 | stream >> *static_cast< NS(QDateTime)*>(data); | - |
| 1144 | break; | - |
| 1145 | #ifndef QT_BOOTSTRAPPED | - |
| 1146 | case QMetaType::QUrl: | - |
| 1147 | stream >> *static_cast< NS(QUrl)*>(data); | - |
| 1148 | break; | - |
| 1149 | #endif | - |
| 1150 | case QMetaType::QLocale: | - |
| 1151 | stream >> *static_cast< NS(QLocale)*>(data); | - |
| 1152 | break; | - |
| 1153 | #ifndef QT_NO_GEOM_VARIANT | - |
| 1154 | case QMetaType::QRect: | - |
| 1155 | stream >> *static_cast< NS(QRect)*>(data); | - |
| 1156 | break; | - |
| 1157 | case QMetaType::QRectF: | - |
| 1158 | stream >> *static_cast< NS(QRectF)*>(data); | - |
| 1159 | break; | - |
| 1160 | case QMetaType::QSize: | - |
| 1161 | stream >> *static_cast< NS(QSize)*>(data); | - |
| 1162 | break; | - |
| 1163 | case QMetaType::QSizeF: | - |
| 1164 | stream >> *static_cast< NS(QSizeF)*>(data); | - |
| 1165 | break; | - |
| 1166 | case QMetaType::QLine: | - |
| 1167 | stream >> *static_cast< NS(QLine)*>(data); | - |
| 1168 | break; | - |
| 1169 | case QMetaType::QLineF: | - |
| 1170 | stream >> *static_cast< NS(QLineF)*>(data); | - |
| 1171 | break; | - |
| 1172 | case QMetaType::QPoint: | - |
| 1173 | stream >> *static_cast< NS(QPoint)*>(data); | - |
| 1174 | break; | - |
| 1175 | case QMetaType::QPointF: | - |
| 1176 | stream >> *static_cast< NS(QPointF)*>(data); | - |
| 1177 | break; | - |
| 1178 | #endif | - |
| 1179 | #ifndef QT_NO_REGEXP | - |
| 1180 | case QMetaType::QRegExp: | - |
| 1181 | stream >> *static_cast< NS(QRegExp)*>(data); | - |
| 1182 | break; | - |
| 1183 | #endif | - |
| 1184 | #ifndef QT_BOOTSTRAPPED | - |
| 1185 | #ifndef QT_NO_REGEXP | - |
| 1186 | case QMetaType::QRegularExpression: | - |
| 1187 | stream >> *static_cast< NS(QRegularExpression)*>(data); | - |
| 1188 | break; | - |
| 1189 | #endif // QT_NO_REGEXP | - |
| 1190 | case QMetaType::QEasingCurve: | - |
| 1191 | stream >> *static_cast< NS(QEasingCurve)*>(data); | - |
| 1192 | break; | - |
| 1193 | #endif // QT_BOOTSTRAPPED | - |
| 1194 | case QMetaType::QFont: | - |
| 1195 | case QMetaType::QPixmap: | - |
| 1196 | case QMetaType::QBrush: | - |
| 1197 | case QMetaType::QColor: | - |
| 1198 | case QMetaType::QPalette: | - |
| 1199 | case QMetaType::QImage: | - |
| 1200 | case QMetaType::QPolygon: | - |
| 1201 | case QMetaType::QPolygonF: | - |
| 1202 | case QMetaType::QRegion: | - |
| 1203 | case QMetaType::QBitmap: | - |
| 1204 | case QMetaType::QCursor: | - |
| 1205 | case QMetaType::QKeySequence: | - |
| 1206 | case QMetaType::QPen: | - |
| 1207 | case QMetaType::QTextLength: | - |
| 1208 | case QMetaType::QTextFormat: | - |
| 1209 | case QMetaType::QMatrix: | - |
| 1210 | case QMetaType::QTransform: | - |
| 1211 | case QMetaType::QMatrix4x4: | - |
| 1212 | case QMetaType::QVector2D: | - |
| 1213 | case QMetaType::QVector3D: | - |
| 1214 | case QMetaType::QVector4D: | - |
| 1215 | case QMetaType::QQuaternion: | - |
| 1216 | case QMetaType::QIcon: | - |
| 1217 | if (!qMetaTypeGuiHelper) | - |
| 1218 | return false; | - |
| 1219 | qMetaTypeGuiHelper[type - FirstGuiType].loadOp(stream, data); | - |
| 1220 | break; | - |
| 1221 | case QMetaType::QSizePolicy: | - |
| 1222 | if (!qMetaTypeWidgetsHelper) | - |
| 1223 | return false; | - |
| 1224 | qMetaTypeWidgetsHelper[type - FirstWidgetsType].loadOp(stream, data); | - |
| 1225 | break; | - |
| 1226 | case QMetaType::QUuid: | - |
| 1227 | stream >> *static_cast< NS(QUuid)*>(data); | - |
| 1228 | break; | - |
| 1229 | default: { | - |
| 1230 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - |
| 1231 | if (!ct) | - |
| 1232 | return false; | - |
| 1233 | | - |
| 1234 | LoadOperator loadOp = 0; | - |
| 1235 | { | - |
| 1236 | QReadLocker locker(customTypesLock()); | - |
| 1237 | loadOp = ct->at(type - User).loadOp; | - |
| 1238 | } | - |
| 1239 | | - |
| 1240 | if (!loadOp) | - |
| 1241 | return false; | - |
| 1242 | loadOp(stream, data); | - |
| 1243 | break; } | - |
| 1244 | } | - |
| 1245 | return true; | - |
| 1246 | } | - |
| 1247 | #endif // QT_NO_DATASTREAM | - |
| 1248 | namespace { | - |
| 1249 | class TypeCreator { | - |
| 1250 | template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted> | - |
| 1251 | struct CreatorImpl { | - |
| 1252 | static void *Create(const int /* type */, const void *copy) | - |
| 1253 | { | - |
| 1254 | // Using QMetaTypeFunctionHelper<T>::Create adds function call cost, even if it is a template (gcc). | - |
| 1255 | // This "copy" check is moved out from the switcher by compiler (at least by gcc) | - |
| 1256 | return copy ? new T(*static_cast<const T*>(copy)) : new T(); | - |
| 1257 | } | - |
| 1258 | }; | - |
| 1259 | template<typename T> | - |
| 1260 | struct CreatorImpl<T, /* IsAcceptedType = */ false> { | - |
| 1261 | static void *Create(const int type, const void *copy) | - |
| 1262 | { | - |
| 1263 | if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) { | - |
| 1264 | if (Q_LIKELY(qMetaTypeGuiHelper)) | - |
| 1265 | return qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].creator(copy); | - |
| 1266 | } | - |
| 1267 | if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) { | - |
| 1268 | if (Q_LIKELY(qMetaTypeWidgetsHelper)) | - |
| 1269 | return qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].creator(copy); | - |
| 1270 | } | - |
| 1271 | // This point can be reached only for known types that definition is not available, for example | - |
| 1272 | // in bootstrap mode. We have no other choice then ignore it. | - |
| 1273 | return 0; | - |
| 1274 | } | - |
| 1275 | }; | - |
| 1276 | public: | - |
| 1277 | TypeCreator(const int type) | - |
| 1278 | : m_type(type) | - |
| 1279 | {} | - |
| 1280 | | - |
| 1281 | template<typename T> | - |
| 1282 | void *delegate(const T *copy) { return CreatorImpl<T>::Create(m_type, copy); } | - |
| 1283 | void *delegate(const void*) { return 0; } | - |
| 1284 | void *delegate(const QMetaTypeSwitcher::UnknownType *) { return 0; } | - |
| 1285 | void *delegate(const QMetaTypeSwitcher::NotBuiltinType *copy) | - |
| 1286 | { | - |
| 1287 | QMetaType::Creator creator; | - |
| 1288 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - |
| 1289 | { | - |
| 1290 | QReadLocker locker(customTypesLock()); | - |
| 1291 | if (Q_UNLIKELY(m_type < QMetaType::User || !ct || ct->count() <= m_type - QMetaType::User)) | - |
| 1292 | return 0; | - |
| 1293 | creator = ct->at(m_type - QMetaType::User).creator; | - |
| 1294 | } | - |
| 1295 | Q_ASSERT_X(creator, "void *QMetaType::create(int type, const void *copy)", "The type was not properly registered"); | - |
| 1296 | return creator(copy); | - |
| 1297 | } | - |
| 1298 | private: | - |
| 1299 | const int m_type; | - |
| 1300 | }; | - |
| 1301 | } // namespace | - |
| 1302 | | - |
| 1303 | /*! | - |
| 1304 | Returns a copy of \a copy, assuming it is of type \a type. If \a | - |
| 1305 | copy is zero, creates a default constructed instance. | - |
| 1306 | | - |
| 1307 | \sa destroy(), isRegistered(), Type | - |
| 1308 | */ | - |
| 1309 | void *QMetaType::create(int type, const void *copy) | - |
| 1310 | { | - |
| 1311 | TypeCreator typeCreator(type); | - |
| 1312 | return QMetaTypeSwitcher::switcher<void*>(typeCreator, type, copy); | - |
| 1313 | } | - |
| 1314 | | - |
| 1315 | namespace { | - |
| 1316 | class TypeDestroyer { | - |
| 1317 | template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted> | - |
| 1318 | struct DestroyerImpl { | - |
| 1319 | static void Destroy(const int /* type */, void *where) { QtMetaTypePrivate::QMetaTypeFunctionHelper<T>::Delete(where); } | - |
| 1320 | }; | - |
| 1321 | template<typename T> | - |
| 1322 | struct DestroyerImpl<T, /* IsAcceptedType = */ false> { | - |
| 1323 | static void Destroy(const int type, void *where) | - |
| 1324 | { | - |
| 1325 | if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) { | - |
| 1326 | if (Q_LIKELY(qMetaTypeGuiHelper)) | - |
| 1327 | qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].deleter(where); | - |
| 1328 | return; | - |
| 1329 | } | - |
| 1330 | if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) { | - |
| 1331 | if (Q_LIKELY(qMetaTypeWidgetsHelper)) | - |
| 1332 | qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].deleter(where); | - |
| 1333 | return; | - |
| 1334 | } | - |
| 1335 | // This point can be reached only for known types that definition is not available, for example | - |
| 1336 | // in bootstrap mode. We have no other choice then ignore it. | - |
| 1337 | } | - |
| 1338 | }; | - |
| 1339 | public: | - |
| 1340 | TypeDestroyer(const int type) | - |
| 1341 | : m_type(type) | - |
| 1342 | {} | - |
| 1343 | | - |
| 1344 | template<typename T> | - |
| 1345 | void delegate(const T *where) { DestroyerImpl<T>::Destroy(m_type, const_cast<T*>(where)); } | - |
| 1346 | void delegate(const void *) {} | - |
| 1347 | void delegate(const QMetaTypeSwitcher::UnknownType*) {} | - |
| 1348 | void delegate(const QMetaTypeSwitcher::NotBuiltinType *where) { customTypeDestroyer(m_type, (void*)where); } | - |
| 1349 | | - |
| 1350 | private: | - |
| 1351 | static void customTypeDestroyer(const int type, void *where) | - |
| 1352 | { | - |
| 1353 | QMetaType::Destructor deleter; | - |
| 1354 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - |
| 1355 | { | - |
| 1356 | QReadLocker locker(customTypesLock()); | - |
| 1357 | if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User)) | - |
| 1358 | return; | - |
| 1359 | deleter = ct->at(type - QMetaType::User).deleter; | - |
| 1360 | } | - |
| 1361 | Q_ASSERT_X(deleter, "void QMetaType::destroy(int type, void *data)", "The type was not properly registered"); | - |
| 1362 | deleter(where); | - |
| 1363 | } | - |
| 1364 | | - |
| 1365 | const int m_type; | - |
| 1366 | }; | - |
| 1367 | } // namespace | - |
| 1368 | | - |
| 1369 | | - |
| 1370 | /*! | - |
| 1371 | Destroys the \a data, assuming it is of the \a type given. | - |
| 1372 | | - |
| 1373 | \sa create(), isRegistered(), Type | - |
| 1374 | */ | - |
| 1375 | void QMetaType::destroy(int type, void *data) | - |
| 1376 | { | - |
| 1377 | TypeDestroyer deleter(type); | - |
| 1378 | QMetaTypeSwitcher::switcher<void>(deleter, type, data); | - |
| 1379 | } | - |
| 1380 | | - |
| 1381 | namespace { | - |
| 1382 | class TypeConstructor { | - |
| 1383 | template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted> | - |
| 1384 | struct ConstructorImpl { | - |
| 1385 | static void *Construct(const int /*type*/, void *where, const void *copy) { return QtMetaTypePrivate::QMetaTypeFunctionHelper<T>::Construct(where, copy); } | - |
| 1386 | }; | - |
| 1387 | template<typename T> | - |
| 1388 | struct ConstructorImpl<T, /* IsAcceptedType = */ false> { | - |
| 1389 | static void *Construct(const int type, void *where, const void *copy) | - |
| 1390 | { | - |
| 1391 | if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) | - |
| 1392 | return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].constructor(where, copy) : 0; | - |
| 1393 | | - |
| 1394 | if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) | - |
| 1395 | return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].constructor(where, copy) : 0; | - |
| 1396 | | - |
| 1397 | // This point can be reached only for known types that definition is not available, for example | - |
| 1398 | // in bootstrap mode. We have no other choice then ignore it. | - |
| 1399 | return 0; | - |
| 1400 | } | - |
| 1401 | }; | - |
| 1402 | public: | - |
| 1403 | TypeConstructor(const int type, void *where) | - |
| 1404 | : m_type(type) | - |
| 1405 | , m_where(where) | - |
| 1406 | {} | - |
| 1407 | | - |
| 1408 | template<typename T> | - |
| 1409 | void *delegate(const T *copy) { return ConstructorImpl<T>::Construct(m_type, m_where, copy); } | - |
| 1410 | void *delegate(const void *) { return m_where; } | - |
| 1411 | void *delegate(const QMetaTypeSwitcher::UnknownType*) { return m_where; } | - |
| 1412 | void *delegate(const QMetaTypeSwitcher::NotBuiltinType *copy) { return customTypeConstructor(m_type, m_where, copy); } | - |
| 1413 | | - |
| 1414 | private: | - |
| 1415 | static void *customTypeConstructor(const int type, void *where, const void *copy) | - |
| 1416 | { | - |
| 1417 | QMetaType::Constructor ctor; | - |
| 1418 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - |
| 1419 | { | - |
| 1420 | QReadLocker locker(customTypesLock()); | - |
| 1421 | if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User)) | - |
| 1422 | return 0; | - |
| 1423 | ctor = ct->at(type - QMetaType::User).constructor; | - |
| 1424 | } | - |
| 1425 | Q_ASSERT_X(ctor, "void *QMetaType::construct(int type, void *where, const void *copy)", "The type was not properly registered"); | - |
| 1426 | return ctor(where, copy); | - |
| 1427 | } | - |
| 1428 | | - |
| 1429 | const int m_type; | - |
| 1430 | void *m_where; | - |
| 1431 | }; | - |
| 1432 | } // namespace | - |
| 1433 | | - |
| 1434 | /*! | - |
| 1435 | \since 5.0 | - |
| 1436 | | - |
| 1437 | Constructs a value of the given \a type in the existing memory | - |
| 1438 | addressed by \a where, that is a copy of \a copy, and returns | - |
| 1439 | \a where. If \a copy is zero, the value is default constructed. | - |
| 1440 | | - |
| 1441 | This is a low-level function for explicitly managing the memory | - |
| 1442 | used to store the type. Consider calling create() if you don't | - |
| 1443 | need this level of control (that is, use "new" rather than | - |
| 1444 | "placement new"). | - |
| 1445 | | - |
| 1446 | You must ensure that \a where points to a location that can store | - |
| 1447 | a value of type \a type, and that \a where is suitably aligned. | - |
| 1448 | The type's size can be queried by calling sizeOf(). | - |
| 1449 | | - |
| 1450 | The rule of thumb for alignment is that a type is aligned to its | - |
| 1451 | natural boundary, which is the smallest power of 2 that is bigger | - |
| 1452 | than the type, unless that alignment is larger than the maximum | - |
| 1453 | useful alignment for the platform. For practical purposes, | - |
| 1454 | alignment larger than 2 * sizeof(void*) is only necessary for | - |
| 1455 | special hardware instructions (e.g., aligned SSE loads and stores | - |
| 1456 | on x86). | - |
| 1457 | | - |
| 1458 | \sa destruct(), sizeOf() | - |
| 1459 | */ | - |
| 1460 | void *QMetaType::construct(int type, void *where, const void *copy) | - |
| 1461 | { | - |
| 1462 | if (!where) | - |
| 1463 | return 0; | - |
| 1464 | TypeConstructor constructor(type, where); | - |
| 1465 | return QMetaTypeSwitcher::switcher<void*>(constructor, type, copy); | - |
| 1466 | } | - |
| 1467 | | - |
| 1468 | | - |
| 1469 | namespace { | - |
| 1470 | class TypeDestructor { | - |
| 1471 | template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted> | - |
| 1472 | struct DestructorImpl { | - |
| 1473 | static void Destruct(const int /* type */, void *where) { QtMetaTypePrivate::QMetaTypeFunctionHelper<T>::Destruct(where); } | - |
| 1474 | }; | - |
| 1475 | template<typename T> | - |
| 1476 | struct DestructorImpl<T, /* IsAcceptedType = */ false> { | - |
| 1477 | static void Destruct(const int type, void *where) | - |
| 1478 | { | - |
| 1479 | if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) { | - |
| 1480 | if (Q_LIKELY(qMetaTypeGuiHelper)) | - |
| 1481 | qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].destructor(where); | - |
| 1482 | return; | - |
| 1483 | } | - |
| 1484 | if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) { | - |
| 1485 | if (Q_LIKELY(qMetaTypeWidgetsHelper)) | - |
| 1486 | qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].destructor(where); | - |
| 1487 | return; | - |
| 1488 | } | - |
| 1489 | // This point can be reached only for known types that definition is not available, for example | - |
| 1490 | // in bootstrap mode. We have no other choice then ignore it. | - |
| 1491 | } | - |
| 1492 | }; | - |
| 1493 | public: | - |
| 1494 | TypeDestructor(const int type) | - |
| 1495 | : m_type(type) | - |
| 1496 | {} | - |
| 1497 | | - |
| 1498 | template<typename T> | - |
| 1499 | void delegate(const T *where) { DestructorImpl<T>::Destruct(m_type, const_cast<T*>(where)); } | - |
| 1500 | void delegate(const void *) {} | - |
| 1501 | void delegate(const QMetaTypeSwitcher::UnknownType*) {} | - |
| 1502 | void delegate(const QMetaTypeSwitcher::NotBuiltinType *where) { customTypeDestructor(m_type, (void*)where); } | - |
| 1503 | | - |
| 1504 | private: | - |
| 1505 | static void customTypeDestructor(const int type, void *where) | - |
| 1506 | { | - |
| 1507 | QMetaType::Destructor dtor; | - |
| 1508 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - |
| 1509 | { | - |
| 1510 | QReadLocker locker(customTypesLock()); | - |
| 1511 | if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User)) | - |
| 1512 | return; | - |
| 1513 | dtor = ct->at(type - QMetaType::User).destructor; | - |
| 1514 | } | - |
| 1515 | Q_ASSERT_X(dtor, "void QMetaType::destruct(int type, void *where)", "The type was not properly registered"); | - |
| 1516 | dtor(where); | - |
| 1517 | } | - |
| 1518 | | - |
| 1519 | const int m_type; | - |
| 1520 | }; | - |
| 1521 | } // namespace | - |
| 1522 | | - |
| 1523 | /*! | - |
| 1524 | \since 5.0 | - |
| 1525 | | - |
| 1526 | Destructs the value of the given \a type, located at \a where. | - |
| 1527 | | - |
| 1528 | Unlike destroy(), this function only invokes the type's | - |
| 1529 | destructor, it doesn't invoke the delete operator. | - |
| 1530 | | - |
| 1531 | \sa construct() | - |
| 1532 | */ | - |
| 1533 | void QMetaType::destruct(int type, void *where) | - |
| 1534 | { | - |
| 1535 | if (!where) | - |
| 1536 | return; | - |
| 1537 | TypeDestructor destructor(type); | - |
| 1538 | QMetaTypeSwitcher::switcher<void>(destructor, type, where); | - |
| 1539 | } | - |
| 1540 | | - |
| 1541 | | - |
| 1542 | namespace { | - |
| 1543 | class SizeOf { | - |
| 1544 | template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted> | - |
| 1545 | struct SizeOfImpl { | - |
| 1546 | static int Size(const int) { return QTypeInfo<T>::sizeOf; } | - |
| 1547 | }; | - |
| 1548 | template<typename T> | - |
| 1549 | struct SizeOfImpl<T, /* IsAcceptedType = */ false> { | - |
| 1550 | static int Size(const int type) | - |
| 1551 | { | - |
| 1552 | if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) | - |
| 1553 | return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].size : 0; | - |
| 1554 | | - |
| 1555 | if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) | - |
| 1556 | return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].size : 0; | - |
| 1557 | | - |
| 1558 | // This point can be reached only for known types that definition is not available, for example | - |
| 1559 | // in bootstrap mode. We have no other choice then ignore it. | - |
| 1560 | return 0; | - |
| 1561 | } | - |
| 1562 | }; | - |
| 1563 | | - |
| 1564 | public: | - |
| 1565 | SizeOf(int type) | - |
| 1566 | : m_type(type) | - |
| 1567 | {} | - |
| 1568 | | - |
| 1569 | template<typename T> | - |
| 1570 | int delegate(const T*) { return SizeOfImpl<T>::Size(m_type); } | - |
| 1571 | int delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; } | - |
| 1572 | int delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customTypeSizeOf(m_type); } | - |
| 1573 | private: | - |
| 1574 | static int customTypeSizeOf(const int type) | - |
| 1575 | { | - |
| 1576 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - |
| 1577 | QReadLocker locker(customTypesLock()); | - |
| 1578 | if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User)) | - |
| 1579 | return 0; | - |
| 1580 | return ct->at(type - QMetaType::User).size; | - |
| 1581 | } | - |
| 1582 | | - |
| 1583 | const int m_type; | - |
| 1584 | }; | - |
| 1585 | } // namespace | - |
| 1586 | | - |
| 1587 | /*! | - |
| 1588 | \since 5.0 | - |
| 1589 | | - |
| 1590 | Returns the size of the given \a type in bytes (i.e. sizeof(T), | - |
| 1591 | where T is the actual type identified by the \a type argument). | - |
| 1592 | | - |
| 1593 | This function is typically used together with construct() | - |
| 1594 | to perform low-level management of the memory used by a type. | - |
| 1595 | | - |
| 1596 | \sa construct() | - |
| 1597 | */ | - |
| 1598 | int QMetaType::sizeOf(int type) | - |
| 1599 | { | - |
| 1600 | SizeOf sizeOf(type); | - |
| 1601 | return QMetaTypeSwitcher::switcher<int>(sizeOf, type, 0); | - |
| 1602 | } | - |
| 1603 | | - |
| 1604 | namespace { | - |
| 1605 | class Flags | - |
| 1606 | { | - |
| 1607 | template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted> | - |
| 1608 | struct FlagsImpl | - |
| 1609 | { | - |
| 1610 | static quint32 Flags(const int /* type */) | - |
| 1611 | { | - |
| 1612 | return QtPrivate::QMetaTypeTypeFlags<T>::Flags; | - |
| 1613 | } | - |
| 1614 | }; | - |
| 1615 | template<typename T> | - |
| 1616 | struct FlagsImpl<T, /* IsAcceptedType = */ false> | - |
| 1617 | { | - |
| 1618 | static quint32 Flags(const int type) | - |
| 1619 | { | - |
| 1620 | if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) | - |
| 1621 | return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].flags : 0; | - |
| 1622 | | - |
| 1623 | if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) | - |
| 1624 | return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].flags : 0; | - |
| 1625 | | - |
| 1626 | // This point can be reached only for known types that definition is not available, for example | - |
| 1627 | // in bootstrap mode. We have no other choice then ignore it. | - |
| 1628 | return 0; | - |
| 1629 | } | - |
| 1630 | }; | - |
| 1631 | public: | - |
| 1632 | Flags(const int type) | - |
| 1633 | : m_type(type) | - |
| 1634 | {} | - |
| 1635 | template<typename T> | - |
| 1636 | quint32 delegate(const T*) { return FlagsImpl<T>::Flags(m_type); } | - |
| 1637 | quint32 delegate(const void*) { return 0; } | - |
| 1638 | quint32 delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; } | - |
| 1639 | quint32 delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customTypeFlags(m_type); } | - |
| 1640 | private: | - |
| 1641 | const int m_type; | - |
| 1642 | static quint32 customTypeFlags(const int type) | - |
| 1643 | { | - |
| 1644 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - |
| 1645 | if (Q_UNLIKELY(!ct || type < QMetaType::User)) | - |
| 1646 | return 0; | - |
| 1647 | QReadLocker locker(customTypesLock()); | - |
| 1648 | if (Q_UNLIKELY(ct->count() <= type - QMetaType::User)) | - |
| 1649 | return 0; | - |
| 1650 | return ct->at(type - QMetaType::User).flags; | - |
| 1651 | } | - |
| 1652 | }; | - |
| 1653 | } // namespace | - |
| 1654 | | - |
| 1655 | /*! | - |
| 1656 | \since 5.0 | - |
| 1657 | | - |
| 1658 | Returns flags of the given \a type. | - |
| 1659 | | - |
| 1660 | \sa QMetaType::TypeFlags | - |
| 1661 | */ | - |
| 1662 | QMetaType::TypeFlags QMetaType::typeFlags(int type) | - |
| 1663 | { | - |
| 1664 | Flags flags(type); | - |
| 1665 | return static_cast<QMetaType::TypeFlags>(QMetaTypeSwitcher::switcher<quint32>(flags, type, 0)); | - |
| 1666 | } | - |
| 1667 | | - |
| 1668 | #ifndef QT_BOOTSTRAPPED | - |
| 1669 | namespace { | - |
| 1670 | class MetaObject | - |
| 1671 | { | - |
| 1672 | public: | - |
| 1673 | MetaObject(const int type) | - |
| 1674 | : m_type(type) | - |
| 1675 | {} | - |
| 1676 | template<typename T> | - |
| 1677 | const QMetaObject *delegate(const T*) { return QtPrivate::MetaObjectForType<T>::value(); } | - |
| 1678 | const QMetaObject *delegate(const void*) { return 0; } | - |
| 1679 | const QMetaObject *delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; } | - |
| 1680 | const QMetaObject *delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customMetaObject(m_type); } | - |
| 1681 | private: | - |
| 1682 | const int m_type; | - |
| 1683 | static const QMetaObject *customMetaObject(const int type) | - |
| 1684 | { | - |
| 1685 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - |
| 1686 | if (Q_UNLIKELY(!ct || type < QMetaType::User)) | - |
| 1687 | return 0; | - |
| 1688 | QReadLocker locker(customTypesLock()); | - |
| 1689 | if (Q_UNLIKELY(ct->count() <= type - QMetaType::User)) | - |
| 1690 | return 0; | - |
| 1691 | return ct->at(type - QMetaType::User).metaObject; | - |
| 1692 | } | - |
| 1693 | }; | - |
| 1694 | } // namespace | - |
| 1695 | #endif | - |
| 1696 | | - |
| 1697 | /*! | - |
| 1698 | \since 5.0 | - |
| 1699 | | - |
| 1700 | Returns QMetaObject of a given \a type, if the \a type is a pointer to type derived from QObject. | - |
| 1701 | */ | - |
| 1702 | const QMetaObject *QMetaType::metaObjectForType(int type) | - |
| 1703 | { | - |
| 1704 | #ifndef QT_BOOTSTRAPPED | - |
| 1705 | MetaObject mo(type); | - |
| 1706 | return QMetaTypeSwitcher::switcher<const QMetaObject*>(mo, type, 0); | - |
| 1707 | #else | - |
| 1708 | Q_UNUSED(type); | - |
| 1709 | return 0; | - |
| 1710 | #endif | - |
| 1711 | } | - |
| 1712 | | - |
| 1713 | /*! | - |
| | \fn int qRegisterMetaType(const char *typeName) | |
| | \relates QMetaType | |
| | \threadsafe | |
| | | |
| | Registers the type name \a typeName for the type \c{T}. Returns | |
| | the internal ID used by QMetaType. Any class or struct that has a | |
| | public default constructor, a public copy constructor and a public | |
| | destructor can be registered. | |
| | | |
| | This function requires that \c{T} is a fully defined type at the point | |
| | where the function is called. For pointer types, it also requires that the | |
| | pointed to type is fully defined. Use Q_DECLARE_OPAQUE_POINTER() to be able | |
| | to register pointers to forward declared types. | |
| | | |
| | After a type has been registered, you can create and destroy | |
| | objects of that type dynamically at run-time. | |
| | | |
| | This example registers the class \c{MyClass}: | |
| | | |
| | \snippet code/src_corelib_kernel_qmetatype.cpp 4 | |
| | | |
| | This function is useful to register typedefs so they can be used | |
| | by QMetaProperty, or in QueuedConnections | |
| | | |
| | \snippet code/src_corelib_kernel_qmetatype.cpp 9 | |
| | | |
| | \sa qRegisterMetaTypeStreamOperators(), QMetaType::isRegistered(), | |
| | Q_DECLARE_METATYPE() | |
| | */*! | |
| 1714 | \fn int qRegisterMetaType(const char *typeName) | - |
| 1715 | \relates QMetaType | - |
| 1716 | \threadsafe | - |
| 1717 | | - |
| 1718 | Registers the type name \a typeName for the type \c{T}. Returns | - |
| 1719 | the internal ID used by QMetaType. Any class or struct that has a | - |
| 1720 | public default constructor, a public copy constructor and a public | - |
| 1721 | destructor can be registered. | - |
| 1722 | | - |
| 1723 | This function requires that \c{T} is a fully defined type at the point | - |
| 1724 | where the function is called. For pointer types, it also requires that the | - |
| 1725 | pointed to type is fully defined. Use Q_DECLARE_OPAQUE_POINTER() to be able | - |
| 1726 | to register pointers to forward declared types. | - |
| 1727 | | - |
| 1728 | After a type has been registered, you can create and destroy | - |
| 1729 | objects of that type dynamically at run-time. | - |
| 1730 | | - |
| 1731 | This example registers the class \c{MyClass}: | - |
| 1732 | | - |
| 1733 | \snippet code/src_corelib_kernel_qmetatype.cpp 4 | - |
| 1734 | | - |
| 1735 | This function is useful to register typedefs so they can be used | - |
| 1736 | by QMetaProperty, or in QueuedConnections | - |
| 1737 | | - |
| 1738 | \snippet code/src_corelib_kernel_qmetatype.cpp 9 | - |
| 1739 | | - |
| 1740 | \warning This function is useful only for registering an alias (typedef) | - |
| 1741 | for every other use case Q_DECLARE_METATYPE and qMetaTypeId() should be used instead. | - |
| 1742 | | - |
| 1743 | \sa qRegisterMetaTypeStreamOperators(), QMetaType::isRegistered(), | - |
| 1744 | Q_DECLARE_METATYPE() | - |
| 1745 | */ | - |
| 1746 | | - |
| 1747 | /*! | - |
| 1748 | \fn void qRegisterMetaTypeStreamOperators(const char *typeName) | - |
| 1749 | \relates QMetaType | - |
| 1750 | \threadsafe | - |
| 1751 | | - |
| 1752 | Registers the stream operators for the type \c{T} called \a | - |
| 1753 | typeName. | - |
| 1754 | | - |
| 1755 | Afterward, the type can be streamed using QMetaType::load() and | - |
| 1756 | QMetaType::save(). These functions are used when streaming a | - |
| 1757 | QVariant. | - |
| 1758 | | - |
| 1759 | \snippet code/src_corelib_kernel_qmetatype.cpp 5 | - |
| 1760 | | - |
| 1761 | The stream operators should have the following signatures: | - |
| 1762 | | - |
| 1763 | \snippet code/src_corelib_kernel_qmetatype.cpp 6 | - |
| 1764 | | - |
| 1765 | \sa qRegisterMetaType(), QMetaType::isRegistered(), Q_DECLARE_METATYPE() | - |
| 1766 | */ | - |
| 1767 | | - |
| 1768 | /*! \typedef QMetaType::Deleter | - |
| 1769 | \internal | - |
| 1770 | */ | - |
| 1771 | /*! \typedef QMetaType::Creator | - |
| 1772 | \internal | - |
| 1773 | */ | - |
| 1774 | /*! \typedef QMetaType::SaveOperator | - |
| 1775 | \internal | - |
| 1776 | */ | - |
| 1777 | /*! \typedef QMetaType::LoadOperator | - |
| 1778 | \internal | - |
| 1779 | */ | - |
| 1780 | /*! \typedef QMetaType::Destructor | - |
| 1781 | \internal | - |
| 1782 | */ | - |
| 1783 | /*! \typedef QMetaType::Constructor | - |
| 1784 | \internal | - |
| 1785 | */ | - |
| 1786 | | - |
| 1787 | /*! | - |
| | \fn int qRegisterMetaType(const char *typeName) | |
| | \relates QMetaType | |
| | \threadsafe | |
| | \since 4.2 | |
| | | |
| | Call this function to register the type \c T. \c T must be declared with | |
| | Q_DECLARE_METATYPE(). Returns the meta type Id. | |
| | | |
| | Example: | |
| | | |
| | \snippet code/src_corelib_kernel_qmetatype.cpp 7 | |
| | | |
| | To use the type \c T in QVariant, using Q_DECLARE_METATYPE() is | |
| | sufficient. To use the type \c T in queued signal and slot connections, | |
| | \c{qRegisterMetaType<T>()} must be called before the first connection | |
| | is established. | |
| | | |
| | Also, to use type \c T with the QObject::property() API, | |
| | \c{qRegisterMetaType<T>()} must be called before it is used, typically | |
| | in the constructor of the class that uses \c T, or in the \c{main()} | |
| | function. | |
| | | |
| | \sa Q_DECLARE_METATYPE() | |
| | */*! | |
| 1788 | \fn int qRegisterMetaType() | - |
| 1789 | \relates QMetaType | - |
| 1790 | \threadsafe | - |
| 1791 | \since 4.2 | - |
| 1792 | | - |
| 1793 | Call this function to register the type \c T. \c T must be declared with | - |
| 1794 | Q_DECLARE_METATYPE(). Returns the meta type Id. | - |
| 1795 | | - |
| 1796 | Example: | - |
| 1797 | | - |
| 1798 | \snippet code/src_corelib_kernel_qmetatype.cpp 7 | - |
| 1799 | | - |
| 1800 | This function requires that \c{T} is a fully defined type at the point | - |
| 1801 | where the function is called. For pointer types, it also requires that the | - |
| 1802 | pointed to type is fully defined. Use Q_DECLARE_OPAQUE_POINTER() to be able | - |
| 1803 | to register pointers to forward declared types. | - |
| 1804 | | - |
| 1805 | After a type has been registered, you can create and destroy | - |
| 1806 | objects of that type dynamically at run-time. | - |
| 1807 | | - |
| 1808 | To use the type \c T in QVariant, using Q_DECLARE_METATYPE() is | - |
| 1809 | sufficient. To use the type \c T in queued signal and slot connections, | - |
| 1810 | \c{qRegisterMetaType<T>()} must be called before the first connection | - |
| 1811 | is established. | - |
| 1812 | | - |
| 1813 | Also, to use type \c T with the QObject::property() API, | - |
| 1814 | \c{qRegisterMetaType<T>()} must be called before it is used, typically | - |
| 1815 | in the constructor of the class that uses \c T, or in the \c{main()} | - |
| 1816 | function. | - |
| 1817 | | - |
| 1818 | \sa Q_DECLARE_METATYPE() | - |
| 1819 | */ | - |
| 1820 | | - |
| 1821 | /*! | - |
| 1822 | \fn int qMetaTypeId() | - |
| 1823 | \relates QMetaType | - |
| 1824 | \threadsafe | - |
| 1825 | \since 4.1 | - |
| 1826 | | - |
| 1827 | Returns the meta type id of type \c T at compile time. If the | - |
| 1828 | type was not declared with Q_DECLARE_METATYPE(), compilation will | - |
| 1829 | fail. | - |
| 1830 | | - |
| 1831 | Typical usage: | - |
| 1832 | | - |
| 1833 | \snippet code/src_corelib_kernel_qmetatype.cpp 8 | - |
| 1834 | | - |
| 1835 | QMetaType::type() returns the same ID as qMetaTypeId(), but does | - |
| 1836 | a lookup at runtime based on the name of the type. | - |
| 1837 | QMetaType::type() is a bit slower, but compilation succeeds if a | - |
| 1838 | type is not registered. | - |
| 1839 | | - |
| 1840 | \sa Q_DECLARE_METATYPE(), QMetaType::type() | - |
| 1841 | */ | - |
| 1842 | | - |
| 1843 | namespace { | - |
| 1844 | class TypeInfo { | - |
| 1845 | template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted> | - |
| 1846 | struct TypeInfoImpl | - |
| 1847 | { | - |
| 1848 | TypeInfoImpl(const uint /* type */, QMetaTypeInterface &info) | - |
| 1849 | { | - |
| 1850 | QMetaTypeInterface tmp = QT_METATYPE_INTERFACE_INIT_NO_DATASTREAM(T); | - |
| 1851 | info = tmp; | - |
| 1852 | } | - |
| 1853 | }; | - |
| 1854 | | - |
| 1855 | template<typename T> | - |
| 1856 | struct TypeInfoImpl<T, /* IsAcceptedType = */ false> | - |
| 1857 | { | - |
| 1858 | TypeInfoImpl(const uint type, QMetaTypeInterface &info) | - |
| 1859 | { | - |
| 1860 | if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) { | - |
| 1861 | if (Q_LIKELY(qMetaTypeGuiHelper)) | - |
| 1862 | info = qMetaTypeGuiHelper[type - QMetaType::FirstGuiType]; | - |
| 1863 | return; | - |
| 1864 | } | - |
| 1865 | if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) { | - |
| 1866 | if (Q_LIKELY(qMetaTypeWidgetsHelper)) | - |
| 1867 | info = qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType]; | - |
| 1868 | return; | - |
| 1869 | } | - |
| 1870 | } | - |
| 1871 | }; | - |
| 1872 | public: | - |
| 1873 | QMetaTypeInterface info; | - |
| 1874 | TypeInfo(const uint type) | - |
| 1875 | : m_type(type) | - |
| 1876 | { | - |
| 1877 | QMetaTypeInterface tmp = QT_METATYPE_INTERFACE_INIT_EMPTY(); | - |
| 1878 | info = tmp; | - |
| 1879 | } | - |
| 1880 | template<typename T> | - |
| 1881 | void delegate(const T*) { TypeInfoImpl<T>(m_type, info); } | - |
| 1882 | void delegate(const QMetaTypeSwitcher::UnknownType*) {} | - |
| 1883 | void delegate(const QMetaTypeSwitcher::NotBuiltinType*) { customTypeInfo(m_type); } | - |
| 1884 | private: | - |
| 1885 | void customTypeInfo(const uint type) | - |
| 1886 | { | - |
| 1887 | const QVector<QCustomTypeInfo> * const ct = customTypes(); | - |
| 1888 | if (Q_UNLIKELY(!ct)) | - |
| 1889 | return; | - |
| 1890 | QReadLocker locker(customTypesLock()); | - |
| 1891 | if (Q_LIKELY(uint(ct->count()) > type - QMetaType::User)) | - |
| 1892 | info = ct->at(type - QMetaType::User); | - |
| 1893 | } | - |
| 1894 | | - |
| 1895 | const uint m_type; | - |
| 1896 | }; | - |
| 1897 | } // namespace | - |
| 1898 | | - |
| 1899 | /*! | - |
| 1900 | \fn QMetaType QMetaType::typeInfo(const int type) | - |
| 1901 | \internal | - |
| 1902 | */ | - |
| 1903 | QMetaType QMetaType::typeInfo(const int type) | - |
| 1904 | { | - |
| 1905 | TypeInfo typeInfo(type); | - |
| 1906 | QMetaTypeSwitcher::switcher<void>(typeInfo, type, 0); | - |
| 1907 | return typeInfo.info.creator ? QMetaType(QMetaType::NoExtensionFlags | - |
| 1908 | , static_cast<const QMetaTypeInterface *>(0) // typeInfo::info is a temporary variable, we can't return address of it. | - |
| 1909 | , typeInfo.info.creator | - |
| 1910 | , typeInfo.info.deleter | - |
| 1911 | , typeInfo.info.saveOp | - |
| 1912 | , typeInfo.info.loadOp | - |
| 1913 | , typeInfo.info.constructor | - |
| 1914 | , typeInfo.info.destructor | - |
| 1915 | , typeInfo.info.size | - |
| 1916 | , typeInfo.info.flags | - |
| 1917 | , type | - |
| 1918 | , typeInfo.info.metaObject) | - |
| 1919 | : QMetaType(UnknownType); | - |
| 1920 | } | - |
| 1921 | | - |
| 1922 | /*! | - |
| 1923 | \fn QMetaType::QMetaType(const int typeId) | - |
| 1924 | \since 5.0 | - |
| 1925 | | - |
| 1926 | Constructs a QMetaType object that contains all information about type \a typeId. | - |
| 1927 | */ | - |
| 1928 | QMetaType::QMetaType(const int typeId) | - |
| 1929 | : m_typeId(typeId) | - |
| 1930 | { | - |
| 1931 | if (Q_UNLIKELY(typeId == UnknownType)) { | - |
| 1932 | // Constructs invalid QMetaType instance. | - |
| 1933 | m_extensionFlags = 0xffffffff; | - |
| 1934 | Q_ASSERT(!isValid()); | - |
| 1935 | } else { | - |
| 1936 | // TODO it can be better. | - |
| 1937 | *this = QMetaType::typeInfo(typeId); | - |
| 1938 | if (m_typeId == UnknownType) | - |
| 1939 | m_extensionFlags = 0xffffffff; | - |
| 1940 | else if (m_typeId == QMetaType::Void) | - |
| 1941 | m_extensionFlags = CreateEx | DestroyEx | ConstructEx | DestructEx; | - |
| 1942 | } | - |
| 1943 | } | - |
| 1944 | | - |
| 1945 | /*! | - |
| 1946 | \fn QMetaType::QMetaType(const QMetaType &other) | - |
| 1947 | \since 5.0 | - |
| 1948 | | - |
| 1949 | Copy constructs a QMetaType object. | - |
| 1950 | */ | - |
| 1951 | QMetaType::QMetaType(const QMetaType &other) | - |
| 1952 | : m_creator(other.m_creator) | - |
| 1953 | , m_deleter(other.m_deleter) | - |
| 1954 | , m_saveOp(other.m_saveOp) | - |
| 1955 | , m_loadOp(other.m_loadOp) | - |
| 1956 | , m_constructor(other.m_constructor) | - |
| 1957 | , m_destructor(other.m_destructor) | - |
| 1958 | , m_extension(other.m_extension) // space reserved for future use | - |
| 1959 | , m_size(other.m_size) | - |
| 1960 | , m_typeFlags(other.m_typeFlags) | - |
| 1961 | , m_extensionFlags(other.m_extensionFlags) | - |
| 1962 | , m_typeId(other.m_typeId) | - |
| 1963 | , m_metaObject(other.m_metaObject) | - |
| 1964 | {} | - |
| 1965 | | - |
| 1966 | QMetaType &QMetaType::operator =(const QMetaType &other) | - |
| 1967 | { | - |
| 1968 | m_creator = other.m_creator; | - |
| 1969 | m_deleter = other.m_deleter; | - |
| 1970 | m_saveOp = other.m_saveOp; | - |
| 1971 | m_loadOp = other.m_loadOp; | - |
| 1972 | m_constructor = other.m_constructor; | - |
| 1973 | m_destructor = other.m_destructor; | - |
| 1974 | m_size = other.m_size; | - |
| 1975 | m_typeFlags = other.m_typeFlags; | - |
| 1976 | m_extensionFlags = other.m_extensionFlags; | - |
| 1977 | m_extension = other.m_extension; // space reserved for future use | - |
| 1978 | m_typeId = other.m_typeId; | - |
| 1979 | m_metaObject = other.m_metaObject; | - |
| 1980 | return *this; | - |
| 1981 | } | - |
| 1982 | | - |
| 1983 | /*! | - |
| 1984 | \fn void QMetaType::ctor(const QMetaTypeInterface *info) | - |
| 1985 | \internal | - |
| 1986 | | - |
| 1987 | Method used for future binary compatible extensions. The function may be | - |
| 1988 | called from within QMetaType's constructor to force a library call from | - |
| 1989 | inlined code. | - |
| 1990 | */ | - |
| 1991 | void QMetaType::ctor(const QMetaTypeInterface *info) | - |
| 1992 | { | - |
| 1993 | // Special case for Void type, the type is valid but not constructible. | - |
| 1994 | // In future we may consider to remove this assert and extend this function to initialize | - |
| 1995 | // differently m_extensionFlags for different types. Currently it is not needed. | - |
| 1996 | Q_ASSERT(m_typeId == QMetaType::Void); | - |
| 1997 | Q_UNUSED(info); | - |
| 1998 | m_extensionFlags = CreateEx | DestroyEx | ConstructEx | DestructEx; | - |
| 1999 | } | - |
| 2000 | | - |
| 2001 | /*! | - |
| 2002 | \fn void QMetaType::dtor() | - |
| 2003 | \internal | - |
| 2004 | | - |
| 2005 | Method used for future binary compatible extensions. The function may be | - |
| 2006 | called from within QMetaType's destructor to force a library call from | - |
| 2007 | inlined code. | - |
| 2008 | */ | - |
| 2009 | void QMetaType::dtor() | - |
| 2010 | {} | - |
| 2011 | | - |
| 2012 | /*! | - |
| 2013 | \fn void *QMetaType::createExtended(const void *copy) const | - |
| 2014 | \internal | - |
| 2015 | | - |
| 2016 | Method used for future binary compatible extensions. The function may be called | - |
| 2017 | during QMetaType::create to force library call from inlined code. | - |
| 2018 | */ | - |
| 2019 | void *QMetaType::createExtended(const void *copy) const | - |
| 2020 | { | - |
| 2021 | Q_UNUSED(copy); | - |
| 2022 | return 0; | - |
| 2023 | } | - |
| 2024 | | - |
| 2025 | /*! | - |
| 2026 | \fn void QMetaType::destroyExtended(void *data) const | - |
| 2027 | \internal | - |
| 2028 | | - |
| 2029 | Method used for future binary compatible extensions. The function may be called | - |
| 2030 | during QMetaType::destroy to force library call from inlined code. | - |
| 2031 | */ | - |
| 2032 | void QMetaType::destroyExtended(void *data) const | - |
| 2033 | { | - |
| 2034 | Q_UNUSED(data); | - |
| 2035 | } | - |
| 2036 | | - |
| 2037 | /*! | - |
| 2038 | \fn void *QMetaType::constructExtended(void *where, const void *copy) const | - |
| 2039 | \internal | - |
| 2040 | | - |
| 2041 | Method used for future binary compatible extensions. The function may be called | - |
| 2042 | during QMetaType::construct to force library call from inlined code. | - |
| 2043 | */ | - |
| 2044 | void *QMetaType::constructExtended(void *where, const void *copy) const | - |
| 2045 | { | - |
| 2046 | Q_UNUSED(where); | - |
| 2047 | Q_UNUSED(copy); | - |
| 2048 | return 0; | - |
| 2049 | } | - |
| 2050 | | - |
| 2051 | /*! | - |
| 2052 | \fn void QMetaType::destructExtended(void *data) const | - |
| 2053 | \internal | - |
| 2054 | | - |
| 2055 | Method used for future binary compatible extensions. The function may be called | - |
| 2056 | during QMetaType::destruct to force library call from inlined code. | - |
| 2057 | */ | - |
| 2058 | void QMetaType::destructExtended(void *data) const | - |
| 2059 | { | - |
| 2060 | Q_UNUSED(data); | - |
| 2061 | } | - |
| 2062 | | - |
| 2063 | /*! | - |
| 2064 | \fn uint QMetaType::sizeExtended() const | - |
| 2065 | \internal | - |
| 2066 | | - |
| 2067 | Method used for future binary compatible extensions. The function may be | - |
| 2068 | called from within QMetaType::size to force a library call from | - |
| 2069 | inlined code. | - |
| 2070 | */ | - |
| 2071 | uint QMetaType::sizeExtended() const | - |
| 2072 | { | - |
| 2073 | return 0; | - |
| 2074 | } | - |
| 2075 | | - |
| 2076 | /*! | - |
| 2077 | \fn QMetaType::TypeFlags QMetaType::flagsExtended() const | - |
| 2078 | \internal | - |
| 2079 | | - |
| 2080 | Method used for future binary compatible extensions. The function may be | - |
| 2081 | called from within QMetaType::flags to force a library call from | - |
| 2082 | inlined code. | - |
| 2083 | */ | - |
| 2084 | QMetaType::TypeFlags QMetaType::flagsExtended() const | - |
| 2085 | { | - |
| 2086 | return 0; | - |
| 2087 | } | - |
| 2088 | | - |
| 2089 | /*! | - |
| 2090 | \brief QMetaType::metaObjectExtended | - |
| 2091 | \internal | - |
| 2092 | | - |
| 2093 | Method used for future binary compatible extensions. The function may be | - |
| 2094 | called from within QMetaType::metaObject to force a library call from | - |
| 2095 | inlined code. | - |
| 2096 | */ | - |
| 2097 | const QMetaObject *QMetaType::metaObjectExtended() const | - |
| 2098 | { | - |
| 2099 | return 0; | - |
| 2100 | } | - |
| 2101 | | - |
| 2102 | | - |
| 2103 | namespace QtPrivate | - |
| 2104 | { | - |
| 2105 | const QMetaObject *metaObjectForQWidget() | - |
| 2106 | { | - |
| 2107 | if (!qMetaTypeWidgetsHelper) | - |
| 2108 | return 0; | - |
| 2109 | return qMetaObjectWidgetsHelper; | - |
| 2110 | } | - |
| 2111 | } | - |
| 2112 | | - |
| 2113 | QT_END_NAMESPACE | - |
| 2114 | | - |
| | |