8#include <QtCore/qatomic.h>
9#include <QtCore/qcompare.h>
10#include <QtCore/qhashfunctions.h>
14template <
class T>
class QSharedDataPointer;
73 T &
operator*() { detachIfImplicit();
return *(d.get()); }
75 T *
operator->() { detachIfImplicit();
return d.get(); }
77 operator T *() { detachIfImplicit();
return d.get(); }
78 operator const T *()
const noexcept {
return d.get(); }
79 T *
data() { detachIfImplicit();
return d.get(); }
80 T *
get() { detachIfImplicit();
return d.get(); }
81 const T *
data()
const noexcept {
return d.get(); }
82 const T *
get()
const noexcept {
return d.get(); }
83 const T *
constData()
const noexcept {
return d.get(); }
84 T *
take()
noexcept {
return std::exchange(d,
nullptr).get(); }
86 void reset(T *ptr =
nullptr)
noexcept
91 T *old =
std::exchange(d, Qt::totally_ordered_wrapper(ptr)).get();
92 if (old && !old->ref.deref())
99 if (d && (d->ref.loadAcquire() == 1 || !d->ref.deref())) {
101 d->ref.storeRelaxed(1);
112 operator bool ()
const noexcept {
return d !=
nullptr; }
113 bool operator!()
const noexcept {
return d ==
nullptr; }
115 void swap(Self &other)
noexcept
116 { qt_ptr_swap(d, other.d); }
121 T *clone() {
return static_cast<Self *>(
this)->clone(); }
122 template <
typename... Args>
static T *create(Args &&... args)
123 {
return Self::create(
std::forward(args)...); }
124 static void destroy(T *ptr) { Self::destroy(ptr); }
126 void detachIfImplicit()
128 if constexpr (Traits::ImplicitlyDetaches)
129 static_cast<Self *>(
this)->detach();
133 {
return lhs.d == rhs.d; }
136 {
return Qt::compareThreeWay(lhs.d, rhs.d); }
139 {
return lhs.d == rhs; }
142 {
return Qt::compareThreeWay(lhs.d, rhs); }
145 {
return lhs.d ==
nullptr; }
148 {
return Qt::compareThreeWay(lhs.d,
nullptr); }
151 {
return qHash(ptr.data(), seed); }
161class QSharedDataPointer :
public QSharedDataPointerBase<QSharedDataPointer, T>
163 using Base = QSharedDataPointerBase<QSharedDataPointer, T>;
172 const T &operator*()
const;
174 const T *operator->()
const noexcept;
176 operator
const T *()
const noexcept;
179 const T *data()
const noexcept;
180 const T *get()
const noexcept;
181 const T *constData()
const noexcept;
186 QSharedDataPointer()
noexcept : Base(
nullptr) { }
190 explicit QSharedDataPointer(T *data)
noexcept : Base(data)
191 {
if (d) d->ref.ref(); }
193 QSharedDataPointer(T *data, QAdoptSharedDataTag)
noexcept : Base(data)
196 QSharedDataPointer(
const QSharedDataPointer &o)
noexcept : Base(o.d.get())
197 {
if (d) d->ref.ref(); }
199 QSharedDataPointer &
operator=(
const QSharedDataPointer &o)
noexcept
204 inline QSharedDataPointer &
operator=(T *o)
noexcept
210 QSharedDataPointer(QSharedDataPointer &&o)
noexcept
211 : Base(std::exchange(o.d,
nullptr).get())
213 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSharedDataPointer)
216 void reset(T *ptr =
nullptr)
noexcept;
219 operator
bool ()
const noexcept;
220 bool operator!()
const noexcept;
222 void swap(QSharedDataPointer &other)
noexcept;
230 template <
typename... Args>
static T *
create(Args &&... args)
231 {
return new T(
std::forward(args)...); }
235 Q_DECLARE_STRONGLY_ORDERED(QSharedDataPointer)
236 Q_DECLARE_STRONGLY_ORDERED(QSharedDataPointer, T*)
237 Q_DECLARE_STRONGLY_ORDERED(QSharedDataPointer, std::nullptr_t)
254 explicit operator const T *()
const noexcept {
return d.get(); }
258 T *
data()
const noexcept {
return d.get(); }
259 T *
get()
const noexcept {
return d.get(); }
265 T *
data()
const noexcept;
266 T *
get()
const noexcept;
290#ifdef QT_ENABLE_QEXPLICITLYSHAREDDATAPOINTER_STATICCAST
291#error This macro has been removed in Qt 6.9.
327 template <
typename... Args>
static T *
create(Args &&... args)
328 {
return new T(
std::forward(args)...); }
341Q_INLINE_TEMPLATE T *QSharedDataPointer<T>::clone()
343 return new T(*
this->d);
347Q_INLINE_TEMPLATE T *QExplicitlySharedDataPointer<T>::clone()
349 return new T(*
this->d.get());
352template <
template <
typename>
class P,
typename T> Q_OUTOFLINE_TEMPLATE
void
353QSharedDataPointerBase<P, T>::detach_helper()
363void swap(QSharedDataPointer<T> &p1, QSharedDataPointer<T> &p2)
noexcept
373#define QT_DECLARE_QSDP_SPECIALIZATION_DTOR_COMMON(Pointer, Class, ExportMacro)
374 template<> ExportMacro Pointer<Class>::~Pointer();
375#define QT_DEFINE_QSDP_SPECIALIZATION_DTOR_COMMON(Pointer, Class, Inline)
376 template<> Inline Pointer<Class>::~Pointer()
378 if (d && !d->ref.deref())
382#define QT_DECLARE_QSDP_SPECIALIZATION_DTOR(Class)
385#define QT_DECLARE_QSDP_SPECIALIZATION_DTOR_WITH_EXPORT(Class, ExportMacro)
388#define QT_DEFINE_QSDP_SPECIALIZATION_DTOR(Class)
391#define QT_DECLARE_QESDP_SPECIALIZATION_DTOR(Class)
394#define QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(Class, ExportMacro)
397#define QT_DEFINE_QESDP_SPECIALIZATION_DTOR(Class)
constexpr QAtomicInt(int value=0) noexcept
Constructs a QAtomicInt with the given value.
\macro Q_ATOMIC_INTnn_IS_SUPPORTED
QAtomicPointer(const QAtomicPointer< T > &other) noexcept
Constructs a copy of other.
QAtomicPointer< T > & operator=(const QAtomicPointer< T > &other) noexcept
Assigns other to this QAtomicPointer and returns a reference to this QAtomicPointer.
constexpr QAtomicPointer(T *value=nullptr) noexcept
Constructs a QAtomicPointer with the given value.
~QExplicitlySharedDataPointer()
Decrements the reference count of the shared data object.
static void destroy(T *ptr)
operator const T *() const noexcept
T Type
This is the type of the shared data object.
static T * create(Args &&... args)
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.
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.
QFileInfoPrivate(const QFileSystemEntry &file, const QFileSystemMetaData &data, std::unique_ptr< QAbstractFileEngine > engine)
bool const isDefaultConstructed
QFileInfoPrivate(const QFileSystemEntry &file, const QFileSystemMetaData &data)
Ret checkAttribute(QFileSystemMetaData::MetaDataFlags fsFlags, FSLambda fsLambda, EngineLambda engineLambda) const
QFileSystemMetaData metaData
QDateTime & getFileTime(QFile::FileTime) const
std::unique_ptr< QAbstractFileEngine > const fileEngine
uint getFileFlags(QAbstractFileEngine::FileFlags) const
void setCachedFlag(uint c) const
QString getFileOwner(QAbstractFileEngine::FileOwner own) const
bool getCachedFlag(uint c) const
QFileInfoPrivate(const QFileInfoPrivate ©)
QFileSystemEntry fileEntry
static QFileInfoPrivate * get(QFileInfo *fi)
QString getFileName(QAbstractFileEngine::FileName) const
QString fileNames[QAbstractFileEngine::NFileNames]
QFileInfoPrivate(const QString &file)
Ret checkAttribute(Ret defaultValue, QFileSystemMetaData::MetaDataFlags fsFlags, FSLambda fsLambda, EngineLambda engineLambda) const
Qt::totally_ordered_wrapper< T * > d
constexpr QSharedDataPointerBase(T *ptr=nullptr) noexcept
friend bool comparesEqual(const QSharedDataPointerBase &lhs, const T *rhs) noexcept
friend bool comparesEqual(const QSharedDataPointerBase &lhs, std::nullptr_t) noexcept
void reset(T *ptr=nullptr) noexcept
const T * data() const noexcept
void swap(Self &other) noexcept
bool operator!() const noexcept
friend Qt::strong_ordering compareThreeWay(const QSharedDataPointerBase &lhs, const QSharedDataPointerBase &rhs) noexcept
friend Qt::strong_ordering compareThreeWay(const QSharedDataPointerBase &lhs, const T *rhs) noexcept
friend size_t qHash(const QSharedDataPointerBase &ptr, size_t seed=0) noexcept
constT & operator*() const
constT * operator->() const noexcept
friend bool comparesEqual(const QSharedDataPointerBase &lhs, const QSharedDataPointerBase &rhs) noexcept
const T * get() const noexcept
operator bool() const noexcept
friend Qt::strong_ordering compareThreeWay(const QSharedDataPointerBase &lhs, std::nullptr_t) noexcept
operator const T *() const noexcept
const T * constData() const noexcept
T Type
This is the type of the shared data object.
~QSharedDataPointer()
Decrements the reference count of the shared data object.
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...
static void destroy(T *ptr)
static T * create(Args &&... args)
void detach()
If the shared data object's reference count is greater than 1, this function creates a deep copy of t...
QSharedDataPointer & operator=(T *o) noexcept
Sets the {d pointer} og this to o and increments {o}'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.
void qAtomicDetach(T *&d)
This is a helper for the detach method of implicitly shared classes.
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
bool comparesEqual(const QFileInfo &lhs, const QFileInfo &rhs)
#define QT_DEFINE_QSDP_SPECIALIZATION_DTOR_COMMON(Pointer, Class, Inline)
Q_DECLARE_TYPEINFO_BODY(QExplicitlySharedDataPointer< T >, Q_RELOCATABLE_TYPE)
void swap(QExplicitlySharedDataPointer< T > &p1, QExplicitlySharedDataPointer< T > &p2) noexcept
void swap(QSharedDataPointer< T > &p1, QSharedDataPointer< T > &p2) noexcept
#define QT_DEFINE_QSDP_SPECIALIZATION_DTOR(Class)
#define QT_DECLARE_QSDP_SPECIALIZATION_DTOR_COMMON(Pointer, Class, ExportMacro)
Q_DECLARE_TYPEINFO_BODY(QSharedDataPointer< T >, Q_RELOCATABLE_TYPE)
\inmodule QtCore \threadsafe