diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2012-04-05 15:34:46 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-06 16:08:02 +0200 |
commit | 294960c1604218618c31878a68f25aee53972103 (patch) | |
tree | f8f5f9bfa21ba987a37456be69cbec0ce3452526 /src/corelib | |
parent | fa36d81bbcbe9cecaaa20922dd278f7b14fc3d3c (diff) |
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 <ogoffart@woboq.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/global/qtypeinfo.h | 10 |
1 files changed, 5 insertions, 5 deletions
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<T>, 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)>(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>(TYPE &value1, TYPE &value2) \ -{ qSwap(value1.data_ptr(), value2.data_ptr()); } \ +{ value1.swap(value2); } \ Q_DECLARE_SHARED_STL(TYPE) /* |