diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-14 13:04:30 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-14 15:33:28 (GMT) |
commit | 78fbb9cf6ef5e8440f0453ef60bd7845ce418745 (patch) | |
tree | a8e784f5e6b509b79d88e6fdd4092c4f89517441 /src/corelib/global/qglobal.h | |
parent | a931fac02fe0430439a351dacc5167ddeca1d4d0 (diff) | |
download | Qt-78fbb9cf6ef5e8440f0453ef60bd7845ce418745.zip Qt-78fbb9cf6ef5e8440f0453ef60bd7845ce418745.tar.gz Qt-78fbb9cf6ef5e8440f0453ef60bd7845ce418745.tar.bz2 |
Reimplement qSwap and Q_DECLARE_SHARED differently.
This enables the use of Q_DECLARE_SHARED with d-pointers that are
QExplicitlySharedDataPointer<PrivateClass>.
Also, this enables swapping atomically QSharedPointers.
Reviewed-by: Harald Fernengel
Diffstat (limited to 'src/corelib/global/qglobal.h')
-rw-r--r-- | src/corelib/global/qglobal.h | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 5a2c329..92fe649 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1906,6 +1906,14 @@ public: \ static inline const char *name() { return #TYPE; } \ } +template <typename T> +inline void qSwap(T &value1, T &value2) +{ + const T t = value1; + value1 = value2; + value2 = t; +} + /* Specialize a shared type with: @@ -1915,33 +1923,12 @@ public: \ types must declare a 'bool isDetached(void) const;' member for this to work. */ -#if defined Q_CC_MSVC && _MSC_VER < 1300 -template <typename T> -inline void qSwap_helper(T &value1, T &value2, T*) -{ - T t = value1; - value1 = value2; - value2 = t; -} #define Q_DECLARE_SHARED(TYPE) \ template <> inline bool qIsDetached<TYPE>(TYPE &t) { return t.isDetached(); } \ -template <> inline void qSwap_helper<TYPE>(TYPE &value1, TYPE &value2, TYPE*) \ -{ \ - const TYPE::DataPtr t = value1.data_ptr(); \ - value1.data_ptr() = value2.data_ptr(); \ - value2.data_ptr() = t; \ -} -#else -#define Q_DECLARE_SHARED(TYPE) \ -template <> inline bool qIsDetached<TYPE>(TYPE &t) { return t.isDetached(); } \ -template <typename T> inline void qSwap(T &, T &); \ template <> inline void qSwap<TYPE>(TYPE &value1, TYPE &value2) \ { \ - const TYPE::DataPtr t = value1.data_ptr(); \ - value1.data_ptr() = value2.data_ptr(); \ - value2.data_ptr() = t; \ + qSwap<TYPE::DataPtr>(value1.data_ptr(), value2.data_ptr()); \ } -#endif /* QTypeInfo primitive specializations |