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())
97 operator bool ()
const noexcept {
return d !=
nullptr; }
98 bool operator!()
const noexcept {
return d ==
nullptr; }
100 void swap(Self &other)
noexcept
101 { qt_ptr_swap(d, other.d); }
106 T *clone() {
return static_cast<Self *>(
this)->clone(); }
107 template <
typename... Args>
static T *create(Args &&... args)
108 {
return Self::create(
std::forward(args)...); }
109 static void destroy(T *ptr) { Self::destroy(ptr); }
111 void detachIfImplicit()
113 if constexpr (Traits::ImplicitlyDetaches)
114 static_cast<Self *>(
this)->detach();
118 {
return lhs.d == rhs.d; }
121 {
return Qt::compareThreeWay(lhs.d, rhs.d); }
124 {
return lhs.d == rhs; }
127 {
return Qt::compareThreeWay(lhs.d, rhs); }
130 {
return lhs.d ==
nullptr; }
133 {
return Qt::compareThreeWay(lhs.d,
nullptr); }
136 {
return qHash(ptr.data(), seed); }
146class QSharedDataPointer :
public QSharedDataPointerBase<QSharedDataPointer, T>
148 using Base = QSharedDataPointerBase<QSharedDataPointer, T>;
157 const T &operator*()
const;
159 const T *operator->()
const noexcept;
161 operator
const T *()
const noexcept;
164 const T *data()
const noexcept;
165 const T *get()
const noexcept;
166 const T *constData()
const noexcept;
171 QSharedDataPointer()
noexcept : Base(
nullptr) { }
175 explicit QSharedDataPointer(T *data)
noexcept : Base(data)
176 {
if (d) d->ref.ref(); }
178 QSharedDataPointer(T *data, QAdoptSharedDataTag)
noexcept : Base(data)
181 QSharedDataPointer(
const QSharedDataPointer &o)
noexcept : Base(o.d.get())
182 {
if (d) d->ref.ref(); }
184 QSharedDataPointer &
operator=(
const QSharedDataPointer &o)
noexcept
189 inline QSharedDataPointer &
operator=(T *o)
noexcept
195 QSharedDataPointer(QSharedDataPointer &&o)
noexcept
196 : Base(std::exchange(o.d,
nullptr).get())
198 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSharedDataPointer)
201 void reset(T *ptr =
nullptr)
noexcept;
203 operator
bool ()
const noexcept;
204 bool operator!()
const noexcept;
206 void swap(QSharedDataPointer &other)
noexcept;
214 template <
typename... Args>
static T *
create(Args &&... args)
215 {
return new T(
std::forward(args)...); }
219 Q_DECLARE_STRONGLY_ORDERED(QSharedDataPointer)
220 Q_DECLARE_STRONGLY_ORDERED(QSharedDataPointer, T*)
221 Q_DECLARE_STRONGLY_ORDERED(QSharedDataPointer, std::nullptr_t)
238 explicit operator const T *()
const noexcept {
return d.get(); }
242 T *
data()
const noexcept {
return d.get(); }
243 T *
get()
const noexcept {
return d.get(); }
249 T *
data()
const noexcept;
250 T *
get()
const noexcept;
274#ifdef QT_ENABLE_QEXPLICITLYSHAREDDATAPOINTER_STATICCAST
275#error This macro has been removed in Qt 6.9.
310 template <
typename... Args>
static T *
create(Args &&... args)
311 {
return new T(
std::forward(args)...); }
324Q_INLINE_TEMPLATE T *QSharedDataPointer<T>::clone()
326 return new T(*
this->d);
330Q_INLINE_TEMPLATE T *QExplicitlySharedDataPointer<T>::clone()
332 return new T(*
this->d.get());
335template <
template <
typename>
class P,
typename T> Q_OUTOFLINE_TEMPLATE
void
336QSharedDataPointerBase<P, T>::detach_helper()
346void swap(QSharedDataPointer<T> &p1, QSharedDataPointer<T> &p2)
noexcept
356#define QT_DECLARE_QSDP_SPECIALIZATION_DTOR(Class)
357 template<> QSharedDataPointer<Class>::~QSharedDataPointer();
359#define QT_DECLARE_QSDP_SPECIALIZATION_DTOR_WITH_EXPORT(Class, ExportMacro)
360 template<> ExportMacro QSharedDataPointer<Class>::~QSharedDataPointer();
362#define QT_DEFINE_QSDP_SPECIALIZATION_DTOR(Class)
363 template<> QSharedDataPointer<Class>::~QSharedDataPointer()
365 if (d && !d->ref.deref())
369#define QT_DECLARE_QESDP_SPECIALIZATION_DTOR(Class)
370 template<> QExplicitlySharedDataPointer<Class>::~QExplicitlySharedDataPointer();
372#define QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(Class, ExportMacro)
373 template<> ExportMacro QExplicitlySharedDataPointer<Class>::~QExplicitlySharedDataPointer();
375#define QT_DEFINE_QESDP_SPECIALIZATION_DTOR(Class)
376 template<> QExplicitlySharedDataPointer<Class>::~QExplicitlySharedDataPointer()
378 if (d && !d->ref.deref())
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)
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
Q_DECLARE_TYPEINFO_BODY(QSharedDataPointer< T >, Q_RELOCATABLE_TYPE)
\inmodule QtCore \threadsafe