QScopedPointer: add get()
For self-consistency with QSharedPointer and minor consistency with std::unique_ptr (although QScopedPointer isn't movable, so we can't claim STL compatibility with it). [ChangeLog][QtCore][QScopedPointer] Added get(). Change-Id: Ib58f936afa0e0d5bce57a61d1467b69956f37ceb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
72f700edd6
commit
fc208838ae
|
|
@ -145,6 +145,13 @@ QT_BEGIN_NAMESPACE
|
|||
still owns the object pointed to.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn T *QScopedPointer::get() const
|
||||
\since 5.11
|
||||
|
||||
Same as data().
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn T &QScopedPointer::operator*() const
|
||||
|
||||
|
|
|
|||
|
|
@ -140,6 +140,11 @@ public:
|
|||
return d;
|
||||
}
|
||||
|
||||
T *get() const Q_DECL_NOTHROW
|
||||
{
|
||||
return d;
|
||||
}
|
||||
|
||||
bool isNull() const Q_DECL_NOTHROW
|
||||
{
|
||||
return !d;
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ void tst_QScopedPointer::defaultConstructor()
|
|||
/* Check that the members, one, is correctly initialized. */
|
||||
QScopedPointer<int> p;
|
||||
QCOMPARE(p.data(), static_cast<int *>(0));
|
||||
QCOMPARE(p.get(), static_cast<int *>(0));
|
||||
}
|
||||
|
||||
void tst_QScopedPointer::dataOnDefaultConstructed()
|
||||
|
|
@ -75,6 +76,7 @@ void tst_QScopedPointer::dataOnDefaultConstructed()
|
|||
QScopedPointer<int> p;
|
||||
|
||||
QCOMPARE(p.data(), static_cast<int *>(0));
|
||||
QCOMPARE(p.get(), static_cast<int *>(0));
|
||||
}
|
||||
|
||||
class MyClass
|
||||
|
|
@ -113,6 +115,7 @@ void tst_QScopedPointer::reset()
|
|||
QScopedPointer<int> p;
|
||||
p.reset();
|
||||
QCOMPARE(p.data(), static_cast<int *>(0));
|
||||
QCOMPARE(p.get(), static_cast<int *>(0));
|
||||
}
|
||||
|
||||
/* Call reset() on an active value. */
|
||||
|
|
@ -120,6 +123,7 @@ void tst_QScopedPointer::reset()
|
|||
QScopedPointer<int> p(new int(3));
|
||||
p.reset();
|
||||
QCOMPARE(p.data(), static_cast<int *>(0));
|
||||
QCOMPARE(p.get(), static_cast<int *>(0));
|
||||
}
|
||||
|
||||
/* Call reset() with a value, on an active value. */
|
||||
|
|
@ -129,6 +133,7 @@ void tst_QScopedPointer::reset()
|
|||
int *const value = new int(9);
|
||||
p.reset(value);
|
||||
QCOMPARE(*p.data(), 9);
|
||||
QCOMPARE(*p.get(), 9);
|
||||
}
|
||||
|
||||
/* Call reset() with a value, on default constructed value. */
|
||||
|
|
@ -138,6 +143,7 @@ void tst_QScopedPointer::reset()
|
|||
int *const value = new int(9);
|
||||
p.reset(value);
|
||||
QCOMPARE(*p.data(), 9);
|
||||
QCOMPARE(*p.get(), 9);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue