QtCore/qsharedpointer.h Source File

qsharedpointer.h
Go to the documentation of this file.
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
51 #else
52 
54 
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 
114 
115  QWeakPointer(const QObject *other);
116  QWeakPointer<T> operator=(const QObject *other);
117 
118  T *data() const;
119  void clear();
120 
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 
147 
149 
150 #endif // Q_QDOC
151 
152 #endif // QSHAREDPOINTER_H
bool isNull() const
#define QT_END_NAMESPACE
Definition: qglobal.h:128
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
bool operator!() const
GLuint src
Definition: GLee.h:7190
QSharedPointer< T > toStrongRef() const
bool operator==(const Attribute &cA, const AttributeInstance< type > &cB)
This operator compares the two attributes and NOT their values.
Definition: node.h:577
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: GLee.h:880
Q_INLINE_TEMPLATE QWeakPointer< X > qWeakPointerCast(const QSharedPointer< T > &src)
QSharedPointer< X > qSharedPointerObjectCast(const QSharedPointer< T > &ptr)
bool operator!=(const QByteArray &a1, const QByteArray &a2)
Definition: qbytearray.h:533
QSharedPointer< X > qSharedPointerDynamicCast(const QSharedPointer< T > &ptr)
MBDLL_DECL Vector operator*(float f, const Vector &v)
Multiplies a float scalar value by a vector, the result is a vector.
Definition: math.h:575
QSharedPointer< X > qSharedPointerCast(const QSharedPointer< T > &ptr)
QWeakPointer & operator=(X *ptr)
QSharedPointer< X > qSharedPointerConstCast(const QSharedPointer< T > &ptr)
#define QT_END_HEADER
Definition: qglobal.h:142
T * data() const