7#include <QtCore/qatomic.h>
8#include <QtCore/qcompare.h>
9#include <QtCore/qhashfunctions.h>
13template <
class T>
class QSharedDataPointer;
71 T &
operator*() { implicitlyDetach();
return *(d.get()); }
73 T *
operator->() { implicitlyDetach();
return d.get(); }
75 operator T *() { implicitlyDetach();
return d.get(); }
76 operator const T *()
const noexcept {
return d.get(); }
77 T *
data() { implicitlyDetach();
return d.get(); }
78 T *
get() { implicitlyDetach();
return d.get(); }
79 const T *
data()
const noexcept {
return d.get(); }
80 const T *
get()
const noexcept {
return d.get(); }
81 const T *
constData()
const noexcept {
return d.get(); }
82 T *
take()
noexcept {
return std::exchange(d,
nullptr).get(); }
84 void reset(T *ptr =
nullptr)
noexcept
89 T *old = std::exchange(d, Qt::totally_ordered_wrapper(ptr)).get();
90 if (old && !old->ref.deref())
95 operator bool ()
const noexcept {
return d !=
nullptr; }
96 bool operator!()
const noexcept {
return d ==
nullptr; }
98 void swap(Self &other)
noexcept
99 { qt_ptr_swap(d, other.d); }
104 T *clone() {
return static_cast<Self *>(
this)->clone(); }
105 template <
typename... Args>
static T *create(Args &&... args)
106 {
return Self::create(
std::forward(args)...); }
107 static void destroy(T *ptr) { Self::destroy(ptr); }
109 void implicitlyDetach()
111 if constexpr (Traits::ImplicitlyDetaches)
112 static_cast<Self *>(
this)->detach();
116 {
return lhs.d == rhs.d; }
119 {
return Qt::compareThreeWay(lhs.d, rhs.d); }
122 {
return lhs.d == rhs; }
125 {
return Qt::compareThreeWay(lhs.d, rhs); }
128 {
return lhs.d ==
nullptr; }
131 {
return Qt::compareThreeWay(lhs.d,
nullptr); }
134 {
return qHash(ptr.data(), seed); }
144class QSharedDataPointer :
public QSharedDataPointerBase<QSharedDataPointer, T>
146 using Base = QSharedDataPointerBase<QSharedDataPointer, T>;
155 const T &operator*()
const;
157 const T *operator->()
const noexcept;
159 operator
const T *()
const noexcept;
162 const T *data()
const noexcept;
163 const T *get()
const noexcept;
164 const T *constData()
const noexcept;
169 QSharedDataPointer()
noexcept : Base(
nullptr) { }
173 explicit QSharedDataPointer(T *data)
noexcept : Base(data)
174 {
if (d) d->ref.ref(); }
176 QSharedDataPointer(T *data, QAdoptSharedDataTag)
noexcept : Base(data)
179 QSharedDataPointer(
const QSharedDataPointer &o)
noexcept : Base(o.d.get())
180 {
if (d) d->ref.ref(); }
182 QSharedDataPointer &
operator=(
const QSharedDataPointer &o)
noexcept
187 inline QSharedDataPointer &
operator=(T *o)
noexcept
193 QSharedDataPointer(QSharedDataPointer &&o)
noexcept
194 : Base(std::exchange(o.d,
nullptr).get())
196 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSharedDataPointer)
199 void reset(T *ptr =
nullptr)
noexcept;
201 operator
bool ()
const noexcept;
202 bool operator!()
const noexcept;
204 void swap(QSharedDataPointer &other)
noexcept;
212 template <
typename... Args>
static T *
create(Args &&... args)
213 {
return new T(
std::forward(args)...); }
217 Q_DECLARE_STRONGLY_ORDERED(QSharedDataPointer)
218 Q_DECLARE_STRONGLY_ORDERED(QSharedDataPointer, T*)
219 Q_DECLARE_STRONGLY_ORDERED(QSharedDataPointer, std::nullptr_t)
236 explicit operator const T *()
const noexcept {
return d.get(); }
240 T *
data()
const noexcept {
return d.get(); }
241 T *
get()
const noexcept {
return d.get(); }
247 T *
data()
const noexcept;
248 T *
get()
const noexcept;
272#ifdef QT_ENABLE_QEXPLICITLYSHAREDDATAPOINTER_STATICCAST
273#error This macro has been removed in Qt 6.9.
308 template <
typename... Args>
static T *
create(Args &&... args)
309 {
return new T(
std::forward(args)...); }
322Q_INLINE_TEMPLATE T *QSharedDataPointer<T>::clone()
324 return new T(*
this->d);
328Q_INLINE_TEMPLATE T *QExplicitlySharedDataPointer<T>::clone()
330 return new T(*
this->d.get());
333template <
template <
typename>
class P,
typename T> Q_OUTOFLINE_TEMPLATE
void
334QSharedDataPointerBase<P, T>::detach_helper()
344void swap(QSharedDataPointer<T> &p1, QSharedDataPointer<T> &p2)
noexcept
354#define QT_DECLARE_QSDP_SPECIALIZATION_DTOR(Class)
355 template<> QSharedDataPointer<Class>::~QSharedDataPointer();
357#define QT_DECLARE_QSDP_SPECIALIZATION_DTOR_WITH_EXPORT(Class, ExportMacro)
358 template<> ExportMacro QSharedDataPointer<Class>::~QSharedDataPointer();
360#define QT_DEFINE_QSDP_SPECIALIZATION_DTOR(Class)
361 template<> QSharedDataPointer<Class>::~QSharedDataPointer()
363 if (d && !d->ref.deref())
367#define QT_DECLARE_QESDP_SPECIALIZATION_DTOR(Class)
368 template<> QExplicitlySharedDataPointer<Class>::~QExplicitlySharedDataPointer();
370#define QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(Class, ExportMacro)
371 template<> ExportMacro QExplicitlySharedDataPointer<Class>::~QExplicitlySharedDataPointer();
373#define QT_DEFINE_QESDP_SPECIALIZATION_DTOR(Class)
374 template<> QExplicitlySharedDataPointer<Class>::~QExplicitlySharedDataPointer()
376 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