4#ifndef QQMLREFCOUNT_P_H
5#define QQMLREFCOUNT_P_H
18#include <QtCore/qglobal.h>
19#include <QtCore/qatomic.h>
20#include <private/qv4global_p.h>
32 inline void addref()
const;
33 inline int count()
const;
36 inline ~QQmlRefCount();
40 mutable QAtomicInt refCount;
71 inline bool isNull()
const {
return !o; }
75 explicit inline operator bool()
const {
return o !=
nullptr; }
76 inline T*
data()
const {
return o; }
80 inline T*
take() { T *res = o; o =
nullptr;
return res; }
94 return qHash(v.o, seed);
114
115
116
117
118
119template <
typename T,
typename ...Args>
122 static_assert(std::is_base_of_v<QQmlRefCount, T>);
123 return QQmlRefPointer<T>(
new T(std::forward<Args>(args)...), QQmlRefPointer<T>::Adopt);
137 Q_ASSERT(refCount.loadRelaxed() == 0);
142 Q_ASSERT(refCount.loadRelaxed() > 0);
149 static_assert(std::is_base_of_v<QQmlRefCounted, T>,
150 "QQmlRefCounted<T> must be a base of T (CRTP)");
151 Q_ASSERT(refCount.loadRelaxed() > 0);
152 if (!refCount.deref())
153 delete static_cast<
const T *>(
this);
159 static_assert(std::is_final_v<T> || std::has_virtual_destructor_v<T>,
160 "T must either be marked final or have a virtual dtor, "
161 "lest release() runs into UB.");
166 return refCount.loadRelaxed();
224
225
226
friend class QQmlRefCounted
void swap(QQmlRefPointer &other) noexcept
QQmlRefPointer< T > & operator=(const QQmlRefPointer< T > &o)
QQmlRefPointer< T > & operator=(QQmlRefPointer< T > &&o) noexcept
friend size_t qHash(const QQmlRefPointer &v, size_t seed=0) noexcept
QQmlRefPointer< T > & adopt(T *)
Takes ownership of other.
friend bool operator!=(const QQmlRefPointer &a, const QQmlRefPointer &b) noexcept
friend bool operator==(const QQmlRefPointer &a, const QQmlRefPointer &b) noexcept
QQmlRefPointer< T > makeRefPointer(Args &&... args)
Q_DECLARE_TYPEINFO_BODY(QQmlRefPointer< T >, Q_RELOCATABLE_TYPE)