Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/qml/ftw/qfinitestack_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 QFINITESTACK_P_H | - | ||||||
41 | #define QFINITESTACK_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 | - | |||||||
56 | QT_BEGIN_NAMESPACE | - | ||||||
57 | - | |||||||
58 | template<typename T> | - | ||||||
59 | struct QFiniteStack { | - | ||||||
60 | inline QFiniteStack(); | - | ||||||
61 | inline ~QFiniteStack(); | - | ||||||
62 | - | |||||||
63 | inline void deallocate(); | - | ||||||
64 | inline void allocate(int size); | - | ||||||
65 | - | |||||||
66 | inline int capacity() const { return _alloc; } executed 6 times by 1 test: return _alloc; Executed by:
| 6 | ||||||
67 | - | |||||||
68 | inline bool isEmpty() const; | - | ||||||
69 | inline const T &top() const; | - | ||||||
70 | inline T &top(); | - | ||||||
71 | inline void push(const T &o); | - | ||||||
72 | inline T pop(); | - | ||||||
73 | inline int count() const; | - | ||||||
74 | inline const T &at(int index) const; | - | ||||||
75 | inline T &operator[](int index); | - | ||||||
76 | private: | - | ||||||
77 | T *_array; | - | ||||||
78 | int _alloc; | - | ||||||
79 | int _size; | - | ||||||
80 | }; | - | ||||||
81 | - | |||||||
82 | template<typename T> | - | ||||||
83 | QFiniteStack<T>::QFiniteStack() | - | ||||||
84 | : _array(nullptr), _alloc(0), _size(0) | - | ||||||
85 | { | - | ||||||
86 | } executed 611792 times by 140 tests: end of block Executed by:
| 611792 | ||||||
87 | - | |||||||
88 | template<typename T> | - | ||||||
89 | QFiniteStack<T>::~QFiniteStack() | - | ||||||
90 | { | - | ||||||
91 | deallocate(); | - | ||||||
92 | } executed 611620 times by 140 tests: end of block Executed by:
| 611620 | ||||||
93 | - | |||||||
94 | template<typename T> | - | ||||||
95 | bool QFiniteStack<T>::isEmpty() const | - | ||||||
96 | { | - | ||||||
97 | return _size == 0; executed 1339942 times by 140 tests: return _size == 0; Executed by:
| 1339942 | ||||||
98 | } | - | ||||||
99 | - | |||||||
100 | template<typename T> | - | ||||||
101 | const T &QFiniteStack<T>::top() const | - | ||||||
102 | { | - | ||||||
103 | return _array[_size - 1]; never executed: return _array[_size - 1]; | 0 | ||||||
104 | } | - | ||||||
105 | - | |||||||
106 | template<typename T> | - | ||||||
107 | T &QFiniteStack<T>::top() | - | ||||||
108 | { | - | ||||||
109 | return _array[_size - 1]; executed 479826 times by 133 tests: return _array[_size - 1]; Executed by:
| 479826 | ||||||
110 | } | - | ||||||
111 | - | |||||||
112 | template<typename T> | - | ||||||
113 | void QFiniteStack<T>::push(const T &o) | - | ||||||
114 | { | - | ||||||
115 | Q_ASSERT(_size < _alloc); | - | ||||||
116 | if (QTypeInfo<T>::isComplex) {
| 479832-1063278 | ||||||
117 | new (_array + _size++) T(o); | - | ||||||
118 | } else { executed 1063278 times by 140 tests: end of block Executed by:
| 1063278 | ||||||
119 | _array[_size++] = o; | - | ||||||
120 | } executed 479832 times by 133 tests: end of block Executed by:
| 479832 | ||||||
121 | } | - | ||||||
122 | - | |||||||
123 | template<typename T> | - | ||||||
124 | T QFiniteStack<T>::pop() | - | ||||||
125 | { | - | ||||||
126 | Q_ASSERT(_size > 0); | - | ||||||
127 | --_size; | - | ||||||
128 | - | |||||||
129 | if (QTypeInfo<T>::isComplex) {
| 479816-553902 | ||||||
130 | T rv = _array[_size]; | - | ||||||
131 | (_array + _size)->~T(); | - | ||||||
132 | return rv; executed 553902 times by 122 tests: return rv; Executed by:
| 553902 | ||||||
133 | } else { | - | ||||||
134 | return _array[_size]; executed 479816 times by 133 tests: return _array[_size]; Executed by:
| 479816 | ||||||
135 | } | - | ||||||
136 | } | - | ||||||
137 | - | |||||||
138 | template<typename T> | - | ||||||
139 | int QFiniteStack<T>::count() const | - | ||||||
140 | { | - | ||||||
141 | return _size; executed 157510 times by 140 tests: return _size; Executed by:
| 157510 | ||||||
142 | } | - | ||||||
143 | - | |||||||
144 | template<typename T> | - | ||||||
145 | const T &QFiniteStack<T>::at(int index) const | - | ||||||
146 | { | - | ||||||
147 | return _array[index]; executed 16 times by 3 tests: return _array[index]; Executed by:
| 16 | ||||||
148 | } | - | ||||||
149 | - | |||||||
150 | template<typename T> | - | ||||||
151 | T &QFiniteStack<T>::operator[](int index) | - | ||||||
152 | { | - | ||||||
153 | return _array[index]; executed 5709 times by 8 tests: return _array[index]; Executed by:
| 5709 | ||||||
154 | } | - | ||||||
155 | - | |||||||
156 | template<typename T> | - | ||||||
157 | void QFiniteStack<T>::allocate(int size) | - | ||||||
158 | { | - | ||||||
159 | Q_ASSERT(_array == nullptr); | - | ||||||
160 | Q_ASSERT(_alloc == 0); | - | ||||||
161 | Q_ASSERT(_size == 0); | - | ||||||
162 | - | |||||||
163 | if (!size) return; executed 3202 times by 56 tests: return; Executed by:
| 3202-455648 | ||||||
164 | - | |||||||
165 | _array = (T *)malloc(size * sizeof(T)); | - | ||||||
166 | _alloc = size; | - | ||||||
167 | } executed 455648 times by 140 tests: end of block Executed by:
| 455648 | ||||||
168 | - | |||||||
169 | template<typename T> | - | ||||||
170 | void QFiniteStack<T>::deallocate() | - | ||||||
171 | { | - | ||||||
172 | if (QTypeInfo<T>::isComplex) {
| 305810 | ||||||
173 | T *i = _array + _size; | - | ||||||
174 | while (i != _array)
| 305810-509280 | ||||||
175 | (--i)->~T(); executed 509280 times by 140 tests: (--i)->~T(); Executed by:
| 509280 | ||||||
176 | } executed 305810 times by 140 tests: end of block Executed by:
| 305810 | ||||||
177 | - | |||||||
178 | free(_array); | - | ||||||
179 | - | |||||||
180 | _array = nullptr; | - | ||||||
181 | _alloc = 0; | - | ||||||
182 | _size = 0; | - | ||||||
183 | } executed 611620 times by 140 tests: end of block Executed by:
| 611620 | ||||||
184 | - | |||||||
185 | QT_END_NAMESPACE | - | ||||||
186 | - | |||||||
187 | #endif // QFINITESTACK_P_H | - | ||||||
188 | - | |||||||
Source code | Switch to Preprocessed file |