// Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QSHAREDPOINTER_H #define QSHAREDPOINTER_H #include #include #include #ifndef Q_QDOC # include #else #include // for std::shared_ptr QT_BEGIN_NAMESPACE // These classes are here to fool qdoc into generating a better documentation template class QSharedPointer { public: // basic accessor functions T *data() const; T *get() const; bool isNull() const; operator bool() const; bool operator!() const; T &operator*() const; T *operator->() const; // constructors QSharedPointer(); template explicit QSharedPointer(X *ptr); template QSharedPointer(X *ptr, Deleter d); QSharedPointer(std::nullptr_t); template QSharedPointer(std::nullptr_t, Deleter d); QSharedPointer(const QSharedPointer &other); QSharedPointer(const QWeakPointer &other); QSharedPointer(QSharedPointer &&other) noexcept; ~QSharedPointer() { } QSharedPointer &operator=(const QSharedPointer &other); QSharedPointer &operator=(QSharedPointer &&other) noexcept; QSharedPointer &operator=(const QWeakPointer &other); template QSharedPointer(QSharedPointer && other) noexcept; template QSharedPointer &operator=(QSharedPointer && other) noexcept; void swap(QSharedPointer &other) noexcept; QWeakPointer toWeakRef() const; void clear(); void reset(); void reset(T *t); template void reset(T *t, Deleter deleter); // casts: template QSharedPointer staticCast() const; template QSharedPointer dynamicCast() const; template QSharedPointer constCast() const; template QSharedPointer objectCast() const; template static inline QSharedPointer create(Args &&... args); // owner-based comparisons template bool owner_before(const QSharedPointer &other) const noexcept; template bool owner_before(const QWeakPointer &other) const noexcept; template bool owner_equal(const QSharedPointer &other) const noexcept; template bool owner_equal(const QWeakPointer &other) const noexcept; size_t owner_hash() const noexcept; }; template size_t qHash(const QSharedPointer &key, size_t seed = 0) noexcept; template class QWeakPointer { public: // basic accessor functions bool isNull() const; operator bool() const; bool operator!() const; // constructors: QWeakPointer(); QWeakPointer(const QWeakPointer &other) noexcept; QWeakPointer(QWeakPointer &&other) noexcept; QWeakPointer(const QSharedPointer &other); ~QWeakPointer(); QWeakPointer &operator=(const QWeakPointer &other) noexcept; QWeakPointer &operator=(QWeakPointer &&other) noexcept; QWeakPointer &operator=(const QSharedPointer &other); QWeakPointer(const QObject *other); QWeakPointer &operator=(const QObject *other); void swap(QWeakPointer &other) noexcept; T *data() const; void clear(); QSharedPointer toStrongRef() const; QSharedPointer lock() const; // owner-based comparisons template bool owner_before(const QWeakPointer &other) const noexcept; template bool owner_before(const QSharedPointer &other) const noexcept; template bool owner_equal(const QWeakPointer &other) const noexcept; template bool owner_equal(const QSharedPointer &other) const noexcept; size_t owner_hash() const noexcept; }; template class QEnableSharedFromThis { public: QSharedPointer sharedFromThis(); QSharedPointer sharedFromThis() const; }; template bool operator==(const QSharedPointer &ptr1, const QSharedPointer &ptr2); template bool operator!=(const QSharedPointer &ptr1, const QSharedPointer &ptr2); template bool operator==(const QSharedPointer &ptr1, const X *ptr2); template bool operator!=(const QSharedPointer &ptr1, const X *ptr2); template bool operator==(const T *ptr1, const QSharedPointer &ptr2); template bool operator!=(const T *ptr1, const QSharedPointer &ptr2); template bool operator==(const QWeakPointer &ptr1, const QSharedPointer &ptr2); template bool operator!=(const QWeakPointer &ptr1, const QSharedPointer &ptr2); template bool operator==(const QSharedPointer &ptr1, const QWeakPointer &ptr2); template bool operator!=(const QSharedPointer &ptr1, const QWeakPointer &ptr2); template bool operator==(const QSharedPointer &lhs, std::nullptr_t); template bool operator!=(const QSharedPointer &lhs, std::nullptr_t); template bool operator==(std::nullptr_t, const QSharedPointer &rhs); template bool operator!=(std::nullptr_t, const QSharedPointer &rhs); template bool operator==(const QWeakPointer &lhs, std::nullptr_t); template bool operator!=(const QWeakPointer &lhs, std::nullptr_t); template bool operator==(std::nullptr_t, const QWeakPointer &rhs); template bool operator!=(std::nullptr_t, const QWeakPointer &rhs); template QSharedPointer qSharedPointerCast(const QSharedPointer &other); template QSharedPointer qSharedPointerCast(const QWeakPointer &other); template QSharedPointer qSharedPointerDynamicCast(const QSharedPointer &src); template QSharedPointer qSharedPointerDynamicCast(const QWeakPointer &src); template QSharedPointer qSharedPointerConstCast(const QSharedPointer &src); template QSharedPointer qSharedPointerConstCast(const QWeakPointer &src); template QSharedPointer qSharedPointerObjectCast(const QSharedPointer &src); template QSharedPointer qSharedPointerObjectCast(const QWeakPointer &src); template std::shared_ptr qobject_pointer_cast(const std::shared_ptr &src); template std::shared_ptr qobject_pointer_cast(std::shared_ptr &&src); template std::shared_ptr qSharedPointerObjectCast(const std::shared_ptr &src); template std::shared_ptr qSharedPointerObjectCast(std::shared_ptr &&src); template QWeakPointer qWeakPointerCast(const QWeakPointer &src); QT_END_NAMESPACE #endif // Q_QDOC #endif // QSHAREDPOINTER_H