diff options
author | Jędrzej Nowacki <jedrzej.nowacki@nokia.com> | 2011-11-29 15:42:33 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-04 14:25:25 +0100 |
commit | 08863b6fdaa8383e2274826db3ec42c4d4f11576 (patch) | |
tree | a3cc772ada845bffa60f5b186defeb469bf1f5af /src/corelib/kernel/qvariant.h | |
parent | 52fc6694b87e93fe0828424bb26d9279785de3e7 (diff) |
Refactor QVariant handlers.
QVariant implementation is based on delegation to a handler. The handler
has rather simple construction, it is a set of function that implements
a switch statement over known types and redirects calls to a right
method of an encapsulated types instance. Unfortunately after qt
modularization project, it is not easy to use types directly from
different modules, as they can be undefined or completely unaccessible.
Which means that each module has to implement own handler to cooperate
correctly with QVariant. We can suspect that list of modules known to
QVariant will grow and it is not limited to GUI, Widgets and Core,
therefore it would be nice to have an unified, from performance and
source code point of view, way of working with handlers.
This patch is an attempt to cleanup handlers. Keynotes:
- Each handler is working only on types defined in the same module
- Core handler implements handling of primitive types too
- Custom types have an own handler
- Each handler is independent which means that dispatch between handlers
is done on QVariant level
- Handlers might be registered / unregistered using same interface
Change-Id: Ib096df65e2c4ce464bc7a684aade5af7d1264c24
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/kernel/qvariant.h')
-rw-r--r-- | src/corelib/kernel/qvariant.h | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 02458a07e0..9b477e5dd6 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -370,19 +370,21 @@ class Q_CORE_EXPORT QVariant { return !cmp(v); } protected: - friend inline bool qvariant_cast_helper(const QVariant &, QVariant::Type, void *); - friend void qRegisterGuiVariant(); - friend void qUnregisterGuiVariant(); friend inline bool operator==(const QVariant &, const QVariantComparisonHelper &); #ifndef QT_NO_DEBUG_STREAM friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QVariant &); #endif Private d; - - static const Handler *handler; - +#ifndef Q_NO_TEMPLATE_FRIENDS + template<typename T> + friend inline T qvariant_cast(const QVariant &); +private: +#else +public: +#endif void create(int type, const void *copy); bool cmp(const QVariant &other) const; + bool convert(const int t, void *ptr) const; private: // force compile error, prevent QVariant(bool) to be called @@ -396,9 +398,6 @@ public: inline DataPtr &data_ptr() { return d; } }; -inline bool qvariant_cast_helper(const QVariant &v, QVariant::Type tp, void *ptr) -{ return QVariant::handler->convert(&v.d, tp, ptr, 0); } - template <typename T> inline QVariant qVariantFromValue(const T &t) { @@ -488,7 +487,7 @@ template<typename T> inline T qvariant_cast(const QVariant &v) return *reinterpret_cast<const T *>(v.constData()); if (vid < int(QMetaType::User)) { T t; - if (qvariant_cast_helper(v, QVariant::Type(vid), &t)) + if (v.convert(vid, &t)) return t; } return T(); |