7#include <QtCore/qglobal.h>
8#include <QtCore/qatomic.h>
9#include <QtCore/qhashfunctions.h>
40 void detach() {
if (d && d->ref.loadRelaxed() != 1) detach_helper(); }
45 operator T *() {
detach();
return d; }
46 operator const T *()
const noexcept {
return d; }
49 const T *
data() const noexcept {
return d; }
50 const T *
get() const noexcept {
return d; }
52 T *
take() noexcept {
return std::exchange(d,
nullptr); }
60 {
if (d) d->ref.ref(); }
66 {
if (d) d->ref.ref(); }
73 T *old = std::exchange(d,
ptr);
74 if (old && !old->ref.deref())
93 operator
bool () const noexcept {
return d !=
nullptr; }
94 bool operator!() const noexcept {
return d ==
nullptr; }
99#define DECLARE_COMPARE_SET(T1, A1, T2, A2) \
100 friend bool operator<(T1, T2) noexcept \
101 { return std::less<T*>{}(A1, A2); } \
102 friend bool operator<=(T1, T2) noexcept \
103 { return !std::less<T*>{}(A2, A1); } \
104 friend bool operator>(T1, T2) noexcept \
105 { return std::less<T*>{}(A2, A1); } \
106 friend bool operator>=(T1, T2) noexcept \
107 { return !std::less<T*>{}(A1, A2); } \
108 friend bool operator==(T1, T2) noexcept \
109 { return A1 == A2; } \
110 friend bool operator!=(T1, T2) noexcept \
111 { return A1 != A2; } \
123 void detach_helper();
138 explicit operator T *() {
return d; }
139 explicit operator const T *()
const noexcept {
return d; }
140 T *
data() const noexcept {
return d; }
141 T *
get() const noexcept {
return d; }
143 T *
take() noexcept {
return std::exchange(
d,
nullptr); }
145 void detach() {
if (
d &&
d->ref.loadRelaxed() != 1) detach_helper(); }
153 {
if (
d)
d->ref.ref(); }
159 {
if (
d)
d->ref.ref(); }
164#ifdef QT_ENABLE_QEXPLICITLYSHAREDDATAPOINTER_STATICCAST
165 :
d(
static_cast<T *
>(
o.data()))
169 {
if (
d)
d->ref.ref(); }
176 T *old = std::exchange(
d,
ptr);
177 if (old && !old->ref.deref())
196 operator
bool () const noexcept {
return d !=
nullptr; }
208#undef DECLARE_COMPARE_SET
214 void detach_helper();
274#define QT_DECLARE_QSDP_SPECIALIZATION_DTOR(Class) \
275 template<> QSharedDataPointer<Class>::~QSharedDataPointer();
277#define QT_DECLARE_QSDP_SPECIALIZATION_DTOR_WITH_EXPORT(Class, ExportMacro) \
278 template<> ExportMacro QSharedDataPointer<Class>::~QSharedDataPointer();
280#define QT_DEFINE_QSDP_SPECIALIZATION_DTOR(Class) \
281 template<> QSharedDataPointer<Class>::~QSharedDataPointer() \
283 if (d && !d->ref.deref()) \
287#define QT_DECLARE_QESDP_SPECIALIZATION_DTOR(Class) \
288 template<> QExplicitlySharedDataPointer<Class>::~QExplicitlySharedDataPointer();
290#define QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(Class, ExportMacro) \
291 template<> ExportMacro QExplicitlySharedDataPointer<Class>::~QExplicitlySharedDataPointer();
293#define QT_DEFINE_QESDP_SPECIALIZATION_DTOR(Class) \
294 template<> QExplicitlySharedDataPointer<Class>::~QExplicitlySharedDataPointer() \
296 if (d && !d->ref.deref()) \
Q_NODISCARD_CTOR QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer< X > &o) noexcept
This copy constructor is different in that it allows o to be a different type of explicitly shared da...
T Type
This is the type of the shared data object.
void reset(T *ptr=nullptr) noexcept
Q_NODISCARD_CTOR QExplicitlySharedDataPointer(T *data, QAdoptSharedDataTag) noexcept
void detach()
If the shared data object's reference count is greater than 1, this function creates a deep copy of t...
QExplicitlySharedDataPointer & operator=(T *o) noexcept
Sets the {d pointer} of this to o and increments {o}'s reference count.
Q_NODISCARD_CTOR QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer &o) noexcept
This standard copy constructor sets the {d pointer} of this to the {d pointer} in o and increments th...
~QExplicitlySharedDataPointer()
Decrements the reference count of the shared data object.
QExplicitlySharedDataPointer & operator=(const QExplicitlySharedDataPointer &o) noexcept
Sets the {d pointer} of this to the {d pointer} of o and increments the reference count of the shared...
T * data() const noexcept
Returns a pointer to the shared data object.
Q_NODISCARD_CTOR QExplicitlySharedDataPointer(T *data) noexcept
Constructs a QExplicitlySharedDataPointer with {d pointer} set to data and increments {data}'s refere...
const T * constData() const noexcept
Returns a const pointer to the shared data object.
T * operator->() noexcept
Provides access to the shared data object's members.
bool operator!() const noexcept
Returns true if the {d pointer} of this is \nullptr.
void swap(QExplicitlySharedDataPointer &other) noexcept
Swap this instance's explicitly shared data pointer with the explicitly shared data pointer in other.
Q_NODISCARD_CTOR QExplicitlySharedDataPointer(QExplicitlySharedDataPointer &&o) noexcept
Move-constructs a QExplicitlySharedDataPointer instance, making it point at the same object that o wa...
T & operator*() const
Provides access to the shared data object's members.
T * operator->() const noexcept
Provides const access to the shared data object's members.
Q_NODISCARD_CTOR QExplicitlySharedDataPointer() noexcept
Constructs a QExplicitlySharedDataPointer initialized with \nullptr as {d pointer}.
void swap(QPixmap &other) noexcept
QSharedDataPointer & operator=(const QSharedDataPointer &o) noexcept
Sets the {d pointer} of this to the {d pointer} of o and increments the reference count of the shared...
void reset(T *ptr=nullptr) noexcept
Q_NODISCARD_CTOR QSharedDataPointer() noexcept
Constructs a QSharedDataPointer initialized with \nullptr as {d pointer}.
Q_NODISCARD_CTOR QSharedDataPointer(QSharedDataPointer &&o) noexcept
Move-constructs a QSharedDataPointer instance, making it point at the same object that o was pointing...
QSharedDataPointer & operator=(T *o) noexcept
Sets the {d pointer} og this to o and increments {o}'s reference count.
T Type
This is the type of the shared data object.
~QSharedDataPointer()
Decrements the reference count of the shared data object.
T & operator*()
Provides access to the shared data object's members.
const T * data() const noexcept
Returns a pointer to the shared data object.
const T * operator->() const noexcept
Provides const access to the shared data object's members.
void swap(QSharedDataPointer &other) noexcept
Swap this instance's shared data pointer with the shared data pointer in other.
const T & operator*() const
Provides const access to the shared data object's members.
bool operator!() const noexcept
Returns true if the {d pointer} of this is \nullptr.
void detach()
If the shared data object's reference count is greater than 1, this function creates a deep copy of t...
T * operator->()
Provides access to the shared data object's members.
const T * get() const noexcept
const T * constData() const noexcept
Returns a const pointer to the shared data object.
Q_NODISCARD_CTOR QSharedDataPointer(const QSharedDataPointer &o) noexcept
Sets the {d pointer} of this to the {d pointer} in o and increments the reference count of the shared...
T * data()
Returns a pointer to the shared data object.
Q_NODISCARD_CTOR QSharedDataPointer(T *data, QAdoptSharedDataTag) noexcept
Q_NODISCARD_CTOR QSharedDataPointer(T *data) noexcept
Constructs a QSharedDataPointer with {d pointer} set to data and increments {data}'s reference count.
QSharedData() noexcept
Constructs a QSharedData object with a reference count of 0.
QSharedData & operator=(const QSharedData &)=delete
QSharedData(const QSharedData &) noexcept
Constructs a QSharedData object with reference count 0.
Combined button and popup list for selecting options.
static ControlElement< T > * ptr(QWidget *widget)
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
size_t qHash(const QSharedDataPointer< T > &ptr, size_t seed=0) noexcept
#define DECLARE_COMPARE_SET(T1, A1, T2, A2)
constexpr void qt_ptr_swap(T *&lhs, T *&rhs) noexcept
#define Q_DECLARE_TYPEINFO_BODY(TYPE, FLAGS)
\inmodule QtCore \threadsafe
constexpr QAdoptSharedDataTag()=default