Change QTaggedPointer API to be more similar to other smart pointers in Qt

* Rename pointer() to data()

Change-Id: I8ef3e552d45c9990fee4b7efa98e2d878ed2cf98
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Simon Hausmann 2020-03-19 17:40:56 +01:00
parent f5fd9c40cd
commit cef009b1e4
4 changed files with 19 additions and 19 deletions

View File

@ -299,7 +299,7 @@ void QPropertyObserverPointer::unlink()
if (ptr->next)
ptr->next->prev = ptr->prev;
if (ptr->prev)
ptr->prev.setPointer(ptr->next.pointer());
ptr->prev.setPointer(ptr->next.data());
ptr->next = nullptr;
ptr->prev.clear();
}
@ -323,7 +323,7 @@ void QPropertyObserverPointer::notify(QPropertyBindingPrivate *triggeringBinding
auto observer = const_cast<QPropertyObserver*>(ptr);
while (observer) {
auto * const next = observer->next.pointer();
auto * const next = observer->next.data();
if (observer->next.tag() == QPropertyObserver::ObserverNotifiesChangeHandler) {
if (!knownIfPropertyChanged && triggeringBinding) {
knownIfPropertyChanged = true;

View File

@ -94,7 +94,7 @@ struct QPropertyObserverPointer
explicit operator bool() const { return ptr != nullptr; }
QPropertyObserverPointer nextObserver() const { return {ptr->next.pointer()}; }
QPropertyObserverPointer nextObserver() const { return {ptr->next.data()}; }
};
class QPropertyBindingErrorPrivate : public QSharedData

View File

@ -93,13 +93,13 @@ public:
Type &operator*() const noexcept
{
Q_ASSERT(pointer());
return *pointer();
Q_ASSERT(data());
return *data();
}
Type *operator->() const noexcept
{
return pointer();
return data();
}
explicit operator bool() const noexcept
@ -137,14 +137,14 @@ public:
return TagType(typename QtPrivate::TagInfo<T>::TagType(d & tagMask()));
}
T* pointer() const noexcept
T* data() const noexcept
{
return reinterpret_cast<T*>(d & pointerMask());
}
bool isNull() const noexcept
{
return !pointer();
return !data();
}
void swap(QTaggedPointer<T, Tag> &other) noexcept
@ -154,12 +154,12 @@ public:
friend inline bool operator==(const QTaggedPointer<T, Tag> &lhs, const QTaggedPointer<T, Tag> &rhs) noexcept
{
return lhs.pointer() == rhs.pointer();
return lhs.data() == rhs.data();
}
friend inline bool operator!=(const QTaggedPointer<T, Tag> &lhs, const QTaggedPointer<T, Tag> &rhs) noexcept
{
return lhs.pointer() != rhs.pointer();
return lhs.data() != rhs.data();
}
friend inline bool operator==(const QTaggedPointer<T, Tag> &lhs, std::nullptr_t) noexcept
@ -184,7 +184,7 @@ public:
friend inline bool operator!(const QTaggedPointer<T, Tag> &ptr) noexcept
{
return !ptr.pointer();
return !ptr.data();
}
protected:

View File

@ -50,24 +50,24 @@ void tst_QTaggedPointer::construction()
{
{
QTaggedPointer<int> p;
QCOMPARE(p.pointer(), nullptr);
QCOMPARE(p.data(), nullptr);
QVERIFY(!p.tag());
}
{
QTaggedPointer<int> p(nullptr, 0x1);
QCOMPARE(p.pointer(), nullptr);
QCOMPARE(p.data(), nullptr);
QCOMPARE(p.tag(), quintptr(0x1));
}
{
QScopedPointer<int> rawPointer(new int(5));
QTaggedPointer<int> p(rawPointer.data());
QCOMPARE(p.pointer(), rawPointer.data());
QCOMPARE(p.data(), rawPointer.data());
QVERIFY(!p.tag());
}
{
QScopedPointer<int> rawPointer(new int(5));
QTaggedPointer<int> p(rawPointer.data(), 0x1);
QCOMPARE(p.pointer(), rawPointer.data());
QCOMPARE(p.data(), rawPointer.data());
QCOMPARE(p.tag(), quintptr(0x1));
}
}
@ -328,7 +328,7 @@ void tst_QTaggedPointer::tag()
{
QScopedPointer<int> rawPointer(new int(3));
QTaggedPointer<int> p(rawPointer.data());
QCOMPARE(*p.pointer(), 3);
QCOMPARE(*p.data(), 3);
QVERIFY(!p.tag());
p.setTag(0x1);
@ -356,11 +356,11 @@ void tst_QTaggedPointer::objectMember()
f.p = QTaggedPointer<int>(rawPointer.data(), 0x1);
Foo f2(f);
QCOMPARE(f2.p.pointer(), f.p.pointer());
QCOMPARE(f2.p.data(), f.p.data());
QCOMPARE(f2.p.tag(), f.p.tag());
Foo f3 = f;
QCOMPARE(f3.p.pointer(), f.p.pointer());
QCOMPARE(f3.p.data(), f.p.data());
QCOMPARE(f3.p.tag(), f.p.tag());
}
@ -411,7 +411,7 @@ struct LinkedListItem
~LinkedListItem()
{
delete next.pointer();
delete next.data();
}
};