Warning, file /include/QtCore/qsharedpointer.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004 #ifndef QSHAREDPOINTER_H
0005 #define QSHAREDPOINTER_H
0006
0007 #include <QtCore/qglobal.h>
0008 #include <QtCore/qatomic.h>
0009 #include <QtCore/qshareddata.h>
0010
0011 #ifndef Q_QDOC
0012 # include <QtCore/qsharedpointer_impl.h>
0013 #else
0014
0015 #include <memory> // for std::shared_ptr
0016
0017 QT_BEGIN_NAMESPACE
0018
0019
0020
0021
0022 template <class T>
0023 class QSharedPointer
0024 {
0025 public:
0026
0027 T *data() const;
0028 T *get() const;
0029 bool isNull() const;
0030 operator bool() const;
0031 bool operator!() const;
0032 T &operator*() const;
0033 T *operator->() const;
0034
0035
0036 QSharedPointer();
0037 template <typename X> explicit QSharedPointer(X *ptr);
0038 template <typename X, typename Deleter> QSharedPointer(X *ptr, Deleter d);
0039 QSharedPointer(std::nullptr_t);
0040 template <typename Deleter> QSharedPointer(std::nullptr_t, Deleter d);
0041 QSharedPointer(const QSharedPointer<T> &other);
0042 QSharedPointer(const QWeakPointer<T> &other);
0043 QSharedPointer(QSharedPointer<T> &&other) noexcept;
0044
0045 ~QSharedPointer() { }
0046
0047 QSharedPointer<T> &operator=(const QSharedPointer<T> &other);
0048 QSharedPointer<T> &operator=(QSharedPointer<T> &&other) noexcept;
0049 QSharedPointer<T> &operator=(const QWeakPointer<T> &other);
0050
0051 template <class X>
0052 QSharedPointer(QSharedPointer<X> && other) noexcept;
0053 template <class X>
0054 QSharedPointer &operator=(QSharedPointer<X> && other) noexcept;
0055
0056 void swap(QSharedPointer<T> &other) noexcept;
0057
0058 QWeakPointer<T> toWeakRef() const;
0059
0060 void clear();
0061
0062 void reset();
0063 void reset(T *t);
0064 template <typename Deleter>
0065 void reset(T *t, Deleter deleter);
0066
0067
0068 template <class X> QSharedPointer<X> staticCast() const;
0069 template <class X> QSharedPointer<X> dynamicCast() const;
0070 template <class X> QSharedPointer<X> constCast() const;
0071 template <class X> QSharedPointer<X> objectCast() const;
0072
0073 template <typename... Args>
0074 static inline QSharedPointer<T> create(Args &&... args);
0075
0076
0077 template <typename X>
0078 bool owner_before(const QSharedPointer<X> &other) const noexcept;
0079 template <typename X>
0080 bool owner_before(const QWeakPointer<X> &other) const noexcept;
0081
0082 template <typename X>
0083 bool owner_equal(const QSharedPointer<X> &other) const noexcept;
0084 template <typename X>
0085 bool owner_equal(const QWeakPointer<X> &other) const noexcept;
0086
0087 size_t owner_hash() const noexcept;
0088 };
0089
0090 template <class T>
0091 size_t qHash(const QSharedPointer<T> &key, size_t seed = 0) noexcept;
0092
0093 template <class T>
0094 class QWeakPointer
0095 {
0096 public:
0097
0098 bool isNull() const;
0099 operator bool() const;
0100 bool operator!() const;
0101
0102
0103 QWeakPointer();
0104 QWeakPointer(const QWeakPointer<T> &other) noexcept;
0105 QWeakPointer(QWeakPointer<T> &&other) noexcept;
0106 QWeakPointer(const QSharedPointer<T> &other);
0107
0108 ~QWeakPointer();
0109
0110 QWeakPointer<T> &operator=(const QWeakPointer<T> &other) noexcept;
0111 QWeakPointer<T> &operator=(QWeakPointer<T> &&other) noexcept;
0112 QWeakPointer<T> &operator=(const QSharedPointer<T> &other);
0113
0114 QWeakPointer(const QObject *other);
0115 QWeakPointer<T> &operator=(const QObject *other);
0116
0117 void swap(QWeakPointer<T> &other) noexcept;
0118
0119 T *data() const;
0120 void clear();
0121
0122 QSharedPointer<T> toStrongRef() const;
0123 QSharedPointer<T> lock() const;
0124
0125
0126 template <typename X>
0127 bool owner_before(const QWeakPointer<X> &other) const noexcept;
0128 template <typename X>
0129 bool owner_before(const QSharedPointer<X> &other) const noexcept;
0130
0131 template <typename X>
0132 bool owner_equal(const QWeakPointer<X> &other) const noexcept;
0133 template <typename X>
0134 bool owner_equal(const QSharedPointer<X> &other) const noexcept;
0135
0136 size_t owner_hash() const noexcept;
0137 };
0138
0139 template <class T>
0140 class QEnableSharedFromThis
0141 {
0142 public:
0143 QSharedPointer<T> sharedFromThis();
0144 QSharedPointer<const T> sharedFromThis() const;
0145 };
0146
0147 template<class T, class X> bool operator==(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2);
0148 template<class T, class X> bool operator!=(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2);
0149 template<class T, class X> bool operator==(const QSharedPointer<T> &ptr1, const X *ptr2);
0150 template<class T, class X> bool operator!=(const QSharedPointer<T> &ptr1, const X *ptr2);
0151 template<class T, class X> bool operator==(const T *ptr1, const QSharedPointer<X> &ptr2);
0152 template<class T, class X> bool operator!=(const T *ptr1, const QSharedPointer<X> &ptr2);
0153 template<class T, class X> bool operator==(const QWeakPointer<T> &ptr1, const QSharedPointer<X> &ptr2);
0154 template<class T, class X> bool operator!=(const QWeakPointer<T> &ptr1, const QSharedPointer<X> &ptr2);
0155 template<class T, class X> bool operator==(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2);
0156 template<class T, class X> bool operator!=(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2);
0157 template<class T> bool operator==(const QSharedPointer<T> &lhs, std::nullptr_t);
0158 template<class T> bool operator!=(const QSharedPointer<T> &lhs, std::nullptr_t);
0159 template<class T> bool operator==(std::nullptr_t, const QSharedPointer<T> &rhs);
0160 template<class T> bool operator!=(std::nullptr_t, const QSharedPointer<T> &rhs);
0161 template<class T> bool operator==(const QWeakPointer<T> &lhs, std::nullptr_t);
0162 template<class T> bool operator!=(const QWeakPointer<T> &lhs, std::nullptr_t);
0163 template<class T> bool operator==(std::nullptr_t, const QWeakPointer<T> &rhs);
0164 template<class T> bool operator!=(std::nullptr_t, const QWeakPointer<T> &rhs);
0165
0166 template <class X, class T> QSharedPointer<X> qSharedPointerCast(const QSharedPointer<T> &other);
0167 template <class X, class T> QSharedPointer<X> qSharedPointerCast(const QWeakPointer<T> &other);
0168 template <class X, class T> QSharedPointer<X> qSharedPointerDynamicCast(const QSharedPointer<T> &src);
0169 template <class X, class T> QSharedPointer<X> qSharedPointerDynamicCast(const QWeakPointer<T> &src);
0170 template <class X, class T> QSharedPointer<X> qSharedPointerConstCast(const QSharedPointer<T> &src);
0171 template <class X, class T> QSharedPointer<X> qSharedPointerConstCast(const QWeakPointer<T> &src);
0172 template <class X, class T> QSharedPointer<X> qSharedPointerObjectCast(const QSharedPointer<T> &src);
0173 template <class X, class T> QSharedPointer<X> qSharedPointerObjectCast(const QWeakPointer<T> &src);
0174 template <typename X, class T> std::shared_ptr<X> qobject_pointer_cast(const std::shared_ptr<T> &src);
0175 template <typename X, class T> std::shared_ptr<X> qobject_pointer_cast(std::shared_ptr<T> &&src);
0176 template <typename X, class T> std::shared_ptr<X> qSharedPointerObjectCast(const std::shared_ptr<T> &src);
0177 template <typename X, class T> std::shared_ptr<X> qSharedPointerObjectCast(std::shared_ptr<T> &&src);
0178
0179 template <class X, class T> QWeakPointer<X> qWeakPointerCast(const QWeakPointer<T> &src);
0180
0181 QT_END_NAMESPACE
0182
0183 #endif
0184
0185 #endif