create() is symmetric with destroy().
Also rename the internal methods and fields to be
consistent (qDeleteHelper already had the "right"
name, though!).
This change will allow us to use construct() and
destruct() for something else: Placement new-style
allocation (QTBUG-12574).
The old construct() is still kept for now, until
the other repositories have been updated to use
create().
Change-Id: Iceb184af6cffcb0a634359cfc3516c718ba0c2f5
Reviewed-on: http://codereview.qt-project.org/6342
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
- Qt::escape() is deprecated (but can be enabled via
QT_DISABLE_DEPRECATED_BEFORE), use QString::toHtmlEscaped() instead.
+- QMetaType::construct() has been renamed to QMetaType::create().
+
****************************************************************************
* General *
****************************************************************************
//! [3]
int id = QMetaType::type("MyClass");
if (id == 0) {
- void *myClassPtr = QMetaType::construct(id);
+ void *myClassPtr = QMetaType::create(id);
...
QMetaType::destroy(id, myClassPtr);
myClassPtr = 0;
for (int i = 1; i < paramCount; ++i) {
types[i] = QMetaType::type(typeNames[i]);
if (types[i]) {
- args[i] = QMetaType::construct(types[i], param[i]);
+ args[i] = QMetaType::create(types[i], param[i]);
++nargs;
} else if (param[i]) {
qWarning("QMetaMethod::invoke: Unable to handle unregistered datatype '%s'",
struct QMetaTypeGuiHelper
{
- QMetaType::Constructor constr;
- QMetaType::Destructor destr;
+ QMetaType::Creator creator;
+ QMetaType::Deleter deleter;
#ifndef QT_NO_DATASTREAM
QMetaType::SaveOperator saveOp;
QMetaType::LoadOperator loadOp;
class QCustomTypeInfo
{
public:
- QCustomTypeInfo() : typeName(), constr(0), destr(0)
+ QCustomTypeInfo() : typeName(), creator(0), deleter(0)
#ifndef QT_NO_DATASTREAM
, saveOp(0), loadOp(0)
#endif
{}
QByteArray typeName;
- QMetaType::Constructor constr;
- QMetaType::Destructor destr;
+ QMetaType::Creator creator;
+ QMetaType::Deleter deleter;
#ifndef QT_NO_DATASTREAM
QMetaType::SaveOperator saveOp;
QMetaType::LoadOperator loadOp;
destructor, and a \a constructor. Returns the type's handle,
or -1 if the type could not be registered.
*/
-int QMetaType::registerType(const char *typeName, Destructor destructor,
- Constructor constructor)
+int QMetaType::registerType(const char *typeName, Deleter deleter,
+ Creator creator)
{
QVector<QCustomTypeInfo> *ct = customTypes();
- if (!ct || !typeName || !destructor || !constructor)
+ if (!ct || !typeName || !deleter || !creator)
return -1;
#ifdef QT_NO_QOBJECT
if (!idx) {
QCustomTypeInfo inf;
inf.typeName = normalizedTypeName;
- inf.constr = constructor;
- inf.destr = destructor;
+ inf.creator = creator;
+ inf.deleter = deleter;
inf.alias = -1;
idx = ct->size() + User;
ct->append(inf);
QCustomTypeInfo inf;
inf.typeName = normalizedTypeName;
inf.alias = aliasId;
- inf.constr = 0;
- inf.destr = 0;
+ inf.creator = 0;
+ inf.deleter = 0;
ct->append(inf);
return aliasId;
}
if (ct->at(v).typeName == typeName) {
QCustomTypeInfo &inf = (*ct)[v];
inf.typeName.clear();
- inf.constr = 0;
- inf.destr = 0;
+ inf.creator = 0;
+ inf.deleter = 0;
inf.alias = -1;
}
}
\sa destroy(), isRegistered(), Type
*/
-void *QMetaType::construct(int type, const void *copy)
+void *QMetaType::create(int type, const void *copy)
{
if (copy) {
switch(type) {
}
}
- Constructor constr = 0;
+ Creator creator = 0;
if (type >= FirstGuiType && type <= LastGuiType) {
if (!qMetaTypeGuiHelper)
return 0;
- constr = qMetaTypeGuiHelper[type - FirstGuiType].constr;
+ creator = qMetaTypeGuiHelper[type - FirstGuiType].creator;
} else if (type >= FirstWidgetsType && type <= LastWidgetsType) {
if (!qMetaTypeWidgetsHelper)
return 0;
- constr = qMetaTypeWidgetsHelper[type - FirstWidgetsType].constr;
+ creator = qMetaTypeWidgetsHelper[type - FirstWidgetsType].creator;
} else {
const QVector<QCustomTypeInfo> * const ct = customTypes();
QReadLocker locker(customTypesLock());
return 0;
if (ct->at(type - User).typeName.isEmpty())
return 0;
- constr = ct->at(type - User).constr;
+ creator = ct->at(type - User).creator;
}
- return constr(copy);
+ return creator(copy);
}
/*!
Destroys the \a data, assuming it is of the \a type given.
- \sa construct(), isRegistered(), Type
+ \sa create(), isRegistered(), Type
*/
void QMetaType::destroy(int type, void *data)
{
break;
default: {
const QVector<QCustomTypeInfo> * const ct = customTypes();
- Destructor destr = 0;
+ Deleter deleter = 0;
if (type >= FirstGuiType && type <= LastGuiType) {
Q_ASSERT(qMetaTypeGuiHelper);
if (!qMetaTypeGuiHelper)
return;
- destr = qMetaTypeGuiHelper[type - FirstGuiType].destr;
+ deleter = qMetaTypeGuiHelper[type - FirstGuiType].deleter;
} else if (type >= FirstWidgetsType && type <= LastWidgetsType) {
Q_ASSERT(qMetaTypeWidgetsHelper);
if (!qMetaTypeWidgetsHelper)
return;
- destr = qMetaTypeWidgetsHelper[type - FirstWidgetsType].destr;
+ deleter = qMetaTypeWidgetsHelper[type - FirstWidgetsType].deleter;
} else {
QReadLocker locker(customTypesLock());
if (type < User || !ct || ct->count() <= type - User)
break;
if (ct->at(type - User).typeName.isEmpty())
break;
- destr = ct->at(type - User).destr;
+ deleter = ct->at(type - User).deleter;
}
- destr(data);
+ deleter(data);
break; }
}
}
\sa qRegisterMetaType(), QMetaType::isRegistered(), Q_DECLARE_METATYPE()
*/
-/*! \typedef QMetaType::Destructor
+/*! \typedef QMetaType::Deleter
\internal
*/
-/*! \typedef QMetaType::Constructor
+/*! \typedef QMetaType::Creator
\internal
*/
/*! \typedef QMetaType::SaveOperator
User = 256
};
- typedef void (*Destructor)(void *);
- typedef void *(*Constructor)(const void *);
+ typedef void (*Deleter)(void *);
+ typedef void *(*Creator)(const void *);
#ifndef QT_NO_DATASTREAM
typedef void (*SaveOperator)(QDataStream &, const void *);
static void registerStreamOperators(int type, SaveOperator saveOp,
LoadOperator loadOp);
#endif
- static int registerType(const char *typeName, Destructor destructor,
- Constructor constructor);
+ static int registerType(const char *typeName, Deleter deleter,
+ Creator creator);
static int registerTypedef(const char *typeName, int aliasId);
static int type(const char *typeName);
static const char *typeName(int type);
static bool isRegistered(int type);
- static void *construct(int type, const void *copy = 0);
+ static void *create(int type, const void *copy = 0);
+#ifdef QT_DEPRECATED
+ QT_DEPRECATED static void *construct(int type, const void *copy = 0)
+ { return create(type, copy); }
+#endif
static void destroy(int type, void *data);
static void unregisterType(const char *typeName);
}
template <typename T>
-void *qMetaTypeConstructHelper(const T *t)
+void *qMetaTypeCreateHelper(const T *t)
{
if (!t)
return new T();
if (typedefOf != -1)
return QMetaType::registerTypedef(typeName, typedefOf);
- typedef void*(*ConstructPtr)(const T*);
- ConstructPtr cptr = qMetaTypeConstructHelper<T>;
+ typedef void*(*CreatePtr)(const T*);
+ CreatePtr cptr = qMetaTypeCreateHelper<T>;
typedef void(*DeletePtr)(T*);
DeletePtr dptr = qMetaTypeDeleteHelper<T>;
- return QMetaType::registerType(typeName, reinterpret_cast<QMetaType::Destructor>(dptr),
- reinterpret_cast<QMetaType::Constructor>(cptr));
+ return QMetaType::registerType(typeName, reinterpret_cast<QMetaType::Deleter>(dptr),
+ reinterpret_cast<QMetaType::Creator>(cptr));
}
#ifndef QT_NO_DATASTREAM
types[0] = 0; // return type
args[0] = 0; // return value
for (int n = 1; n < nargs; ++n)
- args[n] = QMetaType::construct((types[n] = c->argumentTypes[n-1]), argv[n]);
+ args[n] = QMetaType::create((types[n] = c->argumentTypes[n-1]), argv[n]);
QCoreApplication::postEvent(c->receiver, new QMetaCallEvent(c->method_offset,
c->method_relative,
c->callFunction,
case QVariant::UserType:
break;
default:
- void *ptr = QMetaType::construct(x->type, copy);
+ void *ptr = QMetaType::create(x->type, copy);
if (!ptr) {
x->type = QVariant::Invalid;
} else {
struct QMetaTypeGuiHelper
{
- QMetaType::Constructor constr;
- QMetaType::Destructor destr;
+ QMetaType::Creator creator;
+ QMetaType::Deleter deleter;
#ifndef QT_NO_DATASTREAM
QMetaType::SaveOperator saveOp;
QMetaType::LoadOperator loadOp;
#ifdef QT_NO_DATASTREAM
# define Q_DECL_METATYPE_HELPER(TYPE) \
- typedef void *(*QConstruct##TYPE)(const TYPE *); \
- static const QConstruct##TYPE qConstruct##TYPE = qMetaTypeConstructHelper<TYPE>; \
- typedef void (*QDestruct##TYPE)(TYPE *); \
- static const QDestruct##TYPE qDestruct##TYPE = qMetaTypeDeleteHelper<TYPE>;
+ typedef void *(*QCreate##TYPE)(const TYPE *); \
+ static const QCreate##TYPE qCreate##TYPE = qMetaTypeCreateHelper<TYPE>; \
+ typedef void (*QDelete##TYPE)(TYPE *); \
+ static const QDelete##TYPE qDelete##TYPE = qMetaTypeDeleteHelper<TYPE>;
#else
# define Q_DECL_METATYPE_HELPER(TYPE) \
- typedef void *(*QConstruct##TYPE)(const TYPE *); \
- static const QConstruct##TYPE qConstruct##TYPE = qMetaTypeConstructHelper<TYPE>; \
- typedef void (*QDestruct##TYPE)(TYPE *); \
- static const QDestruct##TYPE qDestruct##TYPE = qMetaTypeDeleteHelper<TYPE>; \
+ typedef void *(*QCreate##TYPE)(const TYPE *); \
+ static const QCreate##TYPE qCreate##TYPE = qMetaTypeCreateHelper<TYPE>; \
+ typedef void (*QDelete##TYPE)(TYPE *); \
+ static const QDelete##TYPE qDelete##TYPE = qMetaTypeDeleteHelper<TYPE>; \
typedef void (*QSave##TYPE)(QDataStream &, const TYPE *); \
static const QSave##TYPE qSave##TYPE = qMetaTypeSaveHelper<TYPE>; \
typedef void (*QLoad##TYPE)(QDataStream &, TYPE *); \
#ifdef QT_NO_DATASTREAM
# define Q_IMPL_METATYPE_HELPER(TYPE) \
- { reinterpret_cast<QMetaType::Constructor>(qConstruct##TYPE), \
- reinterpret_cast<QMetaType::Destructor>(qDestruct##TYPE) }
+ { reinterpret_cast<QMetaType::Creator>(qCreate##TYPE), \
+ reinterpret_cast<QMetaType::Deleter>(qDelete##TYPE) }
#else
# define Q_IMPL_METATYPE_HELPER(TYPE) \
- { reinterpret_cast<QMetaType::Constructor>(qConstruct##TYPE), \
- reinterpret_cast<QMetaType::Destructor>(qDestruct##TYPE), \
+ { reinterpret_cast<QMetaType::Creator>(qCreate##TYPE), \
+ reinterpret_cast<QMetaType::Deleter>(qDelete##TYPE), \
reinterpret_cast<QMetaType::SaveOperator>(qSave##TYPE), \
reinterpret_cast<QMetaType::LoadOperator>(qLoad##TYPE) \
}
d->dataCount, d->tag);
QTEST_ASSERT(false);
}
- d->data[d->dataCount] = QMetaType::construct(type, data);
+ d->data[d->dataCount] = QMetaType::create(type, data);
++d->dataCount;
}
struct QMetaTypeGuiHelper
{
- QMetaType::Constructor constr;
- QMetaType::Destructor destr;
+ QMetaType::Creator creator;
+ QMetaType::Deleter deleter;
#ifndef QT_NO_DATASTREAM
QMetaType::SaveOperator saveOp;
QMetaType::LoadOperator loadOp;
#ifdef QT_NO_DATASTREAM
# define Q_DECL_METATYPE_HELPER(TYPE) \
- typedef void *(*QConstruct##TYPE)(const TYPE *); \
- static const QConstruct##TYPE qConstruct##TYPE = qMetaTypeConstructHelper<TYPE>; \
- typedef void (*QDestruct##TYPE)(TYPE *); \
- static const QDestruct##TYPE qDestruct##TYPE = qMetaTypeDeleteHelper<TYPE>;
+ typedef void *(*QCreate##TYPE)(const TYPE *); \
+ static const QCreate##TYPE qCreate##TYPE = qMetaTypeCreateHelper<TYPE>; \
+ typedef void (*QDelete##TYPE)(TYPE *); \
+ static const QDelete##TYPE qDelete##TYPE = qMetaTypeDeleteHelper<TYPE>;
#else
# define Q_DECL_METATYPE_HELPER(TYPE) \
- typedef void *(*QConstruct##TYPE)(const TYPE *); \
- static const QConstruct##TYPE qConstruct##TYPE = qMetaTypeConstructHelper<TYPE>; \
- typedef void (*QDestruct##TYPE)(TYPE *); \
- static const QDestruct##TYPE qDestruct##TYPE = qMetaTypeDeleteHelper<TYPE>; \
+ typedef void *(*QCreate##TYPE)(const TYPE *); \
+ static const QCreate##TYPE qCreate##TYPE = qMetaTypeCreateHelper<TYPE>; \
+ typedef void (*QDelete##TYPE)(TYPE *); \
+ static const QDelete##TYPE qDelete##TYPE = qMetaTypeDeleteHelper<TYPE>; \
typedef void (*QSave##TYPE)(QDataStream &, const TYPE *); \
static const QSave##TYPE qSave##TYPE = qMetaTypeSaveHelper<TYPE>; \
typedef void (*QLoad##TYPE)(QDataStream &, TYPE *); \
#ifdef QT_NO_DATASTREAM
# define Q_IMPL_METATYPE_HELPER(TYPE) \
- { reinterpret_cast<QMetaType::Constructor>(qConstruct##TYPE), \
- reinterpret_cast<QMetaType::Destructor>(qDestruct##TYPE) }
+ { reinterpret_cast<QMetaType::Creator>(qCreate##TYPE), \
+ reinterpret_cast<QMetaType::Deleter>(qDelete##TYPE) }
#else
# define Q_IMPL_METATYPE_HELPER(TYPE) \
- { reinterpret_cast<QMetaType::Constructor>(qConstruct##TYPE), \
- reinterpret_cast<QMetaType::Destructor>(qDestruct##TYPE), \
+ { reinterpret_cast<QMetaType::Creator>(qCreate##TYPE), \
+ reinterpret_cast<QMetaType::Deleter>(qDelete##TYPE), \
reinterpret_cast<QMetaType::SaveOperator>(qSave##TYPE), \
reinterpret_cast<QMetaType::LoadOperator>(qLoad##TYPE) \
}
void normalizedTypes();
void typeName_data();
void typeName();
- void construct();
+ void create();
void typedefs();
void isRegistered_data();
void isRegistered();
++failureCount;
qWarning() << "Wrong typeName returned for" << tp;
}
- void *buf = QMetaType::construct(tp, 0);
- void *buf2 = QMetaType::construct(tp, buf);
+ void *buf = QMetaType::create(tp, 0);
+ void *buf2 = QMetaType::create(tp, buf);
if (!buf) {
++failureCount;
- qWarning() << "Null buffer returned by QMetaType::construct(tp, 0)";
+ qWarning() << "Null buffer returned by QMetaType::create(tp, 0)";
}
if (!buf2) {
++failureCount;
- qWarning() << "Null buffer returned by QMetaType::construct(tp, buf)";
+ qWarning() << "Null buffer returned by QMetaType::create(tp, buf)";
}
QMetaType::destroy(tp, buf);
QMetaType::destroy(tp, buf2);
QCOMPARE(QString::fromLatin1(QMetaType::typeName(aType)), aTypeName);
}
-void tst_QMetaType::construct()
+void tst_QMetaType::create()
{
QSize x(1, 1);
- void *size = QMetaType::construct(QMetaType::QSize, &x);
+ void *size = QMetaType::create(QMetaType::QSize, &x);
QVERIFY(size);
QCOMPARE(static_cast<QSize *>(size)->width(), 1);
QMetaType::destroy(QMetaType::QSize, size);
qVariantSetValue(variant, QMatrix().rotate(90));
QCOMPARE(QMatrix().rotate(90), qVariantValue<QMatrix>(variant));
- void *mmatrix = QMetaType::construct(QVariant::Matrix, 0);
+ void *mmatrix = QMetaType::create(QVariant::Matrix, 0);
QVERIFY(mmatrix);
QMetaType::destroy(QVariant::Matrix, mmatrix);
}
qVariantSetValue(variant, m);
QCOMPARE(m, qVariantValue<QMatrix4x4>(variant));
- void *mmatrix = QMetaType::construct(QVariant::Matrix4x4, 0);
+ void *mmatrix = QMetaType::create(QVariant::Matrix4x4, 0);
QVERIFY(mmatrix);
QMetaType::destroy(QVariant::Matrix4x4, mmatrix);
}
qVariantSetValue(variant, QTransform().rotate(90));
QCOMPARE(QTransform().rotate(90), qVariantValue<QTransform>(variant));
- void *mmatrix = QMetaType::construct(QVariant::Transform, 0);
+ void *mmatrix = QMetaType::create(QVariant::Transform, 0);
QVERIFY(mmatrix);
QMetaType::destroy(QVariant::Transform, mmatrix);
}
qVariantSetValue(variant, QVector2D(0.1, 0.2));
QCOMPARE(QVector2D(0.1, 0.2), qVariantValue<QVector2D>(variant));
- void *pvector = QMetaType::construct(QVariant::Vector2D, 0);
+ void *pvector = QMetaType::create(QVariant::Vector2D, 0);
QVERIFY(pvector);
QMetaType::destroy(QVariant::Vector2D, pvector);
}
qVariantSetValue(variant, QVector3D(0.1, 0.2, 0.3));
QCOMPARE(QVector3D(0.1, 0.2, 0.3), qVariantValue<QVector3D>(variant));
- void *pvector = QMetaType::construct(QVariant::Vector3D, 0);
+ void *pvector = QMetaType::create(QVariant::Vector3D, 0);
QVERIFY(pvector);
QMetaType::destroy(QVariant::Vector3D, pvector);
}
qVariantSetValue(variant, QVector4D(0.1, 0.2, 0.3, 0.4));
QCOMPARE(QVector4D(0.1, 0.2, 0.3, 0.4), qVariantValue<QVector4D>(variant));
- void *pvector = QMetaType::construct(QVariant::Vector4D, 0);
+ void *pvector = QMetaType::create(QVariant::Vector4D, 0);
QVERIFY(pvector);
QMetaType::destroy(QVariant::Vector4D, pvector);
}
qVariantSetValue(variant, QQuaternion(0.1, 0.2, 0.3, 0.4));
QCOMPARE(QQuaternion(0.1, 0.2, 0.3, 0.4), qVariantValue<QQuaternion>(variant));
- void *pquaternion = QMetaType::construct(QVariant::Quaternion, 0);
+ void *pquaternion = QMetaType::create(QVariant::Quaternion, 0);
QVERIFY(pquaternion);
QMetaType::destroy(QVariant::Quaternion, pquaternion);
}
QFETCH(int, typeId);
QBENCHMARK {
for (int i = 0; i < 100000; ++i) {
- void *data = QMetaType::construct(typeId, (void *)0);
+ void *data = QMetaType::create(typeId, (void *)0);
QMetaType::destroy(typeId, data);
}
}
const void *copy = other.constData();
QBENCHMARK {
for (int i = 0; i < 100000; ++i) {
- void *data = QMetaType::construct(typeId, copy);
+ void *data = QMetaType::create(typeId, copy);
QMetaType::destroy(typeId, data);
}
}
QFETCH(int, typeId);
QBENCHMARK {
for (int i = 0; i < 100000; ++i) {
- void *data = QMetaType::construct(typeId, (void *)0);
+ void *data = QMetaType::create(typeId, (void *)0);
QMetaType::destroy(typeId, data);
}
}
const void *copy = other.constData();
QBENCHMARK {
for (int i = 0; i < 100000; ++i) {
- void *data = QMetaType::construct(typeId, copy);
+ void *data = QMetaType::create(typeId, copy);
QMetaType::destroy(typeId, data);
}
}