summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qpropertyprivate.h
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2020-02-27 14:11:51 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2020-03-19 13:09:13 +0100
commit4a702e580eec2d6efc4f80664725bd90bfcaa4e0 (patch)
tree2c67ac949d55238d4260002f543f5aa349742435 /src/corelib/kernel/qpropertyprivate.h
parent58992993a381fedd2f0e36edb73a63cfb9b3bcea (diff)
Use QTaggedPointer in QPropertyObserver
This replaces the private tagged pointer and the use of enums for the tag makes the observer handling code more readable. The pointer-to-tagged-pointer class remains in qpropertyprivate.h due to its exoticness. Change-Id: Icc88799136c6839426d994b42368526463265e66 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qpropertyprivate.h')
-rw-r--r--src/corelib/kernel/qpropertyprivate.h70
1 files changed, 18 insertions, 52 deletions
diff --git a/src/corelib/kernel/qpropertyprivate.h b/src/corelib/kernel/qpropertyprivate.h
index 6d4a729845..22c5416197 100644
--- a/src/corelib/kernel/qpropertyprivate.h
+++ b/src/corelib/kernel/qpropertyprivate.h
@@ -53,6 +53,7 @@
#include <QtCore/qglobal.h>
#include <QtCore/QExplicitlySharedDataPointer>
+#include <QtCore/qtaggedpointer.h>
QT_BEGIN_NAMESPACE
@@ -161,85 +162,50 @@ struct QPropertyValueStorage<bool>
}
};
-template <typename T> class QTaggedPointer;
-
-template <typename T, quintptr Mask = 0x3>
-class QPropertyTagPreservingPointerToPointer
+template <typename T, typename Tag>
+class QTagPreservingPointerToPointer
{
- quintptr *data = nullptr;
-
public:
- QPropertyTagPreservingPointerToPointer() = default;
- QPropertyTagPreservingPointerToPointer(T **ptr)
- : data(reinterpret_cast<quintptr*>(ptr))
- {}
- QPropertyTagPreservingPointerToPointer(quintptr *ptr)
- : data(ptr)
+ QTagPreservingPointerToPointer() = default;
+
+ QTagPreservingPointerToPointer(T **ptr)
+ : d(reinterpret_cast<quintptr*>(ptr))
{}
- QPropertyTagPreservingPointerToPointer<T> &operator=(T **ptr)
+ QTagPreservingPointerToPointer<T, Tag> &operator=(T **ptr)
{
- data = reinterpret_cast<quintptr*>(ptr);
+ d = reinterpret_cast<quintptr*>(ptr);
return *this;
}
- QPropertyTagPreservingPointerToPointer<T> &operator=(QTaggedPointer<T> *ptr)
+ QTagPreservingPointerToPointer<T, Tag> &operator=(QTaggedPointer<T, Tag> *ptr)
{
- data = reinterpret_cast<quintptr*>(ptr);
+ d = reinterpret_cast<quintptr*>(ptr);
return *this;
}
void clear()
{
- data = nullptr;
+ d = nullptr;
}
- void set(T *ptr)
+ void setPointer(T *ptr)
{
- *data = (*data & Mask) | (reinterpret_cast<quintptr>(ptr) & ~Mask);
+ *d = (reinterpret_cast<quintptr>(ptr) & QTaggedPointer<T, Tag>::pointerMask()) | (*d & QTaggedPointer<T, Tag>::tagMask());
}
T *get() const
{
- return reinterpret_cast<T*>(*data & ~Mask);
+ return reinterpret_cast<T*>(*d & QTaggedPointer<T, Tag>::pointerMask());
}
- explicit operator bool() const { return data != nullptr; }
-};
-
-template <typename T>
-class QTaggedPointer
-{
-public:
- QTaggedPointer() = default;
- QTaggedPointer(T *ptr) : tagAndPointer(reinterpret_cast<quintptr>(ptr)) {}
-
- void setFlag(bool b)
+ explicit operator bool() const
{
- if (b)
- tagAndPointer |= Flag1Mask;
- else
- tagAndPointer &= ~Flag1Mask;
+ return d != nullptr;
}
- bool flag() const { return tagAndPointer & Flag1Mask; }
-
- QTaggedPointer &operator=(T *ptr)
- {
- quintptr tag = tagAndPointer & TagMask;
- tagAndPointer = reinterpret_cast<quintptr>(ptr) | tag;
- return *this;
- }
-
- T *data() const { return reinterpret_cast<T*>(tagAndPointer & ~TagMask); }
-
- explicit operator bool() const { return tagAndPointer & ~TagMask; }
- T *operator->() const { return data(); }
-
private:
- quintptr tagAndPointer = 0;
- static const quintptr Flag1Mask = 0x1;
- static const quintptr TagMask = 0x3;
+ quintptr *d = nullptr;
};
} // namespace QtPrivate