Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/qml/ftw/qqmlrefcount_p.h |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 QtQml 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 QQMLREFCOUNT_P_H | - | ||||||||||||
41 | #define QQMLREFCOUNT_P_H | - | ||||||||||||
42 | - | |||||||||||||
43 | // | - | ||||||||||||
44 | // W A R N I N G | - | ||||||||||||
45 | // ------------- | - | ||||||||||||
46 | // | - | ||||||||||||
47 | // This file is not part of the Qt API. It exists purely as an | - | ||||||||||||
48 | // implementation detail. This header file may change from version to | - | ||||||||||||
49 | // version without notice, or even be removed. | - | ||||||||||||
50 | // | - | ||||||||||||
51 | // We mean it. | - | ||||||||||||
52 | // | - | ||||||||||||
53 | - | |||||||||||||
54 | #include <QtCore/qglobal.h> | - | ||||||||||||
55 | #include <QtCore/qatomic.h> | - | ||||||||||||
56 | #include <private/qv4global_p.h> | - | ||||||||||||
57 | - | |||||||||||||
58 | QT_BEGIN_NAMESPACE | - | ||||||||||||
59 | - | |||||||||||||
60 | - | |||||||||||||
61 | class Q_QML_PRIVATE_EXPORT QQmlRefCount | - | ||||||||||||
62 | { | - | ||||||||||||
63 | public: | - | ||||||||||||
64 | inline QQmlRefCount(); | - | ||||||||||||
65 | inline virtual ~QQmlRefCount(); | - | ||||||||||||
66 | inline void addref(); | - | ||||||||||||
67 | inline void release(); | - | ||||||||||||
68 | inline int count() const; | - | ||||||||||||
69 | - | |||||||||||||
70 | protected: | - | ||||||||||||
71 | inline virtual void destroy(); | - | ||||||||||||
72 | - | |||||||||||||
73 | private: | - | ||||||||||||
74 | QAtomicInt refCount; | - | ||||||||||||
75 | }; | - | ||||||||||||
76 | - | |||||||||||||
77 | template<class T> | - | ||||||||||||
78 | class QQmlRefPointer | - | ||||||||||||
79 | { | - | ||||||||||||
80 | public: | - | ||||||||||||
81 | enum Mode { | - | ||||||||||||
82 | AddRef, | - | ||||||||||||
83 | Adopt | - | ||||||||||||
84 | }; | - | ||||||||||||
85 | inline QQmlRefPointer(); | - | ||||||||||||
86 | inline QQmlRefPointer(T *, Mode m = AddRef); | - | ||||||||||||
87 | inline QQmlRefPointer(const QQmlRefPointer<T> &); | - | ||||||||||||
88 | inline QQmlRefPointer(QQmlRefPointer<T> &&); | - | ||||||||||||
89 | inline ~QQmlRefPointer(); | - | ||||||||||||
90 | - | |||||||||||||
91 | inline QQmlRefPointer<T> &operator=(const QQmlRefPointer<T> &o); | - | ||||||||||||
92 | inline QQmlRefPointer<T> &operator=(QQmlRefPointer<T> &&o); | - | ||||||||||||
93 | - | |||||||||||||
94 | inline bool isNull() const { return !o; } executed 716408 times by 142 tests: return !o; Executed by:
| 716408 | ||||||||||||
95 | - | |||||||||||||
96 | inline T* operator->() const { return o; } executed 11793879 times by 149 tests: return o; Executed by:
| 11793879 | ||||||||||||
97 | inline T& operator*() const { return *o; } never executed: return *o; | 0 | ||||||||||||
98 | explicit inline operator bool() const { return o != nullptr; } executed 5641778 times by 142 tests: return o != nullptr; Executed by:
| 5641778 | ||||||||||||
99 | inline T* data() const { return o; } executed 918015 times by 143 tests: return o; Executed by:
| 918015 | ||||||||||||
100 | - | |||||||||||||
101 | inline QQmlRefPointer<T> &adopt(T *); | - | ||||||||||||
102 | - | |||||||||||||
103 | inline T* take() { T *res = o; o = nullptr; return res; } executed 9413362 times by 148 tests: return res; Executed by:
| 9413362 | ||||||||||||
104 | - | |||||||||||||
105 | private: | - | ||||||||||||
106 | T *o; | - | ||||||||||||
107 | }; | - | ||||||||||||
108 | - | |||||||||||||
109 | QQmlRefCount::QQmlRefCount() | - | ||||||||||||
110 | : refCount(1) | - | ||||||||||||
111 | { | - | ||||||||||||
112 | } executed 242955 times by 146 tests: end of block Executed by:
| 242955 | ||||||||||||
113 | - | |||||||||||||
114 | QQmlRefCount::~QQmlRefCount() | - | ||||||||||||
115 | { | - | ||||||||||||
116 | Q_ASSERT(refCount.load() == 0); | - | ||||||||||||
117 | } executed 200092 times by 144 tests: end of block Executed by:
| 200092 | ||||||||||||
118 | - | |||||||||||||
119 | void QQmlRefCount::addref() | - | ||||||||||||
120 | { | - | ||||||||||||
121 | Q_ASSERT(refCount.load() > 0); | - | ||||||||||||
122 | refCount.ref(); | - | ||||||||||||
123 | } executed 4738528 times by 146 tests: end of block Executed by:
| 4738528 | ||||||||||||
124 | - | |||||||||||||
125 | void QQmlRefCount::release() | - | ||||||||||||
126 | { | - | ||||||||||||
127 | Q_ASSERT(refCount.load() > 0); | - | ||||||||||||
128 | if (!refCount.deref())
| 198576-4760707 | ||||||||||||
129 | destroy(); executed 198576 times by 144 tests: destroy(); Executed by:
| 198576 | ||||||||||||
130 | } executed 4959283 times by 146 tests: end of block Executed by:
| 4959283 | ||||||||||||
131 | - | |||||||||||||
132 | int QQmlRefCount::count() const | - | ||||||||||||
133 | { | - | ||||||||||||
134 | return refCount.load(); executed 6668 times by 3 tests: return refCount.load(); Executed by:
| 6668 | ||||||||||||
135 | } | - | ||||||||||||
136 | - | |||||||||||||
137 | void QQmlRefCount::destroy() | - | ||||||||||||
138 | { | - | ||||||||||||
139 | delete this; | - | ||||||||||||
140 | } executed 247922 times by 144 tests: end of block Executed by:
| 247922 | ||||||||||||
141 | - | |||||||||||||
142 | template<class T> | - | ||||||||||||
143 | QQmlRefPointer<T>::QQmlRefPointer() | - | ||||||||||||
144 | : o(nullptr) | - | ||||||||||||
145 | { | - | ||||||||||||
146 | } executed 10772105 times by 154 tests: end of block Executed by:
| 10772105 | ||||||||||||
147 | - | |||||||||||||
148 | template<class T> | - | ||||||||||||
149 | QQmlRefPointer<T>::QQmlRefPointer(T *o, Mode m) | - | ||||||||||||
150 | : o(o) | - | ||||||||||||
151 | { | - | ||||||||||||
152 | if (m == AddRef && o)
| 45773-6528541 | ||||||||||||
153 | o->addref(); executed 3603760 times by 144 tests: o->addref(); Executed by:
| 3603760 | ||||||||||||
154 | } executed 6574294 times by 149 tests: end of block Executed by:
| 6574294 | ||||||||||||
155 | - | |||||||||||||
156 | template<class T> | - | ||||||||||||
157 | QQmlRefPointer<T>::QQmlRefPointer(const QQmlRefPointer<T> &other) | - | ||||||||||||
158 | : o(other.o) | - | ||||||||||||
159 | { | - | ||||||||||||
160 | if (o) o->addref(); executed 1153007 times by 143 tests: o->addref(); Executed by:
| 76909-1153007 | ||||||||||||
161 | } executed 1229916 times by 143 tests: end of block Executed by:
| 1229916 | ||||||||||||
162 | - | |||||||||||||
163 | template <class T> | - | ||||||||||||
164 | QQmlRefPointer<T>::QQmlRefPointer(QQmlRefPointer<T> &&other) | - | ||||||||||||
165 | : o(other.take()) | - | ||||||||||||
166 | { | - | ||||||||||||
167 | } executed 9413108 times by 148 tests: end of block Executed by:
| 9413108 | ||||||||||||
168 | - | |||||||||||||
169 | template<class T> | - | ||||||||||||
170 | QQmlRefPointer<T>::~QQmlRefPointer() | - | ||||||||||||
171 | { | - | ||||||||||||
172 | if (o) o->release(); executed 9326099 times by 149 tests: o->release(); Executed by:
| 9326080-18532414 | ||||||||||||
173 | } executed 27857095 times by 154 tests: end of block Executed by:
| 27857095 | ||||||||||||
174 | - | |||||||||||||
175 | template<class T> | - | ||||||||||||
176 | QQmlRefPointer<T> &QQmlRefPointer<T>::operator=(const QQmlRefPointer<T> &other) | - | ||||||||||||
177 | { | - | ||||||||||||
178 | if (other.o) other.o->addref(); executed 2392717 times by 142 tests: other.o->addref(); Executed by:
| 1016-2392717 | ||||||||||||
179 | if (o) o->release(); executed 49150 times by 142 tests: o->release(); Executed by:
| 49150-2344583 | ||||||||||||
180 | o = other.o; | - | ||||||||||||
181 | return *this; executed 2393733 times by 142 tests: return *this; Executed by:
| 2393733 | ||||||||||||
182 | } | - | ||||||||||||
183 | - | |||||||||||||
184 | template <class T> | - | ||||||||||||
185 | QQmlRefPointer<T> &QQmlRefPointer<T>::operator=(QQmlRefPointer<T> &&other) | - | ||||||||||||
186 | { | - | ||||||||||||
187 | QQmlRefPointer<T> m(std::move(other)); | - | ||||||||||||
188 | qSwap(o, m.o); | - | ||||||||||||
189 | return *this; executed 8090211 times by 148 tests: return *this; Executed by:
| 8090211 | ||||||||||||
190 | } | - | ||||||||||||
191 | - | |||||||||||||
192 | /*! | - | ||||||||||||
193 | Takes ownership of \a other. take() does *not* add a reference, as it assumes ownership | - | ||||||||||||
194 | of the callers reference of other. | - | ||||||||||||
195 | */ | - | ||||||||||||
196 | template<class T> | - | ||||||||||||
197 | QQmlRefPointer<T> &QQmlRefPointer<T>::adopt(T *other) | - | ||||||||||||
198 | { | - | ||||||||||||
199 | if (o) o->release(); never executed: o->release();
| 0-2463787 | ||||||||||||
200 | o = other; | - | ||||||||||||
201 | return *this; executed 2464073 times by 147 tests: return *this; Executed by:
| 2464073 | ||||||||||||
202 | } | - | ||||||||||||
203 | - | |||||||||||||
204 | QT_END_NAMESPACE | - | ||||||||||||
205 | - | |||||||||||||
206 | #endif // QQMLREFCOUNT_P_H | - | ||||||||||||
Source code | Switch to Preprocessed file |