1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
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 Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #ifndef QSHAREDPOINTER_H |
43 | #define QSHAREDPOINTER_H |
44 | |
45 | #include <QtCore/qglobal.h> |
46 | #include <QtCore/qatomic.h> |
47 | #include <QtCore/qshareddata.h> |
48 | |
49 | #ifndef Q_QDOC |
50 | # include <QtCore/qsharedpointer_impl.h> |
51 | #else |
52 | |
53 | QT_BEGIN_HEADER |
54 | |
55 | QT_BEGIN_NAMESPACE |
56 | |
57 | QT_MODULE(Core) |
58 | |
59 | // These classes are here to fool qdoc into generating a better documentation |
60 | |
61 | template <class T> |
62 | class QSharedPointer |
63 | { |
64 | public: |
65 | // basic accessor functions |
66 | T *data() const; |
67 | bool isNull() const; |
68 | operator bool() const; |
69 | bool operator!() const; |
70 | T &operator*() const; |
71 | T *operator ->() const; |
72 | |
73 | // constructors |
74 | QSharedPointer(); |
75 | explicit QSharedPointer(T *ptr); |
76 | QSharedPointer(T *ptr, Deleter d); |
77 | QSharedPointer(const QSharedPointer<T> &other); |
78 | QSharedPointer(const QWeakPointer<T> &other); |
79 | |
80 | ~QSharedPointer() { } |
81 | |
82 | QSharedPointer<T> &operator=(const QSharedPointer<T> &other); |
83 | QSharedPointer<T> &operator=(const QWeakPointer<T> &other); |
84 | |
85 | QWeakPointer<T> toWeakRef() const; |
86 | |
87 | void clear(); |
88 | |
89 | // casts: |
90 | template <class X> QSharedPointer<X> staticCast() const; |
91 | template <class X> QSharedPointer<X> dynamicCast() const; |
92 | template <class X> QSharedPointer<X> constCast() const; |
93 | template <class X> QSharedPointer<X> objectCast() const; |
94 | }; |
95 | |
96 | template <class T> |
97 | class QWeakPointer |
98 | { |
99 | public: |
100 | // basic accessor functions |
101 | bool isNull() const; |
102 | operator bool() const; |
103 | bool operator!() const; |
104 | |
105 | // constructors: |
106 | QWeakPointer(); |
107 | QWeakPointer(const QWeakPointer<T> &other); |
108 | QWeakPointer(const QSharedPointer<T> &other); |
109 | |
110 | ~QWeakPointer(); |
111 | |
112 | QWeakPointer<T> operator=(const QWeakPointer<T> &other); |
113 | QWeakPointer<T> operator=(const QSharedPointer<T> &other); |
114 | |
115 | QWeakPointer(const QObject *other); |
116 | QWeakPointer<T> operator=(const QObject *other); |
117 | |
118 | T *data() const; |
119 | void clear(); |
120 | |
121 | QSharedPointer<T> toStrongRef() const; |
122 | }; |
123 | |
124 | template<class T, class X> bool operator==(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2); |
125 | template<class T, class X> bool operator!=(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2); |
126 | template<class T, class X> bool operator==(const QSharedPointer<T> &ptr1, const X *ptr2); |
127 | template<class T, class X> bool operator!=(const QSharedPointer<T> &ptr1, const X *ptr2); |
128 | template<class T, class X> bool operator==(const T *ptr1, const QSharedPointer<X> &ptr2); |
129 | template<class T, class X> bool operator!=(const T *ptr1, const QSharedPointer<X> &ptr2); |
130 | template<class T, class X> bool operator==(const QWeakPointer<T> &ptr1, const QSharedPointer<X> &ptr2); |
131 | template<class T, class X> bool operator!=(const QWeakPointer<T> &ptr1, const QSharedPointer<X> &ptr2); |
132 | template<class T, class X> bool operator==(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2); |
133 | template<class T, class X> bool operator!=(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2); |
134 | |
135 | template <class X, class T> QSharedPointer<X> qSharedPointerCast(const QSharedPointer<T> &other); |
136 | template <class X, class T> QSharedPointer<X> qSharedPointerCast(const QWeakPointer<T> &other); |
137 | template <class X, class T> QSharedPointer<X> qSharedPointerDynamicCast(const QSharedPointer<T> &src); |
138 | template <class X, class T> QSharedPointer<X> qSharedPointerDynamicCast(const QWeakPointer<T> &src); |
139 | template <class X, class T> QSharedPointer<X> qSharedPointerConstCast(const QSharedPointer<T> &src); |
140 | template <class X, class T> QSharedPointer<X> qSharedPointerConstCast(const QWeakPointer<T> &src); |
141 | template <class X, class T> QSharedPointer<X> qSharedPointerObjectCast(const QSharedPointer<T> &src); |
142 | template <class X, class T> QSharedPointer<X> qSharedPointerObjectCast(const QWeakPointer<T> &src); |
143 | |
144 | template <class X, class T> QWeakPointer<X> qWeakPointerCast(const QWeakPointer<T> &src); |
145 | |
146 | QT_END_NAMESPACE |
147 | |
148 | QT_END_HEADER |
149 | |
150 | #endif // Q_QDOC |
151 | |
152 | #endif // QSHAREDPOINTER_H |
153 | |