diff options
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qalgorithms.h | 17 | ||||
-rw-r--r-- | src/corelib/tools/qshareddata.h | 14 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 19 |
3 files changed, 31 insertions, 19 deletions
diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h index 6f623d9..3e5c3cc 100644 --- a/src/corelib/tools/qalgorithms.h +++ b/src/corelib/tools/qalgorithms.h @@ -141,23 +141,6 @@ inline void qCount(const Container &container, const T &value, Size &n) qCount(container.constBegin(), container.constEnd(), value, n); } - -#if defined Q_CC_MSVC && _MSC_VER < 1300 -template <typename T> -inline void qSwap(T &value1, T &value2) -{ - qSwap_helper<T>(value1, value2, (T *)0); -} -#else -template <typename T> -inline void qSwap(T &value1, T &value2) -{ - T t = value1; - value1 = value2; - value2 = t; -} -#endif - #ifdef qdoc template <typename T> LessThan qLess() 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 diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index cbeb79f..1136aa9 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -171,8 +171,8 @@ namespace QtSharedPointer { inline ExternalRefCountData() { - QBasicAtomicInt proto = Q_BASIC_ATOMIC_INITIALIZER(1); - weakref = strongref = proto; + strongref = 1; + weakref = 1; } inline ExternalRefCountData(Qt::Initialization) { } virtual inline ~ExternalRefCountData() { Q_ASSERT(!weakref); Q_ASSERT(strongref <= 0); } @@ -385,6 +385,12 @@ namespace QtSharedPointer { delete this->value; } + inline void internalSwap(ExternalRefCount &other) + { + qSwap(d, other.d); + qSwap(this->value, other.value); + } + #if defined(Q_NO_TEMPLATE_FRIENDS) public: #else @@ -465,6 +471,9 @@ public: inline QSharedPointer<T> &operator=(const QWeakPointer<X> &other) { internalSet(other.d, other.value); return *this; } + inline void swap(QSharedPointer &other) + { internalSwap(other); } + template <class X> QSharedPointer<X> staticCast() const { @@ -682,6 +691,12 @@ Q_INLINE_TEMPLATE QWeakPointer<T> QSharedPointer<T>::toWeakRef() const return QWeakPointer<T>(*this); } +template <class T> +inline void qSwap(QSharedPointer<T> &p1, QSharedPointer<T> &p2) +{ + p1.swap(p2); +} + namespace QtSharedPointer { // helper functions: template <class X, class T> |