8#include <QtCore/qatomic.h>
9#include <QtCore/qcompare.h>
10#include <QtCore/qhashfunctions.h>
14template <
class T>
class QSharedDataPointer;
72 T &
operator*() { implicitlyDetach();
return *(d.get()); }
74 T *
operator->() { implicitlyDetach();
return d.get(); }
76 operator T *() { implicitlyDetach();
return d.get(); }
77 operator const T *()
const noexcept {
return d.get(); }
78 T *
data() { implicitlyDetach();
return d.get(); }
79 T *
get() { implicitlyDetach();
return d.get(); }
80 const T *
data()
const noexcept {
return d.get(); }
81 const T *
get()
const noexcept {
return d.get(); }
82 const T *
constData()
const noexcept {
return d.get(); }
83 T *
take()
noexcept {
return std::exchange(d,
nullptr).get(); }
85 void reset(T *ptr =
nullptr)
noexcept
90 T *old =
std::exchange(d, Qt::totally_ordered_wrapper(ptr)).get();
91 if (old && !old->ref.deref())
96 operator bool ()
const noexcept {
return d !=
nullptr; }
97 bool operator!()
const noexcept {
return d ==
nullptr; }
99 void swap(Self &other)
noexcept
100 { qt_ptr_swap(d, other.d); }
105 T *clone() {
return static_cast<Self *>(
this)->clone(); }
106 template <
typename... Args>
static T *create(Args &&... args)
107 {
return Self::create(
std::forward(args)...); }
108 static void destroy(T *ptr) { Self::destroy(ptr); }
110 void implicitlyDetach()
112 if constexpr (Traits::ImplicitlyDetaches)
113 static_cast<Self *>(
this)->detach();
117 {
return lhs.d == rhs.d; }
120 {
return Qt::compareThreeWay(lhs.d, rhs.d); }
123 {
return lhs.d == rhs; }
126 {
return Qt::compareThreeWay(lhs.d, rhs); }
129 {
return lhs.d ==
nullptr; }
132 {
return Qt::compareThreeWay(lhs.d,
nullptr); }
135 {
return qHash(ptr.data(), seed); }
145class QSharedDataPointer :
public QSharedDataPointerBase<QSharedDataPointer, T>
147 using Base = QSharedDataPointerBase<QSharedDataPointer, T>;
156 const T &operator*()
const;
158 const T *operator->()
const noexcept;
160 operator
const T *()
const noexcept;
163 const T *data()
const noexcept;
164 const T *get()
const noexcept;
165 const T *constData()
const noexcept;
170 QSharedDataPointer()
noexcept : Base(
nullptr) { }
174 explicit QSharedDataPointer(T *data)
noexcept : Base(data)
175 {
if (d) d->ref.ref(); }
177 QSharedDataPointer(T *data, QAdoptSharedDataTag)
noexcept : Base(data)
180 QSharedDataPointer(
const QSharedDataPointer &o)
noexcept : Base(o.d.get())
181 {
if (d) d->ref.ref(); }
183 QSharedDataPointer &
operator=(
const QSharedDataPointer &o)
noexcept
188 inline QSharedDataPointer &
operator=(T *o)
noexcept
194 QSharedDataPointer(QSharedDataPointer &&o)
noexcept
195 : Base(std::exchange(o.d,
nullptr).get())
197 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSharedDataPointer)
200 void reset(T *ptr =
nullptr)
noexcept;
202 operator
bool ()
const noexcept;
203 bool operator!()
const noexcept;
205 void swap(QSharedDataPointer &other)
noexcept;
213 template <
typename... Args>
static T *
create(Args &&... args)
214 {
return new T(
std::forward(args)...); }
218 Q_DECLARE_STRONGLY_ORDERED(QSharedDataPointer)
219 Q_DECLARE_STRONGLY_ORDERED(QSharedDataPointer, T*)
220 Q_DECLARE_STRONGLY_ORDERED(QSharedDataPointer, std::nullptr_t)
237 explicit operator const T *()
const noexcept {
return d.get(); }
241 T *
data()
const noexcept {
return d.get(); }
242 T *
get()
const noexcept {
return d.get(); }
248 T *
data()
const noexcept;
249 T *
get()
const noexcept;
273#ifdef QT_ENABLE_QEXPLICITLYSHAREDDATAPOINTER_STATICCAST
274#error This macro has been removed in Qt 6.9.
309 template <
typename... Args>
static T *
create(Args &&... args)
310 {
return new T(
std::forward(args)...); }
323Q_INLINE_TEMPLATE T *QSharedDataPointer<T>::clone()
325 return new T(*
this->d);
329Q_INLINE_TEMPLATE T *QExplicitlySharedDataPointer<T>::clone()
331 return new T(*
this->d.get());
334template <
template <
typename>
class P,
typename T> Q_OUTOFLINE_TEMPLATE
void
335QSharedDataPointerBase<P, T>::detach_helper()
345void swap(QSharedDataPointer<T> &p1, QSharedDataPointer<T> &p2)
noexcept
355#define QT_DECLARE_QSDP_SPECIALIZATION_DTOR(Class)
356 template<> QSharedDataPointer<Class>::~QSharedDataPointer();
358#define QT_DECLARE_QSDP_SPECIALIZATION_DTOR_WITH_EXPORT(Class, ExportMacro)
359 template<> ExportMacro QSharedDataPointer<Class>::~QSharedDataPointer();
361#define QT_DEFINE_QSDP_SPECIALIZATION_DTOR(Class)
362 template<> QSharedDataPointer<Class>::~QSharedDataPointer()
364 if (d && !d->ref.deref())
368#define QT_DECLARE_QESDP_SPECIALIZATION_DTOR(Class)
369 template<> QExplicitlySharedDataPointer<Class>::~QExplicitlySharedDataPointer();
371#define QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(Class, ExportMacro)
372 template<> ExportMacro QExplicitlySharedDataPointer<Class>::~QExplicitlySharedDataPointer();
374#define QT_DEFINE_QESDP_SPECIALIZATION_DTOR(Class)
375 template<> QExplicitlySharedDataPointer<Class>::~QExplicitlySharedDataPointer()
377 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