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
Giuseppe D'Angelo 2017-09-15 17:08:15 +01:00
parent 72f700edd6
commit fc208838ae
3 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -140,6 +140,11 @@ public:
return d;
}
T *get() const Q_DECL_NOTHROW
{
return d;
}
bool isNull() const Q_DECL_NOTHROW
{
return !d;

View File

@ -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);
}
}