From 294960c1604218618c31878a68f25aee53972103 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 5 Apr 2012 15:34:46 +0200 Subject: Q_DECLARE_SHARED: fix docs; require and use member-swap By requiring a member-swap, this macro becomes applicable to a wider range of types (e.g. QFont, which has another member besides 'd'), while at the same time avoiding the encapsulation leak that is data_ptr(). There have been concerns over breaking existing users of this macro, but for some time now, Q_DECLARE_SHARED only works within QT_BEGIN_NAMESPACE anyway, so its a safe bet that all users of this macro are in-tree. Change-Id: I7fdd9dba204554af8d3f9768b97bb42847a5acf4 Reviewed-by: Olivier Goffart Reviewed-by: Thiago Macieira --- src/corelib/global/qtypeinfo.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/corelib/global/qtypeinfo.h') diff --git a/src/corelib/global/qtypeinfo.h b/src/corelib/global/qtypeinfo.h index 48ee99ef27..de484006c5 100644 --- a/src/corelib/global/qtypeinfo.h +++ b/src/corelib/global/qtypeinfo.h @@ -166,23 +166,23 @@ Q_DECLARE_TYPEINFO_BODY(QFlags, Q_PRIMITIVE_TYPE); /* Specialize a shared type with: - Q_DECLARE_SHARED(type); + Q_DECLARE_SHARED(type) where 'type' is the name of the type to specialize. NOTE: shared - types must declare a 'bool isDetached(void) const;' member for this - to work. + types must define a member-swap, and be defined in the same + namespace as Qt for this to work. */ #define Q_DECLARE_SHARED_STL(TYPE) \ QT_END_NAMESPACE \ namespace std { \ template<> inline void swap(QT_PREPEND_NAMESPACE(TYPE) &value1, QT_PREPEND_NAMESPACE(TYPE) &value2) \ - { swap(value1.data_ptr(), value2.data_ptr()); } \ + { value1.swap(value2); } \ } \ QT_BEGIN_NAMESPACE #define Q_DECLARE_SHARED(TYPE) \ template <> inline void qSwap(TYPE &value1, TYPE &value2) \ -{ qSwap(value1.data_ptr(), value2.data_ptr()); } \ +{ value1.swap(value2); } \ Q_DECLARE_SHARED_STL(TYPE) /* -- cgit v1.2.3