diff options
Diffstat (limited to 'src/corelib/kernel/qpropertyprivate.h')
-rw-r--r-- | src/corelib/kernel/qpropertyprivate.h | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/src/corelib/kernel/qpropertyprivate.h b/src/corelib/kernel/qpropertyprivate.h index aca6d14c96..c4a73f2c91 100644 --- a/src/corelib/kernel/qpropertyprivate.h +++ b/src/corelib/kernel/qpropertyprivate.h @@ -19,6 +19,7 @@ #include <QtCore/qtaggedpointer.h> #include <QtCore/qmetatype.h> #include <QtCore/qcontainerfwd.h> +#include <QtCore/qttypetraits.h> #include <functional> @@ -36,9 +37,13 @@ namespace QtPrivate { // QPropertyBindingPrivatePtr operates on a RefCountingMixin solely so that we can inline // the constructor and copy constructor struct RefCounted { + + int refCount() const { return ref; } + void addRef() { ++ref; } + bool deref() { return --ref != 0; } + +private: int ref = 0; - void addRef() {++ref;} - bool deref() {--ref; return ref;} }; } @@ -61,7 +66,7 @@ public: QPropertyBindingPrivatePtr() noexcept : d(nullptr) { } ~QPropertyBindingPrivatePtr() { - if (d && (--d->ref == 0)) + if (d && !d->deref()) destroyAndFreeMemory(); } Q_CORE_EXPORT void destroyAndFreeMemory(); @@ -91,28 +96,20 @@ public: void swap(QPropertyBindingPrivatePtr &other) noexcept { qt_ptr_swap(d, other.d); } - friend bool operator==(const QPropertyBindingPrivatePtr &p1, const QPropertyBindingPrivatePtr &p2) noexcept - { return p1.d == p2.d; } - friend bool operator!=(const QPropertyBindingPrivatePtr &p1, const QPropertyBindingPrivatePtr &p2) noexcept - { return p1.d != p2.d; } - friend bool operator==(const QPropertyBindingPrivatePtr &p1, const T *ptr) noexcept - { return p1.d == ptr; } - friend bool operator!=(const QPropertyBindingPrivatePtr &p1, const T *ptr) noexcept - { return p1.d != ptr; } - friend bool operator==(const T *ptr, const QPropertyBindingPrivatePtr &p2) noexcept - { return ptr == p2.d; } - friend bool operator!=(const T *ptr, const QPropertyBindingPrivatePtr &p2) noexcept - { return ptr != p2.d; } - friend bool operator==(const QPropertyBindingPrivatePtr &p1, std::nullptr_t) noexcept - { return !p1; } - friend bool operator!=(const QPropertyBindingPrivatePtr &p1, std::nullptr_t) noexcept - { return p1; } - friend bool operator==(std::nullptr_t, const QPropertyBindingPrivatePtr &p2) noexcept - { return !p2; } - friend bool operator!=(std::nullptr_t, const QPropertyBindingPrivatePtr &p2) noexcept - { return p2; } - private: + friend bool comparesEqual(const QPropertyBindingPrivatePtr &lhs, + const QPropertyBindingPrivatePtr &rhs) noexcept + { return lhs.d == rhs.d; } + Q_DECLARE_EQUALITY_COMPARABLE(QPropertyBindingPrivatePtr) + friend bool comparesEqual(const QPropertyBindingPrivatePtr &lhs, + const T *rhs) noexcept + { return lhs.d == rhs; } + Q_DECLARE_EQUALITY_COMPARABLE(QPropertyBindingPrivatePtr, T*) + friend bool comparesEqual(const QPropertyBindingPrivatePtr &lhs, + std::nullptr_t) noexcept + { return !lhs; } + Q_DECLARE_EQUALITY_COMPARABLE(QPropertyBindingPrivatePtr, std::nullptr_t) + QtPrivate::RefCounted *d; }; @@ -124,11 +121,13 @@ struct QPropertyObserverPointer; class QUntypedPropertyData { -public: - // sentinel to check whether a class inherits QUntypedPropertyData - struct InheritsQUntypedPropertyData {}; }; +namespace QtPrivate { +template <typename T> +using IsUntypedPropertyData = std::enable_if_t<std::is_base_of_v<QUntypedPropertyData, T>, bool>; +} + template <typename T> class QPropertyData; |