From 737161bbec97e738d0e91cc86bd4e4033be07b97 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 13 Jan 2010 12:31:12 +0100 Subject: Add an overload of qRegisterMetaTypeStreamOperators without the type name Reviewed-by: Bradley T. Hughes --- src/corelib/kernel/qmetatype.cpp | 7 +++++++ src/corelib/kernel/qmetatype.h | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index b1ce608..ac15e49 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -361,7 +361,14 @@ void QMetaType::registerStreamOperators(const char *typeName, SaveOperator saveO int idx = type(typeName); if (!idx) return; + registerStreamOperators(idx, saveOp, loadOp); +} +/*! \internal +*/ +void QMetaType::registerStreamOperators(int idx, SaveOperator saveOp, + LoadOperator loadOp) +{ QVector *ct = customTypes(); if (!ct) return; diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 0277200..115411c 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -108,6 +108,8 @@ public: typedef void (*LoadOperator)(QDataStream &, void *); static void registerStreamOperators(const char *typeName, SaveOperator saveOp, LoadOperator loadOp); + static void registerStreamOperators(int type, SaveOperator saveOp, + LoadOperator loadOp); #endif static int registerType(const char *typeName, Destructor destructor, Constructor constructor); @@ -224,6 +226,24 @@ inline int qRegisterMetaType( #endif } +#ifndef QT_NO_DATASTREAM +template +inline int qRegisterMetaTypeStreamOperators() +{ + typedef void(*SavePtr)(QDataStream &, const T *); + typedef void(*LoadPtr)(QDataStream &, T *); + SavePtr sptr = qMetaTypeSaveHelper; + LoadPtr lptr = qMetaTypeLoadHelper; + + register int id = qMetaTypeId(); + QMetaType::registerStreamOperators(id, + reinterpret_cast(sptr), + reinterpret_cast(lptr)); + + return id; +} +#endif + #define Q_DECLARE_METATYPE(TYPE) \ QT_BEGIN_NAMESPACE \ template <> \ -- cgit v0.12