Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-01 09:22:03

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:significant reason:default
0004 
0005 #ifndef QSHAREDPOINTER_H
0006 #define QSHAREDPOINTER_H
0007 
0008 #include <QtCore/qglobal.h>
0009 #include <QtCore/qatomic.h>
0010 #include <QtCore/qshareddata.h>
0011 
0012 #ifndef Q_QDOC
0013 # include <QtCore/qsharedpointer_impl.h>
0014 #else
0015 
0016 #include <memory> // for std::shared_ptr
0017 
0018 QT_BEGIN_NAMESPACE
0019 
0020 
0021 // These classes are here to fool qdoc into generating a better documentation
0022 
0023 template <class T>
0024 class QSharedPointer
0025 {
0026 public:
0027     // basic accessor functions
0028     T *data() const;
0029     T *get() const;
0030     bool isNull() const;
0031     operator bool() const;
0032     bool operator!() const;
0033     T &operator*() const;
0034     T *operator->() const;
0035 
0036     // constructors
0037     QSharedPointer();
0038     template <typename X> explicit QSharedPointer(X *ptr);
0039     template <typename X, typename Deleter> QSharedPointer(X *ptr, Deleter d);
0040     QSharedPointer(std::nullptr_t);
0041     template <typename Deleter> QSharedPointer(std::nullptr_t, Deleter d);
0042     QSharedPointer(const QSharedPointer<T> &other);
0043     QSharedPointer(const QWeakPointer<T> &other);
0044     QSharedPointer(QSharedPointer<T> &&other) noexcept;
0045 
0046     ~QSharedPointer() { }
0047 
0048     QSharedPointer<T> &operator=(const QSharedPointer<T> &other);
0049     QSharedPointer<T> &operator=(QSharedPointer<T> &&other) noexcept;
0050     QSharedPointer<T> &operator=(const QWeakPointer<T> &other);
0051 
0052     template <class X>
0053     QSharedPointer(QSharedPointer<X> && other) noexcept;
0054     template <class X>
0055     QSharedPointer &operator=(QSharedPointer<X> && other) noexcept;
0056 
0057     void swap(QSharedPointer<T> &other) noexcept;
0058 
0059     QWeakPointer<T> toWeakRef() const;
0060 
0061     void clear();
0062 
0063     void reset();
0064     void reset(T *t);
0065     template <typename Deleter>
0066     void reset(T *t, Deleter deleter);
0067 
0068     // casts:
0069     template <class X> QSharedPointer<X> staticCast() const &;
0070     template <class X> QSharedPointer<X> staticCast() &&;
0071     template <class X> QSharedPointer<X> dynamicCast() const &;
0072     template <class X> QSharedPointer<X> dynamicCast() &&;
0073     template <class X> QSharedPointer<X> constCast() const &;
0074     template <class X> QSharedPointer<X> constCast() &&;
0075     template <class X> QSharedPointer<X> objectCast() const &;
0076     template <class X> QSharedPointer<X> objectCast() &&;
0077 
0078     template <typename... Args>
0079     static inline QSharedPointer<T> create(Args &&... args);
0080 
0081     // owner-based comparisons
0082     template <typename X>
0083     bool owner_before(const QSharedPointer<X> &other) const noexcept;
0084     template <typename X>
0085     bool owner_before(const QWeakPointer<X> &other) const noexcept;
0086 
0087     template <typename X>
0088     bool owner_equal(const QSharedPointer<X> &other) const noexcept;
0089     template <typename X>
0090     bool owner_equal(const QWeakPointer<X> &other) const noexcept;
0091 
0092     size_t owner_hash() const noexcept;
0093 };
0094 
0095 template <class T>
0096 size_t qHash(const QSharedPointer<T> &key, size_t seed = 0) noexcept;
0097 
0098 template <class T>
0099 class QWeakPointer
0100 {
0101 public:
0102     // basic accessor functions
0103     bool isNull() const;
0104     operator bool() const;
0105     bool operator!() const;
0106 
0107     // constructors:
0108     QWeakPointer();
0109     QWeakPointer(const QWeakPointer<T> &other) noexcept;
0110     QWeakPointer(QWeakPointer<T> &&other) noexcept;
0111     QWeakPointer(const QSharedPointer<T> &other);
0112 
0113     ~QWeakPointer();
0114 
0115     QWeakPointer<T> &operator=(const QWeakPointer<T> &other) noexcept;
0116     QWeakPointer<T> &operator=(QWeakPointer<T> &&other) noexcept;
0117     QWeakPointer<T> &operator=(const QSharedPointer<T> &other);
0118 
0119     void swap(QWeakPointer<T> &other) noexcept;
0120 
0121     void clear();
0122 
0123     QSharedPointer<T> toStrongRef() const;
0124     QSharedPointer<T> lock() const;
0125 
0126     // owner-based comparisons
0127     template <typename X>
0128     bool owner_before(const QWeakPointer<X> &other) const noexcept;
0129     template <typename X>
0130     bool owner_before(const QSharedPointer<X> &other) const noexcept;
0131 
0132     template <typename X>
0133     bool owner_equal(const QWeakPointer<X> &other) const noexcept;
0134     template <typename X>
0135     bool owner_equal(const QSharedPointer<X> &other) const noexcept;
0136 
0137     size_t owner_hash() const noexcept;
0138 };
0139 
0140 template <class T>
0141 class QEnableSharedFromThis
0142 {
0143 public:
0144     QSharedPointer<T> sharedFromThis();
0145     QSharedPointer<const T> sharedFromThis() const;
0146 };
0147 
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 QSharedPointer<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 QSharedPointer<T> &ptr1, const 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 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 QWeakPointer<T> &ptr1, const QSharedPointer<X> &ptr2);
0156 template<class T, class X> bool operator==(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2);
0157 template<class T, class X> bool operator!=(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2);
0158 template<class T> bool operator==(const QSharedPointer<T> &lhs, std::nullptr_t);
0159 template<class T> bool operator!=(const QSharedPointer<T> &lhs, std::nullptr_t);
0160 template<class T> bool operator==(std::nullptr_t, const QSharedPointer<T> &rhs);
0161 template<class T> bool operator!=(std::nullptr_t, const QSharedPointer<T> &rhs);
0162 template<class T> bool operator==(const QWeakPointer<T> &lhs, std::nullptr_t);
0163 template<class T> bool operator!=(const QWeakPointer<T> &lhs, std::nullptr_t);
0164 template<class T> bool operator==(std::nullptr_t, const QWeakPointer<T> &rhs);
0165 template<class T> bool operator!=(std::nullptr_t, const QWeakPointer<T> &rhs);
0166 
0167 template <class X, class T> QSharedPointer<X> qSharedPointerCast(const QSharedPointer<T> &other);
0168 template <class X, class T> QSharedPointer<X> qSharedPointerCast(QSharedPointer<T> &&other);
0169 template <class X, class T> QSharedPointer<X> qSharedPointerCast(const QWeakPointer<T> &other);
0170 template <class X, class T> QSharedPointer<X> qSharedPointerDynamicCast(const QSharedPointer<T> &src);
0171 template <class X, class T> QSharedPointer<X> qSharedPointerDynamicCast(QSharedPointer<T> &&src);
0172 template <class X, class T> QSharedPointer<X> qSharedPointerDynamicCast(const QWeakPointer<T> &src);
0173 template <class X, class T> QSharedPointer<X> qSharedPointerConstCast(const QSharedPointer<T> &src);
0174 template <class X, class T> QSharedPointer<X> qSharedPointerConstCast(QSharedPointer<T> &&src);
0175 template <class X, class T> QSharedPointer<X> qSharedPointerConstCast(const QWeakPointer<T> &src);
0176 template <class X, class T> QSharedPointer<X> qSharedPointerObjectCast(const QSharedPointer<T> &src);
0177 template <class X, class T> QSharedPointer<X> qSharedPointerObjectCast(QSharedPointer<T> &&src);
0178 template <class X, class T> QSharedPointer<X> qSharedPointerObjectCast(const QWeakPointer<T> &src);
0179 template <typename X, class T> std::shared_ptr<X> qobject_pointer_cast(const std::shared_ptr<T> &src);
0180 template <typename X, class T> std::shared_ptr<X> qobject_pointer_cast(std::shared_ptr<T> &&src);
0181 template <typename X, class T> std::shared_ptr<X> qSharedPointerObjectCast(const std::shared_ptr<T> &src);
0182 template <typename X, class T> std::shared_ptr<X> qSharedPointerObjectCast(std::shared_ptr<T> &&src);
0183 
0184 template <class X, class T> QWeakPointer<X> qWeakPointerCast(const QWeakPointer<T> &src);
0185 
0186 QT_END_NAMESPACE
0187 
0188 #endif // Q_QDOC
0189 
0190 #endif // QSHAREDPOINTER_H