QWeakPointer: add member-swap
[ChangeLog][QtCore][QWeakPointer] Added member-swap function. Change-Id: Ide3672dc74a9d8153e5f930290d938e8c23993b5 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
e3a8e242ad
commit
b1d6af35a4
@ -770,6 +770,14 @@
|
||||
you will get a compiler error.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QWeakPointer::swap(QWeakPointer<T> &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
|
||||
|
||||
|
@ -122,6 +122,8 @@ public:
|
||||
QWeakPointer(const QObject *other);
|
||||
QWeakPointer<T> operator=(const QObject *other);
|
||||
|
||||
void swap(QWeakPointer<T> &other);
|
||||
|
||||
T *data() const;
|
||||
void clear();
|
||||
|
||||
|
@ -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<T> &o) : d(o.d), value(o.data())
|
||||
{ if (d) d->weakref.ref();}
|
||||
inline QWeakPointer &operator=(const QSharedPointer<T> &o)
|
||||
|
@ -392,6 +392,30 @@ void tst_QSharedPointer::swap()
|
||||
QVERIFY(p2 != control);
|
||||
QVERIFY(p2.isNull());
|
||||
QVERIFY(*p1 == 42);
|
||||
|
||||
QWeakPointer<int> w1, w2 = control;
|
||||
|
||||
QVERIFY(w1.isNull());
|
||||
QVERIFY(!w2.isNull());
|
||||
QVERIFY(w2.lock() == control);
|
||||
QVERIFY(!w1.lock());
|
||||
|
||||
w1.swap(w2);
|
||||
QVERIFY(w2.isNull());
|
||||
QVERIFY(!w1.isNull());
|
||||
QVERIFY(w1.lock() == control);
|
||||
QVERIFY(!w2.lock());
|
||||
|
||||
qSwap(w1, w2);
|
||||
QVERIFY(w1.isNull());
|
||||
QVERIFY(w2.lock() == control);
|
||||
|
||||
p1.reset();
|
||||
p2.reset();
|
||||
control.reset();
|
||||
|
||||
QVERIFY(w1.isNull());
|
||||
QVERIFY(w2.isNull());
|
||||
}
|
||||
|
||||
void tst_QSharedPointer::useOfForwardDeclared()
|
||||
|
Loading…
Reference in New Issue
Block a user