1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QSHAREDPOINTER_H
41#define QSHAREDPOINTER_H
42
43#include <QtCore/qglobal.h>
44#include <QtCore/qatomic.h>
45#include <QtCore/qshareddata.h>
46
47#ifndef Q_QDOC
48# include <QtCore/qsharedpointer_impl.h>
49#else
50
51QT_BEGIN_NAMESPACE
52
53
54// These classes are here to fool qdoc into generating a better documentation
55
56template <class T>
57class QSharedPointer
58{
59public:
60 // basic accessor functions
61 T *data() const;
62 T *get() const;
63 bool isNull() const;
64 operator bool() const;
65 bool operator!() const;
66 T &operator*() const;
67 T *operator ->() const;
68
69 // constructors
70 QSharedPointer();
71 template <typename X> explicit QSharedPointer(X *ptr);
72 template <typename X, typename Deleter> QSharedPointer(X *ptr, Deleter d);
73 QSharedPointer(std::nullptr_t);
74 template <typename Deleter> QSharedPointer(std::nullptr_t, Deleter d);
75 QSharedPointer(const QSharedPointer<T> &other);
76 QSharedPointer(const QWeakPointer<T> &other);
77
78 ~QSharedPointer() { }
79
80 QSharedPointer<T> &operator=(const QSharedPointer<T> &other);
81 QSharedPointer<T> &operator=(const QWeakPointer<T> &other);
82
83 void swap(QSharedPointer<T> &other);
84
85 QWeakPointer<T> toWeakRef() const;
86
87 void clear();
88
89 void reset();
90 void reset(T *t);
91 template <typename Deleter>
92 void reset(T *t, Deleter deleter);
93
94 // casts:
95 template <class X> QSharedPointer<X> staticCast() const;
96 template <class X> QSharedPointer<X> dynamicCast() const;
97 template <class X> QSharedPointer<X> constCast() const;
98 template <class X> QSharedPointer<X> objectCast() const;
99
100 static inline QSharedPointer<T> create();
101 static inline QSharedPointer<T> create(...);
102};
103
104template <class T>
105class QWeakPointer
106{
107public:
108 // basic accessor functions
109 bool isNull() const;
110 operator bool() const;
111 bool operator!() const;
112
113 // constructors:
114 QWeakPointer();
115 QWeakPointer(const QWeakPointer<T> &other);
116 QWeakPointer(const QSharedPointer<T> &other);
117
118 ~QWeakPointer();
119
120 QWeakPointer<T> &operator=(const QWeakPointer<T> &other);
121 QWeakPointer<T> &operator=(const QSharedPointer<T> &other);
122
123 QWeakPointer(const QObject *other);
124 QWeakPointer<T> &operator=(const QObject *other);
125
126 void swap(QWeakPointer<T> &other);
127
128 T *data() const;
129 void clear();
130
131 QSharedPointer<T> toStrongRef() const;
132 QSharedPointer<T> lock() const;
133};
134
135template <class T>
136class QEnableSharedFromThis
137{
138public:
139 QSharedPointer<T> sharedFromThis();
140 QSharedPointer<const T> sharedFromThis() const;
141};
142
143template<class T, class X> bool operator==(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2);
144template<class T, class X> bool operator!=(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2);
145template<class T, class X> bool operator==(const QSharedPointer<T> &ptr1, const X *ptr2);
146template<class T, class X> bool operator!=(const QSharedPointer<T> &ptr1, const X *ptr2);
147template<class T, class X> bool operator==(const T *ptr1, const QSharedPointer<X> &ptr2);
148template<class T, class X> bool operator!=(const T *ptr1, const QSharedPointer<X> &ptr2);
149template<class T, class X> bool operator==(const QWeakPointer<T> &ptr1, const QSharedPointer<X> &ptr2);
150template<class T, class X> bool operator!=(const QWeakPointer<T> &ptr1, const QSharedPointer<X> &ptr2);
151template<class T, class X> bool operator==(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2);
152template<class T, class X> bool operator!=(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2);
153template<class T> bool operator==(const QSharedPointer<T> &lhs, std::nullptr_t);
154template<class T> bool operator!=(const QSharedPointer<T> &lhs, std::nullptr_t);
155template<class T> bool operator==(std::nullptr_t, const QSharedPointer<T> &rhs);
156template<class T> bool operator!=(std::nullptr_t, const QSharedPointer<T> &rhs);
157template<class T> bool operator==(const QWeakPointer<T> &lhs, std::nullptr_t);
158template<class T> bool operator!=(const QWeakPointer<T> &lhs, std::nullptr_t);
159template<class T> bool operator==(std::nullptr_t, const QWeakPointer<T> &rhs);
160template<class T> bool operator!=(std::nullptr_t, const QWeakPointer<T> &rhs);
161
162template <class X, class T> QSharedPointer<X> qSharedPointerCast(const QSharedPointer<T> &other);
163template <class X, class T> QSharedPointer<X> qSharedPointerCast(const QWeakPointer<T> &other);
164template <class X, class T> QSharedPointer<X> qSharedPointerDynamicCast(const QSharedPointer<T> &src);
165template <class X, class T> QSharedPointer<X> qSharedPointerDynamicCast(const QWeakPointer<T> &src);
166template <class X, class T> QSharedPointer<X> qSharedPointerConstCast(const QSharedPointer<T> &src);
167template <class X, class T> QSharedPointer<X> qSharedPointerConstCast(const QWeakPointer<T> &src);
168template <class X, class T> QSharedPointer<X> qSharedPointerObjectCast(const QSharedPointer<T> &src);
169template <class X, class T> QSharedPointer<X> qSharedPointerObjectCast(const QWeakPointer<T> &src);
170
171template <class X, class T> QWeakPointer<X> qWeakPointerCast(const QWeakPointer<T> &src);
172
173QT_END_NAMESPACE
174
175#endif // Q_QDOC
176
177#endif // QSHAREDPOINTER_H
178