Qt 4.8
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
50 # include <QtCore/qsharedpointer_impl.h>
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>
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
75  explicit QSharedPointer(T *ptr);
76  QSharedPointer(T *ptr, Deleter d);
77  QSharedPointer(const QSharedPointer<T> &other);
78  QSharedPointer(const QWeakPointer<T> &other);
79 
81 
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>
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 
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 
147 
149 
150 #endif // Q_QDOC
151 
152 #endif // QSHAREDPOINTER_H
double d
Definition: qnumeric_p.h:62
QSharedPointer< X > constCast() const
Performs a const_cast from this pointer&#39;s type to X and returns a QSharedPointer that shares the refe...
QSharedPointer< X > qSharedPointerConstCast(const QSharedPointer< T > &other)
Returns a shared pointer to the pointer held by other, cast to type X.
The QSharedPointer class holds a strong reference to a shared pointer.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
T & operator*() const
Provides access to the shared pointer&#39;s members.
bool operator!() const
Returns true if this object is null.
QWeakPointer< T > toWeakRef() const
Returns a weak reference object that shares the pointer referenced by this object.
bool operator!=(const QSharedPointer< T > &ptr1, const QSharedPointer< X > &ptr2)
Returns true if the pointer referenced by ptr1 is not the same pointer as that referenced by ptr2...
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QWeakPointer< X > qWeakPointerCast(const QWeakPointer< T > &src)
QSharedPointer< X > staticCast() const
Performs a static cast from this pointer&#39;s type to X and returns a QSharedPointer that shares the ref...
QSharedPointer< X > qSharedPointerDynamicCast(const QSharedPointer< T > &other)
Returns a shared pointer to the pointer held by other, using a dynamic cast to type X to obtain an in...
bool operator==(const QSharedPointer< T > &ptr1, const QSharedPointer< X > &ptr2)
Returns true if the pointer referenced by ptr1 is the same pointer as that referenced by ptr2...
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
~QSharedPointer()
Destroys this QSharedPointer object.
QSharedPointer< X > objectCast() const
Performs a qobject_cast() from this pointer&#39;s type to X and returns a QSharedPointer that shares the ...
T * operator->() const
Provides access to the shared pointer&#39;s members.
const T * ptr(const T &t)
T * data() const
Returns the value of the pointer referenced by this object.
QSharedPointer< X > dynamicCast() const
Performs a dynamic cast from this pointer&#39;s type to X and returns a QSharedPointer that shares the re...
QSharedPointer< X > qSharedPointerObjectCast(const QSharedPointer< T > &other)
The qSharedPointerObjectCast function is for casting a shared pointer.
void clear()
Clears this QSharedPointer object, dropping the reference that it may have had to the pointer...
QSharedPointer< X > qSharedPointerCast(const QSharedPointer< T > &other)
Returns a shared pointer to the pointer held by other, cast to type X.
QSharedPointer< T > & operator=(const QSharedPointer< T > &other)
Makes this object share other&#39;s pointer.
#define QT_END_HEADER
Definition: qglobal.h:137
QSharedPointer()
Creates a QSharedPointer that points to null (0).
bool isNull() const
Returns true if this object is holding a reference to a null pointer.
The QWeakPointer class holds a weak reference to a shared pointer.