Merge remote-tracking branch 'origin/master' into api_changes
[profile/ivi/qtbase.git] / src / corelib / tools / qsharedpointer.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
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
58 // These classes are here to fool qdoc into generating a better documentation
59
60 template <class T>
61 class QSharedPointer
62 {
63 public:
64     // basic accessor functions
65     T *data() const;
66     bool isNull() const;
67     operator bool() const;
68     bool operator!() const;
69     T &operator*() const;
70     T *operator ->() const;
71
72     // constructors
73     QSharedPointer();
74     explicit QSharedPointer(T *ptr);
75     QSharedPointer(T *ptr, Deleter d);
76     QSharedPointer(const QSharedPointer<T> &other);
77     QSharedPointer(const QWeakPointer<T> &other);
78
79     ~QSharedPointer() { }
80
81     QSharedPointer<T> &operator=(const QSharedPointer<T> &other);
82     QSharedPointer<T> &operator=(const QWeakPointer<T> &other);
83
84     QWeakPointer<T> toWeakRef() const;
85
86     void clear();
87
88     void reset();
89     void reset(T *t);
90     template <typename Deleter>
91     void reset(T *t, Deleter deleter);
92
93     // casts:
94     template <class X> QSharedPointer<X> staticCast() const;
95     template <class X> QSharedPointer<X> dynamicCast() const;
96     template <class X> QSharedPointer<X> constCast() const;
97     template <class X> QSharedPointer<X> objectCast() const;
98 };
99
100 template <class T>
101 class QWeakPointer
102 {
103 public:
104     // basic accessor functions
105     bool isNull() const;
106     operator bool() const;
107     bool operator!() const;
108
109     // constructors:
110     QWeakPointer();
111     QWeakPointer(const QWeakPointer<T> &other);
112     QWeakPointer(const QSharedPointer<T> &other);
113
114     ~QWeakPointer();
115
116     QWeakPointer<T> operator=(const QWeakPointer<T> &other);
117     QWeakPointer<T> operator=(const QSharedPointer<T> &other);
118
119     QWeakPointer(const QObject *other);
120     QWeakPointer<T> operator=(const QObject *other);
121
122     T *data() const;
123     void clear();
124
125     QSharedPointer<T> toStrongRef() const;
126 };
127
128 template<class T, class X> bool operator==(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2);
129 template<class T, class X> bool operator!=(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2);
130 template<class T, class X> bool operator==(const QSharedPointer<T> &ptr1, const X *ptr2);
131 template<class T, class X> bool operator!=(const QSharedPointer<T> &ptr1, const X *ptr2);
132 template<class T, class X> bool operator==(const T *ptr1, const QSharedPointer<X> &ptr2);
133 template<class T, class X> bool operator!=(const T *ptr1, const QSharedPointer<X> &ptr2);
134 template<class T, class X> bool operator==(const QWeakPointer<T> &ptr1, const QSharedPointer<X> &ptr2);
135 template<class T, class X> bool operator!=(const QWeakPointer<T> &ptr1, const QSharedPointer<X> &ptr2);
136 template<class T, class X> bool operator==(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2);
137 template<class T, class X> bool operator!=(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2);
138
139 template <class X, class T> QSharedPointer<X> qSharedPointerCast(const QSharedPointer<T> &other);
140 template <class X, class T> QSharedPointer<X> qSharedPointerCast(const QWeakPointer<T> &other);
141 template <class X, class T> QSharedPointer<X> qSharedPointerDynamicCast(const QSharedPointer<T> &src);
142 template <class X, class T> QSharedPointer<X> qSharedPointerDynamicCast(const QWeakPointer<T> &src);
143 template <class X, class T> QSharedPointer<X> qSharedPointerConstCast(const QSharedPointer<T> &src);
144 template <class X, class T> QSharedPointer<X> qSharedPointerConstCast(const QWeakPointer<T> &src);
145 template <class X, class T> QSharedPointer<X> qSharedPointerObjectCast(const QSharedPointer<T> &src);
146 template <class X, class T> QSharedPointer<X> qSharedPointerObjectCast(const QWeakPointer<T> &src);
147
148 template <class X, class T> QWeakPointer<X> qWeakPointerCast(const QWeakPointer<T> &src);
149
150 QT_END_NAMESPACE
151
152 QT_END_HEADER
153
154 #endif // Q_QDOC
155
156 #endif // QSHAREDPOINTER_H