Simplify QMetaTypeSwitcher.

We do not need to distinguish between different types in the switcher.

Before this patch it was not possible to overload
DelegateObject::delegate with a pointer type. Now it is fixed.

Change-Id: Icd73a53e73e5e66b1b6f6407ba4e0f79e584d930
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Jędrzej Nowacki 2012-02-24 14:27:01 +01:00 committed by Qt by Nokia
parent 184c9e346e
commit 6df396286a
2 changed files with 8 additions and 26 deletions

View File

@ -59,46 +59,27 @@ QT_BEGIN_NAMESPACE
class QMetaTypeSwitcher { class QMetaTypeSwitcher {
public: public:
class NotBuiltinType;
typedef void *NotBuiltinType;
template<class ReturnType, class DelegateObject> template<class ReturnType, class DelegateObject>
static ReturnType switcher(DelegateObject &logic, int type, const void *data); static ReturnType switcher(DelegateObject &logic, int type, const void *data);
}; };
#define QT_METATYPE_SWICHER_CASE_PRIMITIVE(TypeName, TypeId, Name)\ #define QT_METATYPE_SWICHER_CASE(TypeName, TypeId, Name)\
case QMetaType::TypeName: return logic.delegate(static_cast<const Name *>(data)); case QMetaType::TypeName: return logic.delegate(static_cast<Name const *>(data));
#define QT_METATYPE_SWICHER_CASE_PRIMITIVE_POINTER(TypeName, TypeId, Name)\
case QMetaType::TypeName: return logic.delegate(static_cast< Name * const *>(data));
#define QT_METATYPE_SWICHER_CASE_POINTER(TypeName, TypeId, Name)\
case QMetaType::TypeName: return logic.delegate(static_cast< QT_PREPEND_NAMESPACE(Name) * const *>(data));
#define QT_METATYPE_SWICHER_CASE_QCLASS(TypeName, TypeId, Name)\
case QMetaType::TypeName: return logic.delegate(static_cast<const QT_PREPEND_NAMESPACE(Name) *>(data));
template<class ReturnType, class DelegateObject> template<class ReturnType, class DelegateObject>
ReturnType QMetaTypeSwitcher::switcher(DelegateObject &logic, int type, const void *data) ReturnType QMetaTypeSwitcher::switcher(DelegateObject &logic, int type, const void *data)
{ {
switch (QMetaType::Type(type)) { switch (QMetaType::Type(type)) {
QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(QT_METATYPE_SWICHER_CASE_PRIMITIVE) QT_FOR_EACH_STATIC_TYPE(QT_METATYPE_SWICHER_CASE)
QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(QT_METATYPE_SWICHER_CASE_PRIMITIVE_POINTER)
QT_FOR_EACH_STATIC_CORE_POINTER(QT_METATYPE_SWICHER_CASE_POINTER)
QT_FOR_EACH_STATIC_CORE_CLASS(QT_METATYPE_SWICHER_CASE_QCLASS)
QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_METATYPE_SWICHER_CASE_QCLASS)
QT_FOR_EACH_STATIC_GUI_CLASS(QT_METATYPE_SWICHER_CASE_QCLASS)
QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_METATYPE_SWICHER_CASE_QCLASS)
default: default:
return logic.delegate(static_cast<const NotBuiltinType *>(data)); return logic.delegate(static_cast<NotBuiltinType const *>(data));
} }
} }
#undef QT_METATYPE_SWICHER_CASE_PRIMITIVE #undef QT_METATYPE_SWICHER_CASE
#undef QT_METATYPE_SWICHER_CASE_PRIMITIVE_POINTER
#undef QT_METATYPE_SWICHER_CASE_QCLASS
#undef QT_METATYPE_SWICHER_CASE_POINTER
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -188,7 +188,7 @@ public:
} }
bool delegate(const void*) { return true; } bool delegate(const void*) { return true; }
bool delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return false; }
protected: protected:
const QVariant::Private *m_a; const QVariant::Private *m_a;
const QVariant::Private *m_b; const QVariant::Private *m_b;
@ -282,6 +282,7 @@ public:
} }
// we need that as sizof(void) is undefined and it is needed in HasIsNullMethod // we need that as sizof(void) is undefined and it is needed in HasIsNullMethod
bool delegate(const void *) { return m_d->is_null; } bool delegate(const void *) { return m_d->is_null; }
bool delegate(const QMetaTypeSwitcher::NotBuiltinType *) { return m_d->is_null; }
protected: protected:
const QVariant::Private *m_d; const QVariant::Private *m_d;
}; };