Make QMetaTypeInterface POD.

QMetaTypeInterface has to be POD because it is constructed in a static
array. Constructors in POD types are not allowed so we will use a macro
instead.

Change-Id: Iab9ae776dfe4dcd7148558f02d6181c5917aa5c3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Jędrzej Nowacki 2011-12-13 16:12:32 +01:00 committed by Qt by Nokia
parent e75e4421cd
commit 31d8ecfe3b
4 changed files with 33 additions and 28 deletions

View File

@ -297,6 +297,14 @@ public:
int alias;
};
namespace
{
union CheckThatItIsPod
{ // This should break if QMetaTypeInterface is not a POD type
QMetaTypeInterface iface;
};
}
Q_DECLARE_TYPEINFO(QCustomTypeInfo, Q_MOVABLE_TYPE);
Q_GLOBAL_STATIC(QVector<QCustomTypeInfo>, customTypes)
Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
@ -454,6 +462,10 @@ int QMetaType::registerType(const char *typeName, Deleter deleter,
inf.typeName = normalizedTypeName;
inf.creator = creator;
inf.deleter = deleter;
#ifndef QT_NO_DATASTREAM
inf.loadOp = 0;
inf.saveOp = 0;
#endif
inf.alias = -1;
inf.constructor = constructor;
inf.destructor = destructor;

View File

@ -113,7 +113,7 @@ QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_DECLARE_WIDGETS_MODULE_TYPES_ITER)
class QMetaTypeInterface
{
private:
public:
template<typename T>
struct Impl {
static void *creator(const T *t)
@ -140,31 +140,6 @@ private:
return new (where) T;
}
};
public:
template<typename T>
explicit QMetaTypeInterface(T *)
: creator(reinterpret_cast<QMetaType::Creator>(Impl<T>::creator))
, deleter(reinterpret_cast<QMetaType::Deleter>(Impl<T>::deleter))
#ifndef QT_NO_DATASTREAM
, saveOp(reinterpret_cast<QMetaType::SaveOperator>(Impl<T>::saver))
, loadOp(reinterpret_cast<QMetaType::LoadOperator>(Impl<T>::loader))
#endif
, constructor(reinterpret_cast<QMetaType::Constructor>(Impl<T>::constructor))
, destructor(reinterpret_cast<QMetaType::Destructor>(Impl<T>::destructor))
, size(sizeof(T))
{}
QMetaTypeInterface()
: creator(0)
, deleter(0)
#ifndef QT_NO_DATASTREAM
, saveOp(0)
, loadOp(0)
#endif
, constructor(0)
, destructor(0)
, size(0)
{}
QMetaType::Creator creator;
QMetaType::Deleter deleter;
@ -177,6 +152,24 @@ public:
int size;
};
#ifndef QT_NO_DATASTREAM
# define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
/*saveOp*/(reinterpret_cast<QMetaType::SaveOperator>(QMetaTypeInterface::Impl<Type>::saver)), \
/*loadOp*/(reinterpret_cast<QMetaType::LoadOperator>(QMetaTypeInterface::Impl<Type>::loader)),
#else
# define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type)
#endif
#define QT_METATYPE_INTERFACE_INIT(Type) \
{ \
/*creator*/(reinterpret_cast<QMetaType::Creator>(QMetaTypeInterface::Impl<Type>::creator)), \
/*deleter*/(reinterpret_cast<QMetaType::Deleter>(QMetaTypeInterface::Impl<Type>::deleter)), \
QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
/*constructor*/(reinterpret_cast<QMetaType::Constructor>(QMetaTypeInterface::Impl<Type>::constructor)), \
/*destructor*/(reinterpret_cast<QMetaType::Destructor>(QMetaTypeInterface::Impl<Type>::destructor)), \
/*size*/(sizeof(Type)) \
}
QT_END_NAMESPACE
#endif // QMETATYPE_P_H

View File

@ -477,7 +477,7 @@ const QVariant::Handler qt_gui_variant_handler = {
extern Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeGuiHelper;
#define QT_IMPL_METATYPEINTERFACE_GUI_TYPES(MetaTypeName, MetaTypeId, RealName) \
QMetaTypeInterface(static_cast<RealName*>(0)),
QT_METATYPE_INTERFACE_INIT(RealName),
static const QMetaTypeInterface qVariantGuiHelper[] = {
QT_FOR_EACH_STATIC_GUI_CLASS(QT_IMPL_METATYPEINTERFACE_GUI_TYPES)

View File

@ -141,7 +141,7 @@ static const QVariant::Handler widgets_handler = {
extern Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeWidgetsHelper;
#define QT_IMPL_METATYPEINTERFACE_WIDGETS_TYPES(MetaTypeName, MetaTypeId, RealName) \
QMetaTypeInterface(static_cast<RealName*>(0)),
QT_METATYPE_INTERFACE_INIT(RealName),
static const QMetaTypeInterface qVariantWidgetsHelper[] = {
QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_IMPL_METATYPEINTERFACE_WIDGETS_TYPES)