From b1d6af35a45860ad9dfbd65979ca1df44abae446 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 9 Mar 2014 11:56:56 +0100 Subject: QWeakPointer: add member-swap [ChangeLog][QtCore][QWeakPointer] Added member-swap function. Change-Id: Ide3672dc74a9d8153e5f930290d938e8c23993b5 Reviewed-by: Olivier Goffart Reviewed-by: Thiago Macieira --- src/corelib/tools/qsharedpointer.cpp | 8 ++++++++ src/corelib/tools/qsharedpointer.h | 2 ++ src/corelib/tools/qsharedpointer_impl.h | 6 ++++++ 3 files changed, 16 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index 19c88fcf1c..2ced3d6a7c 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -770,6 +770,14 @@ you will get a compiler error. */ +/*! + \fn void QWeakPointer::swap(QWeakPointer &other) + \since 5.4 + + Swaps this weak pointer instance with \a other. This function is + very fast and never fails. +*/ + /*! \fn bool QWeakPointer::isNull() const diff --git a/src/corelib/tools/qsharedpointer.h b/src/corelib/tools/qsharedpointer.h index ea9b4fbf27..d9de48b7f4 100644 --- a/src/corelib/tools/qsharedpointer.h +++ b/src/corelib/tools/qsharedpointer.h @@ -122,6 +122,8 @@ public: QWeakPointer(const QObject *other); QWeakPointer operator=(const QObject *other); + void swap(QWeakPointer &other); + T *data() const; void clear(); diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index e59efce7ae..f70e398cfe 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -587,6 +587,12 @@ public: return *this; } + inline void swap(QWeakPointer &other) + { + qSwap(this->d, other.d); + qSwap(this->value, other.value); + } + inline QWeakPointer(const QSharedPointer &o) : d(o.d), value(o.data()) { if (d) d->weakref.ref();} inline QWeakPointer &operator=(const QSharedPointer &o) -- cgit v1.2.3