summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qshareddata.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-08-14 13:04:30 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-08-14 15:33:28 (GMT)
commit78fbb9cf6ef5e8440f0453ef60bd7845ce418745 (patch)
treea8e784f5e6b509b79d88e6fdd4092c4f89517441 /src/corelib/tools/qshareddata.h
parenta931fac02fe0430439a351dacc5167ddeca1d4d0 (diff)
downloadQt-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/tools/qshareddata.h')
-rw-r--r--src/corelib/tools/qshareddata.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h
index e13e37c..dde6e88 100644
--- a/src/corelib/tools/qshareddata.h
+++ b/src/corelib/tools/qshareddata.h
@@ -111,6 +111,9 @@ public:
inline bool operator!() const { return !d; }
+ inline void swap(QSharedDataPointer &other)
+ { qSwap(d, other.d); }
+
protected:
T *clone();
@@ -186,6 +189,9 @@ public:
inline bool operator!() const { return !d; }
+ inline void swap(QExplicitlySharedDataPointer &other)
+ { qSwap(d, other.d); }
+
protected:
T *clone();
@@ -235,6 +241,14 @@ template <class T>
Q_INLINE_TEMPLATE QExplicitlySharedDataPointer<T>::QExplicitlySharedDataPointer(T *adata) : d(adata)
{ if (d) d->ref.ref(); }
+template <class T>
+Q_INLINE_TEMPLATE void qSwap(QSharedDataPointer<T> &p1, QSharedDataPointer<T> &p2)
+{ p1.swap(p2); }
+
+template <class T>
+Q_INLINE_TEMPLATE void qSwap(QExplicitlySharedDataPointer<T> &p1, QExplicitlySharedDataPointer<T> &p2)
+{ p1.swap(p2); }
+
QT_END_NAMESPACE
QT_END_HEADER