Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qbitarray.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include "qbitarray.h" | - | ||||||||||||||||||
35 | #include <qalgorithms.h> | - | ||||||||||||||||||
36 | #include <qdatastream.h> | - | ||||||||||||||||||
37 | #include <qdebug.h> | - | ||||||||||||||||||
38 | #include <qendian.h> | - | ||||||||||||||||||
39 | #include <string.h> | - | ||||||||||||||||||
40 | - | |||||||||||||||||||
41 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
42 | - | |||||||||||||||||||
43 | /*! | - | ||||||||||||||||||
44 | \class QBitArray | - | ||||||||||||||||||
45 | \inmodule QtCore | - | ||||||||||||||||||
46 | \brief The QBitArray class provides an array of bits. | - | ||||||||||||||||||
47 | - | |||||||||||||||||||
48 | \ingroup tools | - | ||||||||||||||||||
49 | \ingroup shared | - | ||||||||||||||||||
50 | \reentrant | - | ||||||||||||||||||
51 | - | |||||||||||||||||||
52 | A QBitArray is an array that gives access to individual bits and | - | ||||||||||||||||||
53 | provides operators (\l{operator&()}{AND}, \l{operator|()}{OR}, | - | ||||||||||||||||||
54 | \l{operator^()}{XOR}, and \l{operator~()}{NOT}) that work on | - | ||||||||||||||||||
55 | entire arrays of bits. It uses \l{implicit sharing} (copy-on-write) | - | ||||||||||||||||||
56 | to reduce memory usage and to avoid the needless copying of data. | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | The following code constructs a QBitArray containing 200 bits | - | ||||||||||||||||||
59 | initialized to false (0): | - | ||||||||||||||||||
60 | - | |||||||||||||||||||
61 | \snippet code/src_corelib_tools_qbitarray.cpp 0 | - | ||||||||||||||||||
62 | - | |||||||||||||||||||
63 | To initialize the bits to true, either pass \c true as second | - | ||||||||||||||||||
64 | argument to the constructor, or call fill() later on. | - | ||||||||||||||||||
65 | - | |||||||||||||||||||
66 | QBitArray uses 0-based indexes, just like C++ arrays. To access | - | ||||||||||||||||||
67 | the bit at a particular index position, you can use operator[](). | - | ||||||||||||||||||
68 | On non-const bit arrays, operator[]() returns a reference to a | - | ||||||||||||||||||
69 | bit that can be used on the left side of an assignment. For | - | ||||||||||||||||||
70 | example: | - | ||||||||||||||||||
71 | - | |||||||||||||||||||
72 | \snippet code/src_corelib_tools_qbitarray.cpp 1 | - | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | For technical reasons, it is more efficient to use testBit() and | - | ||||||||||||||||||
75 | setBit() to access bits in the array than operator[](). For | - | ||||||||||||||||||
76 | example: | - | ||||||||||||||||||
77 | - | |||||||||||||||||||
78 | \snippet code/src_corelib_tools_qbitarray.cpp 2 | - | ||||||||||||||||||
79 | - | |||||||||||||||||||
80 | QBitArray supports \c{&} (\l{operator&()}{AND}), \c{|} | - | ||||||||||||||||||
81 | (\l{operator|()}{OR}), \c{^} (\l{operator^()}{XOR}), | - | ||||||||||||||||||
82 | \c{~} (\l{operator~()}{NOT}), as well as | - | ||||||||||||||||||
83 | \c{&=}, \c{|=}, and \c{^=}. These operators work in the same way | - | ||||||||||||||||||
84 | as the built-in C++ bitwise operators of the same name. For | - | ||||||||||||||||||
85 | example: | - | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | \snippet code/src_corelib_tools_qbitarray.cpp 3 | - | ||||||||||||||||||
88 | - | |||||||||||||||||||
89 | For historical reasons, QBitArray distinguishes between a null | - | ||||||||||||||||||
90 | bit array and an empty bit array. A \e null bit array is a bit | - | ||||||||||||||||||
91 | array that is initialized using QBitArray's default constructor. | - | ||||||||||||||||||
92 | An \e empty bit array is any bit array with size 0. A null bit | - | ||||||||||||||||||
93 | array is always empty, but an empty bit array isn't necessarily | - | ||||||||||||||||||
94 | null: | - | ||||||||||||||||||
95 | - | |||||||||||||||||||
96 | \snippet code/src_corelib_tools_qbitarray.cpp 4 | - | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | All functions except isNull() treat null bit arrays the same as | - | ||||||||||||||||||
99 | empty bit arrays; for example, QBitArray() compares equal to | - | ||||||||||||||||||
100 | QBitArray(0). We recommend that you always use isEmpty() and | - | ||||||||||||||||||
101 | avoid isNull(). | - | ||||||||||||||||||
102 | - | |||||||||||||||||||
103 | \sa QByteArray, QVector | - | ||||||||||||||||||
104 | */ | - | ||||||||||||||||||
105 | - | |||||||||||||||||||
106 | /*! | - | ||||||||||||||||||
107 | \fn QBitArray::QBitArray(QBitArray &&other) | - | ||||||||||||||||||
108 | - | |||||||||||||||||||
109 | Move-constructs a QBitArray instance, making it point at the same | - | ||||||||||||||||||
110 | object that \a other was pointing to. | - | ||||||||||||||||||
111 | - | |||||||||||||||||||
112 | \since 5.2 | - | ||||||||||||||||||
113 | */ | - | ||||||||||||||||||
114 | - | |||||||||||||||||||
115 | /*! \fn QBitArray::QBitArray() | - | ||||||||||||||||||
116 | - | |||||||||||||||||||
117 | Constructs an empty bit array. | - | ||||||||||||||||||
118 | - | |||||||||||||||||||
119 | \sa isEmpty() | - | ||||||||||||||||||
120 | */ | - | ||||||||||||||||||
121 | - | |||||||||||||||||||
122 | /* | - | ||||||||||||||||||
123 | * QBitArray construction note: | - | ||||||||||||||||||
124 | * | - | ||||||||||||||||||
125 | * We overallocate the byte array by 1 byte. The first user bit is at | - | ||||||||||||||||||
126 | * d.data()[1]. On the extra first byte, we store the difference between the | - | ||||||||||||||||||
127 | * number of bits in the byte array (including this byte) and the number of | - | ||||||||||||||||||
128 | * bits in the bit array. Therefore, it's always a number between 8 and 15. | - | ||||||||||||||||||
129 | * | - | ||||||||||||||||||
130 | * This allows for fast calculation of the bit array size: | - | ||||||||||||||||||
131 | * inline int size() const { return (d.size() << 3) - *d.constData(); } | - | ||||||||||||||||||
132 | * | - | ||||||||||||||||||
133 | * Note: for an array of zero size, *d.constData() is the QByteArray implicit NUL. | - | ||||||||||||||||||
134 | */ | - | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | /*! | - | ||||||||||||||||||
137 | Constructs a bit array containing \a size bits. The bits are | - | ||||||||||||||||||
138 | initialized with \a value, which defaults to false (0). | - | ||||||||||||||||||
139 | */ | - | ||||||||||||||||||
140 | QBitArray::QBitArray(int size, bool value) | - | ||||||||||||||||||
141 | : d(size <= 0 ? 0 : 1 + (size + 7)/8, Qt::Uninitialized) | - | ||||||||||||||||||
142 | { | - | ||||||||||||||||||
143 | Q_ASSERT_X(size >= 0, "QBitArray::QBitArray", "Size must be greater than or equal to 0."); | - | ||||||||||||||||||
144 | if (size <= 0)
| 303-16972 | ||||||||||||||||||
145 | return; executed 303 times by 6 tests: return; Executed by:
| 303 | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | uchar* c = reinterpret_cast<uchar*>(d.data()); | - | ||||||||||||||||||
148 | memset(c + 1, value ? 0xff : 0, d.size() - 1); | - | ||||||||||||||||||
149 | *c = d.size()*8 - size; | - | ||||||||||||||||||
150 | if (value && size && size % 8)
| 0-12933 | ||||||||||||||||||
151 | *(c+1+size/8) &= (1 << (size%8)) - 1; executed 3532 times by 4 tests: *(c+1+size/8) &= (1 << (size%8)) - 1; Executed by:
| 3532 | ||||||||||||||||||
152 | } executed 16972 times by 29 tests: end of block Executed by:
| 16972 | ||||||||||||||||||
153 | - | |||||||||||||||||||
154 | /*! \fn int QBitArray::size() const | - | ||||||||||||||||||
155 | - | |||||||||||||||||||
156 | Returns the number of bits stored in the bit array. | - | ||||||||||||||||||
157 | - | |||||||||||||||||||
158 | \sa resize() | - | ||||||||||||||||||
159 | */ | - | ||||||||||||||||||
160 | - | |||||||||||||||||||
161 | /*! \fn int QBitArray::count() const | - | ||||||||||||||||||
162 | - | |||||||||||||||||||
163 | Same as size(). | - | ||||||||||||||||||
164 | */ | - | ||||||||||||||||||
165 | - | |||||||||||||||||||
166 | /*! | - | ||||||||||||||||||
167 | If \a on is true, this function returns the number of | - | ||||||||||||||||||
168 | 1-bits stored in the bit array; otherwise the number | - | ||||||||||||||||||
169 | of 0-bits is returned. | - | ||||||||||||||||||
170 | */ | - | ||||||||||||||||||
171 | int QBitArray::count(bool on) const | - | ||||||||||||||||||
172 | { | - | ||||||||||||||||||
173 | int numBits = 0; | - | ||||||||||||||||||
174 | const quint8 *bits = reinterpret_cast<const quint8 *>(d.data()) + 1; | - | ||||||||||||||||||
175 | - | |||||||||||||||||||
176 | // the loops below will try to read from *end | - | ||||||||||||||||||
177 | // it's the QByteArray implicit NUL, so it will not change the bit count | - | ||||||||||||||||||
178 | const quint8 *const end = reinterpret_cast<const quint8 *>(d.end()); | - | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | while (bits + 7 <= end) {
| 16147-499980 | ||||||||||||||||||
181 | quint64 v = qFromUnaligned<quint64>(bits); | - | ||||||||||||||||||
182 | bits += 8; | - | ||||||||||||||||||
183 | numBits += int(qPopulationCount(v)); | - | ||||||||||||||||||
184 | } executed 499980 times by 1 test: end of block Executed by:
| 499980 | ||||||||||||||||||
185 | if (bits + 3 <= end) {
| 8041-8106 | ||||||||||||||||||
186 | quint32 v = qFromUnaligned<quint32>(bits); | - | ||||||||||||||||||
187 | bits += 4; | - | ||||||||||||||||||
188 | numBits += int(qPopulationCount(v)); | - | ||||||||||||||||||
189 | } executed 8106 times by 1 test: end of block Executed by:
| 8106 | ||||||||||||||||||
190 | if (bits + 1 < end) {
| 4038-12109 | ||||||||||||||||||
191 | quint16 v = qFromUnaligned<quint16>(bits); | - | ||||||||||||||||||
192 | bits += 2; | - | ||||||||||||||||||
193 | numBits += int(qPopulationCount(v)); | - | ||||||||||||||||||
194 | } executed 4038 times by 1 test: end of block Executed by:
| 4038 | ||||||||||||||||||
195 | if (bits < end)
| 4069-12078 | ||||||||||||||||||
196 | numBits += int(qPopulationCount(bits[0])); executed 4069 times by 2 tests: numBits += int(qPopulationCount(bits[0])); Executed by:
| 4069 | ||||||||||||||||||
197 | - | |||||||||||||||||||
198 | return on ? numBits : size() - numBits; executed 16147 times by 2 tests: return on ? numBits : size() - numBits; Executed by:
| 8073-16147 | ||||||||||||||||||
199 | } | - | ||||||||||||||||||
200 | - | |||||||||||||||||||
201 | /*! | - | ||||||||||||||||||
202 | Resizes the bit array to \a size bits. | - | ||||||||||||||||||
203 | - | |||||||||||||||||||
204 | If \a size is greater than the current size, the bit array is | - | ||||||||||||||||||
205 | extended to make it \a size bits with the extra bits added to the | - | ||||||||||||||||||
206 | end. The new bits are initialized to false (0). | - | ||||||||||||||||||
207 | - | |||||||||||||||||||
208 | If \a size is less than the current size, bits are removed from | - | ||||||||||||||||||
209 | the end. | - | ||||||||||||||||||
210 | - | |||||||||||||||||||
211 | \sa size() | - | ||||||||||||||||||
212 | */ | - | ||||||||||||||||||
213 | void QBitArray::resize(int size) | - | ||||||||||||||||||
214 | { | - | ||||||||||||||||||
215 | if (!size) {
| 52-4482 | ||||||||||||||||||
216 | d.resize(0); | - | ||||||||||||||||||
217 | } else { executed 52 times by 3 tests: end of block Executed by:
| 52 | ||||||||||||||||||
218 | int s = d.size(); | - | ||||||||||||||||||
219 | d.resize(1 + (size+7)/8); | - | ||||||||||||||||||
220 | uchar* c = reinterpret_cast<uchar*>(d.data()); | - | ||||||||||||||||||
221 | if (size > (s << 3))
| 405-4077 | ||||||||||||||||||
222 | memset(c + s, 0, d.size() - s); executed 405 times by 10 tests: memset(c + s, 0, d.size() - s); Executed by:
| 405 | ||||||||||||||||||
223 | else if ( size % 8)
| 514-3563 | ||||||||||||||||||
224 | *(c+1+size/8) &= (1 << (size%8)) - 1; executed 3563 times by 7 tests: *(c+1+size/8) &= (1 << (size%8)) - 1; Executed by:
| 3563 | ||||||||||||||||||
225 | *c = d.size()*8 - size; | - | ||||||||||||||||||
226 | } executed 4482 times by 11 tests: end of block Executed by:
| 4482 | ||||||||||||||||||
227 | } | - | ||||||||||||||||||
228 | - | |||||||||||||||||||
229 | /*! \fn bool QBitArray::isEmpty() const | - | ||||||||||||||||||
230 | - | |||||||||||||||||||
231 | Returns \c true if this bit array has size 0; otherwise returns | - | ||||||||||||||||||
232 | false. | - | ||||||||||||||||||
233 | - | |||||||||||||||||||
234 | \sa size() | - | ||||||||||||||||||
235 | */ | - | ||||||||||||||||||
236 | - | |||||||||||||||||||
237 | /*! \fn bool QBitArray::isNull() const | - | ||||||||||||||||||
238 | - | |||||||||||||||||||
239 | Returns \c true if this bit array is null; otherwise returns \c false. | - | ||||||||||||||||||
240 | - | |||||||||||||||||||
241 | Example: | - | ||||||||||||||||||
242 | \snippet code/src_corelib_tools_qbitarray.cpp 5 | - | ||||||||||||||||||
243 | - | |||||||||||||||||||
244 | Qt makes a distinction between null bit arrays and empty bit | - | ||||||||||||||||||
245 | arrays for historical reasons. For most applications, what | - | ||||||||||||||||||
246 | matters is whether or not a bit array contains any data, | - | ||||||||||||||||||
247 | and this can be determined using isEmpty(). | - | ||||||||||||||||||
248 | - | |||||||||||||||||||
249 | \sa isEmpty() | - | ||||||||||||||||||
250 | */ | - | ||||||||||||||||||
251 | - | |||||||||||||||||||
252 | /*! \fn bool QBitArray::fill(bool value, int size = -1) | - | ||||||||||||||||||
253 | - | |||||||||||||||||||
254 | Sets every bit in the bit array to \a value, returning true if successful; | - | ||||||||||||||||||
255 | otherwise returns \c false. If \a size is different from -1 (the default), | - | ||||||||||||||||||
256 | the bit array is resized to \a size beforehand. | - | ||||||||||||||||||
257 | - | |||||||||||||||||||
258 | Example: | - | ||||||||||||||||||
259 | \snippet code/src_corelib_tools_qbitarray.cpp 6 | - | ||||||||||||||||||
260 | - | |||||||||||||||||||
261 | \sa resize() | - | ||||||||||||||||||
262 | */ | - | ||||||||||||||||||
263 | - | |||||||||||||||||||
264 | /*! | - | ||||||||||||||||||
265 | \overload | - | ||||||||||||||||||
266 | - | |||||||||||||||||||
267 | Sets bits at index positions \a begin up to (but not including) \a end | - | ||||||||||||||||||
268 | to \a value. | - | ||||||||||||||||||
269 | - | |||||||||||||||||||
270 | \a begin must be a valid index position in the bit array | - | ||||||||||||||||||
271 | (0 <= \a begin < size()). | - | ||||||||||||||||||
272 | - | |||||||||||||||||||
273 | \a end must be either a valid index position or equal to size(), in | - | ||||||||||||||||||
274 | which case the fill operation runs until the end of the array | - | ||||||||||||||||||
275 | (0 <= \a end <= size()). | - | ||||||||||||||||||
276 | - | |||||||||||||||||||
277 | Example: | - | ||||||||||||||||||
278 | \snippet code/src_corelib_tools_qbitarray.cpp 15 | - | ||||||||||||||||||
279 | */ | - | ||||||||||||||||||
280 | - | |||||||||||||||||||
281 | void QBitArray::fill(bool value, int begin, int end) | - | ||||||||||||||||||
282 | { | - | ||||||||||||||||||
283 | while (begin < end && begin & 0x7)
| 56-492 | ||||||||||||||||||
284 | setBit(begin++, value); executed 390 times by 1 test: setBit(begin++, value); Executed by:
| 390 | ||||||||||||||||||
285 | int len = end - begin; | - | ||||||||||||||||||
286 | if (len <= 0)
| 56-102 | ||||||||||||||||||
287 | return; executed 56 times by 1 test: return; Executed by:
| 56 | ||||||||||||||||||
288 | int s = len & ~0x7; | - | ||||||||||||||||||
289 | uchar *c = reinterpret_cast<uchar*>(d.data()); | - | ||||||||||||||||||
290 | memset(c + (begin >> 3) + 1, value ? 0xff : 0, s >> 3); | - | ||||||||||||||||||
291 | begin += s; | - | ||||||||||||||||||
292 | while (begin < end)
| 102-344 | ||||||||||||||||||
293 | setBit(begin++, value); executed 344 times by 1 test: setBit(begin++, value); Executed by:
| 344 | ||||||||||||||||||
294 | } executed 102 times by 1 test: end of block Executed by:
| 102 | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | /*! \fn bool QBitArray::isDetached() const | - | ||||||||||||||||||
297 | - | |||||||||||||||||||
298 | \internal | - | ||||||||||||||||||
299 | */ | - | ||||||||||||||||||
300 | - | |||||||||||||||||||
301 | /*! \fn void QBitArray::detach() | - | ||||||||||||||||||
302 | - | |||||||||||||||||||
303 | \internal | - | ||||||||||||||||||
304 | */ | - | ||||||||||||||||||
305 | - | |||||||||||||||||||
306 | /*! \fn void QBitArray::clear() | - | ||||||||||||||||||
307 | - | |||||||||||||||||||
308 | Clears the contents of the bit array and makes it empty. | - | ||||||||||||||||||
309 | - | |||||||||||||||||||
310 | \sa resize(), isEmpty() | - | ||||||||||||||||||
311 | */ | - | ||||||||||||||||||
312 | - | |||||||||||||||||||
313 | /*! \fn void QBitArray::truncate(int pos) | - | ||||||||||||||||||
314 | - | |||||||||||||||||||
315 | Truncates the bit array at index position \a pos. | - | ||||||||||||||||||
316 | - | |||||||||||||||||||
317 | If \a pos is beyond the end of the array, nothing happens. | - | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | \sa resize() | - | ||||||||||||||||||
320 | */ | - | ||||||||||||||||||
321 | - | |||||||||||||||||||
322 | /*! \fn bool QBitArray::toggleBit(int i) | - | ||||||||||||||||||
323 | - | |||||||||||||||||||
324 | Inverts the value of the bit at index position \a i, returning the | - | ||||||||||||||||||
325 | previous value of that bit as either true (if it was set) or false (if | - | ||||||||||||||||||
326 | it was unset). | - | ||||||||||||||||||
327 | - | |||||||||||||||||||
328 | If the previous value was 0, the new value will be 1. If the | - | ||||||||||||||||||
329 | previous value was 1, the new value will be 0. | - | ||||||||||||||||||
330 | - | |||||||||||||||||||
331 | \a i must be a valid index position in the bit array (i.e., 0 <= | - | ||||||||||||||||||
332 | \a i < size()). | - | ||||||||||||||||||
333 | - | |||||||||||||||||||
334 | \sa setBit(), clearBit() | - | ||||||||||||||||||
335 | */ | - | ||||||||||||||||||
336 | - | |||||||||||||||||||
337 | /*! \fn bool QBitArray::testBit(int i) const | - | ||||||||||||||||||
338 | - | |||||||||||||||||||
339 | Returns \c true if the bit at index position \a i is 1; otherwise | - | ||||||||||||||||||
340 | returns \c false. | - | ||||||||||||||||||
341 | - | |||||||||||||||||||
342 | \a i must be a valid index position in the bit array (i.e., 0 <= | - | ||||||||||||||||||
343 | \a i < size()). | - | ||||||||||||||||||
344 | - | |||||||||||||||||||
345 | \sa setBit(), clearBit() | - | ||||||||||||||||||
346 | */ | - | ||||||||||||||||||
347 | - | |||||||||||||||||||
348 | /*! \fn bool QBitArray::setBit(int i) | - | ||||||||||||||||||
349 | - | |||||||||||||||||||
350 | Sets the bit at index position \a i to 1. | - | ||||||||||||||||||
351 | - | |||||||||||||||||||
352 | \a i must be a valid index position in the bit array (i.e., 0 <= | - | ||||||||||||||||||
353 | \a i < size()). | - | ||||||||||||||||||
354 | - | |||||||||||||||||||
355 | \sa clearBit(), toggleBit() | - | ||||||||||||||||||
356 | */ | - | ||||||||||||||||||
357 | - | |||||||||||||||||||
358 | /*! \fn void QBitArray::setBit(int i, bool value) | - | ||||||||||||||||||
359 | - | |||||||||||||||||||
360 | \overload | - | ||||||||||||||||||
361 | - | |||||||||||||||||||
362 | Sets the bit at index position \a i to \a value. | - | ||||||||||||||||||
363 | */ | - | ||||||||||||||||||
364 | - | |||||||||||||||||||
365 | /*! \fn void QBitArray::clearBit(int i) | - | ||||||||||||||||||
366 | - | |||||||||||||||||||
367 | Sets the bit at index position \a i to 0. | - | ||||||||||||||||||
368 | - | |||||||||||||||||||
369 | \a i must be a valid index position in the bit array (i.e., 0 <= | - | ||||||||||||||||||
370 | \a i < size()). | - | ||||||||||||||||||
371 | - | |||||||||||||||||||
372 | \sa setBit(), toggleBit() | - | ||||||||||||||||||
373 | */ | - | ||||||||||||||||||
374 | - | |||||||||||||||||||
375 | /*! \fn bool QBitArray::at(int i) const | - | ||||||||||||||||||
376 | - | |||||||||||||||||||
377 | Returns the value of the bit at index position \a i. | - | ||||||||||||||||||
378 | - | |||||||||||||||||||
379 | \a i must be a valid index position in the bit array (i.e., 0 <= | - | ||||||||||||||||||
380 | \a i < size()). | - | ||||||||||||||||||
381 | - | |||||||||||||||||||
382 | \sa operator[]() | - | ||||||||||||||||||
383 | */ | - | ||||||||||||||||||
384 | - | |||||||||||||||||||
385 | /*! \fn QBitRef QBitArray::operator[](int i) | - | ||||||||||||||||||
386 | - | |||||||||||||||||||
387 | Returns the bit at index position \a i as a modifiable reference. | - | ||||||||||||||||||
388 | - | |||||||||||||||||||
389 | \a i must be a valid index position in the bit array (i.e., 0 <= | - | ||||||||||||||||||
390 | \a i < size()). | - | ||||||||||||||||||
391 | - | |||||||||||||||||||
392 | Example: | - | ||||||||||||||||||
393 | \snippet code/src_corelib_tools_qbitarray.cpp 7 | - | ||||||||||||||||||
394 | - | |||||||||||||||||||
395 | The return value is of type QBitRef, a helper class for QBitArray. | - | ||||||||||||||||||
396 | When you get an object of type QBitRef, you can assign to | - | ||||||||||||||||||
397 | it, and the assignment will apply to the bit in the QBitArray | - | ||||||||||||||||||
398 | from which you got the reference. | - | ||||||||||||||||||
399 | - | |||||||||||||||||||
400 | The functions testBit(), setBit(), and clearBit() are slightly | - | ||||||||||||||||||
401 | faster. | - | ||||||||||||||||||
402 | - | |||||||||||||||||||
403 | \sa at(), testBit(), setBit(), clearBit() | - | ||||||||||||||||||
404 | */ | - | ||||||||||||||||||
405 | - | |||||||||||||||||||
406 | /*! \fn bool QBitArray::operator[](int i) const | - | ||||||||||||||||||
407 | - | |||||||||||||||||||
408 | \overload | - | ||||||||||||||||||
409 | */ | - | ||||||||||||||||||
410 | - | |||||||||||||||||||
411 | /*! \fn QBitRef QBitArray::operator[](uint i) | - | ||||||||||||||||||
412 | - | |||||||||||||||||||
413 | \overload | - | ||||||||||||||||||
414 | */ | - | ||||||||||||||||||
415 | - | |||||||||||||||||||
416 | /*! \fn bool QBitArray::operator[](uint i) const | - | ||||||||||||||||||
417 | - | |||||||||||||||||||
418 | \overload | - | ||||||||||||||||||
419 | */ | - | ||||||||||||||||||
420 | - | |||||||||||||||||||
421 | /*! \fn QBitArray::QBitArray(const QBitArray &other) | - | ||||||||||||||||||
422 | - | |||||||||||||||||||
423 | Constructs a copy of \a other. | - | ||||||||||||||||||
424 | - | |||||||||||||||||||
425 | This operation takes \l{constant time}, because QBitArray is | - | ||||||||||||||||||
426 | \l{implicitly shared}. This makes returning a QBitArray from a | - | ||||||||||||||||||
427 | function very fast. If a shared instance is modified, it will be | - | ||||||||||||||||||
428 | copied (copy-on-write), and that takes \l{linear time}. | - | ||||||||||||||||||
429 | - | |||||||||||||||||||
430 | \sa operator=() | - | ||||||||||||||||||
431 | */ | - | ||||||||||||||||||
432 | - | |||||||||||||||||||
433 | /*! \fn QBitArray &QBitArray::operator=(const QBitArray &other) | - | ||||||||||||||||||
434 | - | |||||||||||||||||||
435 | Assigns \a other to this bit array and returns a reference to | - | ||||||||||||||||||
436 | this bit array. | - | ||||||||||||||||||
437 | */ | - | ||||||||||||||||||
438 | - | |||||||||||||||||||
439 | /*! \fn QBitArray &QBitArray::operator=(QBitArray &&other) | - | ||||||||||||||||||
440 | \since 5.2 | - | ||||||||||||||||||
441 | - | |||||||||||||||||||
442 | Moves \a other to this bit array and returns a reference to | - | ||||||||||||||||||
443 | this bit array. | - | ||||||||||||||||||
444 | */ | - | ||||||||||||||||||
445 | - | |||||||||||||||||||
446 | /*! \fn void QBitArray::swap(QBitArray &other) | - | ||||||||||||||||||
447 | \since 4.8 | - | ||||||||||||||||||
448 | - | |||||||||||||||||||
449 | Swaps bit array \a other with this bit array. This operation is very | - | ||||||||||||||||||
450 | fast and never fails. | - | ||||||||||||||||||
451 | */ | - | ||||||||||||||||||
452 | - | |||||||||||||||||||
453 | /*! \fn bool QBitArray::operator==(const QBitArray &other) const | - | ||||||||||||||||||
454 | - | |||||||||||||||||||
455 | Returns \c true if \a other is equal to this bit array; otherwise | - | ||||||||||||||||||
456 | returns \c false. | - | ||||||||||||||||||
457 | - | |||||||||||||||||||
458 | \sa operator!=() | - | ||||||||||||||||||
459 | */ | - | ||||||||||||||||||
460 | - | |||||||||||||||||||
461 | /*! \fn bool QBitArray::operator!=(const QBitArray &other) const | - | ||||||||||||||||||
462 | - | |||||||||||||||||||
463 | Returns \c true if \a other is not equal to this bit array; | - | ||||||||||||||||||
464 | otherwise returns \c false. | - | ||||||||||||||||||
465 | - | |||||||||||||||||||
466 | \sa operator==() | - | ||||||||||||||||||
467 | */ | - | ||||||||||||||||||
468 | - | |||||||||||||||||||
469 | /*! | - | ||||||||||||||||||
470 | Performs the AND operation between all bits in this bit array and | - | ||||||||||||||||||
471 | \a other. Assigns the result to this bit array, and returns a | - | ||||||||||||||||||
472 | reference to it. | - | ||||||||||||||||||
473 | - | |||||||||||||||||||
474 | The result has the length of the longest of the two bit arrays, | - | ||||||||||||||||||
475 | with any missing bits (if one array is shorter than the other) | - | ||||||||||||||||||
476 | taken to be 0. | - | ||||||||||||||||||
477 | - | |||||||||||||||||||
478 | Example: | - | ||||||||||||||||||
479 | \snippet code/src_corelib_tools_qbitarray.cpp 8 | - | ||||||||||||||||||
480 | - | |||||||||||||||||||
481 | \sa operator&(), operator|=(), operator^=(), operator~() | - | ||||||||||||||||||
482 | */ | - | ||||||||||||||||||
483 | - | |||||||||||||||||||
484 | QBitArray &QBitArray::operator&=(const QBitArray &other) | - | ||||||||||||||||||
485 | { | - | ||||||||||||||||||
486 | resize(qMax(size(), other.size())); | - | ||||||||||||||||||
487 | uchar *a1 = reinterpret_cast<uchar*>(d.data()) + 1; | - | ||||||||||||||||||
488 | const uchar *a2 = reinterpret_cast<const uchar*>(other.d.constData()) + 1; | - | ||||||||||||||||||
489 | int n = other.d.size() -1 ; | - | ||||||||||||||||||
490 | int p = d.size() - 1 - n; | - | ||||||||||||||||||
491 | while (n-- > 0)
| 8-9 | ||||||||||||||||||
492 | *a1++ &= *a2++; executed 9 times by 1 test: *a1++ &= *a2++; Executed by:
| 9 | ||||||||||||||||||
493 | while (p-- > 0)
| 4-8 | ||||||||||||||||||
494 | *a1++ = 0; executed 4 times by 1 test: *a1++ = 0; Executed by:
| 4 | ||||||||||||||||||
495 | return *this; executed 8 times by 1 test: return *this; Executed by:
| 8 | ||||||||||||||||||
496 | } | - | ||||||||||||||||||
497 | - | |||||||||||||||||||
498 | /*! | - | ||||||||||||||||||
499 | Performs the OR operation between all bits in this bit array and | - | ||||||||||||||||||
500 | \a other. Assigns the result to this bit array, and returns a | - | ||||||||||||||||||
501 | reference to it. | - | ||||||||||||||||||
502 | - | |||||||||||||||||||
503 | The result has the length of the longest of the two bit arrays, | - | ||||||||||||||||||
504 | with any missing bits (if one array is shorter than the other) | - | ||||||||||||||||||
505 | taken to be 0. | - | ||||||||||||||||||
506 | - | |||||||||||||||||||
507 | Example: | - | ||||||||||||||||||
508 | \snippet code/src_corelib_tools_qbitarray.cpp 9 | - | ||||||||||||||||||
509 | - | |||||||||||||||||||
510 | \sa operator|(), operator&=(), operator^=(), operator~() | - | ||||||||||||||||||
511 | */ | - | ||||||||||||||||||
512 | - | |||||||||||||||||||
513 | QBitArray &QBitArray::operator|=(const QBitArray &other) | - | ||||||||||||||||||
514 | { | - | ||||||||||||||||||
515 | resize(qMax(size(), other.size())); | - | ||||||||||||||||||
516 | uchar *a1 = reinterpret_cast<uchar*>(d.data()) + 1; | - | ||||||||||||||||||
517 | const uchar *a2 = reinterpret_cast<const uchar *>(other.d.constData()) + 1; | - | ||||||||||||||||||
518 | int n = other.d.size() - 1; | - | ||||||||||||||||||
519 | while (n-- > 0)
| 8 | ||||||||||||||||||
520 | *a1++ |= *a2++; executed 8 times by 1 test: *a1++ |= *a2++; Executed by:
| 8 | ||||||||||||||||||
521 | return *this; executed 8 times by 1 test: return *this; Executed by:
| 8 | ||||||||||||||||||
522 | } | - | ||||||||||||||||||
523 | - | |||||||||||||||||||
524 | /*! | - | ||||||||||||||||||
525 | Performs the XOR operation between all bits in this bit array and | - | ||||||||||||||||||
526 | \a other. Assigns the result to this bit array, and returns a | - | ||||||||||||||||||
527 | reference to it. | - | ||||||||||||||||||
528 | - | |||||||||||||||||||
529 | The result has the length of the longest of the two bit arrays, | - | ||||||||||||||||||
530 | with any missing bits (if one array is shorter than the other) | - | ||||||||||||||||||
531 | taken to be 0. | - | ||||||||||||||||||
532 | - | |||||||||||||||||||
533 | Example: | - | ||||||||||||||||||
534 | \snippet code/src_corelib_tools_qbitarray.cpp 10 | - | ||||||||||||||||||
535 | - | |||||||||||||||||||
536 | \sa operator^(), operator&=(), operator|=(), operator~() | - | ||||||||||||||||||
537 | */ | - | ||||||||||||||||||
538 | - | |||||||||||||||||||
539 | QBitArray &QBitArray::operator^=(const QBitArray &other) | - | ||||||||||||||||||
540 | { | - | ||||||||||||||||||
541 | resize(qMax(size(), other.size())); | - | ||||||||||||||||||
542 | uchar *a1 = reinterpret_cast<uchar*>(d.data()) + 1; | - | ||||||||||||||||||
543 | const uchar *a2 = reinterpret_cast<const uchar *>(other.d.constData()) + 1; | - | ||||||||||||||||||
544 | int n = other.d.size() - 1; | - | ||||||||||||||||||
545 | while (n-- > 0)
| 8-9 | ||||||||||||||||||
546 | *a1++ ^= *a2++; executed 9 times by 1 test: *a1++ ^= *a2++; Executed by:
| 9 | ||||||||||||||||||
547 | return *this; executed 8 times by 1 test: return *this; Executed by:
| 8 | ||||||||||||||||||
548 | } | - | ||||||||||||||||||
549 | - | |||||||||||||||||||
550 | /*! | - | ||||||||||||||||||
551 | Returns a bit array that contains the inverted bits of this bit | - | ||||||||||||||||||
552 | array. | - | ||||||||||||||||||
553 | - | |||||||||||||||||||
554 | Example: | - | ||||||||||||||||||
555 | \snippet code/src_corelib_tools_qbitarray.cpp 11 | - | ||||||||||||||||||
556 | - | |||||||||||||||||||
557 | \sa operator&(), operator|(), operator^() | - | ||||||||||||||||||
558 | */ | - | ||||||||||||||||||
559 | - | |||||||||||||||||||
560 | QBitArray QBitArray::operator~() const | - | ||||||||||||||||||
561 | { | - | ||||||||||||||||||
562 | int sz = size(); | - | ||||||||||||||||||
563 | QBitArray a(sz); | - | ||||||||||||||||||
564 | const uchar *a1 = reinterpret_cast<const uchar *>(d.constData()) + 1; | - | ||||||||||||||||||
565 | uchar *a2 = reinterpret_cast<uchar*>(a.d.data()) + 1; | - | ||||||||||||||||||
566 | int n = d.size() - 1; | - | ||||||||||||||||||
567 | - | |||||||||||||||||||
568 | while (n-- > 0)
| 13 | ||||||||||||||||||
569 | *a2++ = ~*a1++; executed 13 times by 2 tests: *a2++ = ~*a1++; Executed by:
| 13 | ||||||||||||||||||
570 | - | |||||||||||||||||||
571 | if (sz && sz%8)
| 2-11 | ||||||||||||||||||
572 | *(a2-1) &= (1 << (sz%8)) - 1; executed 6 times by 2 tests: *(a2-1) &= (1 << (sz%8)) - 1; Executed by:
| 6 | ||||||||||||||||||
573 | return a; executed 13 times by 2 tests: return a; Executed by:
| 13 | ||||||||||||||||||
574 | } | - | ||||||||||||||||||
575 | - | |||||||||||||||||||
576 | /*! | - | ||||||||||||||||||
577 | \relates QBitArray | - | ||||||||||||||||||
578 | - | |||||||||||||||||||
579 | Returns a bit array that is the AND of the bit arrays \a a1 and \a | - | ||||||||||||||||||
580 | a2. | - | ||||||||||||||||||
581 | - | |||||||||||||||||||
582 | The result has the length of the longest of the two bit arrays, | - | ||||||||||||||||||
583 | with any missing bits (if one array is shorter than the other) | - | ||||||||||||||||||
584 | taken to be 0. | - | ||||||||||||||||||
585 | - | |||||||||||||||||||
586 | Example: | - | ||||||||||||||||||
587 | \snippet code/src_corelib_tools_qbitarray.cpp 12 | - | ||||||||||||||||||
588 | - | |||||||||||||||||||
589 | \sa {QBitArray::}{operator&=()}, {QBitArray::}{operator|()}, {QBitArray::}{operator^()} | - | ||||||||||||||||||
590 | */ | - | ||||||||||||||||||
591 | - | |||||||||||||||||||
592 | QBitArray operator&(const QBitArray &a1, const QBitArray &a2) | - | ||||||||||||||||||
593 | { | - | ||||||||||||||||||
594 | QBitArray tmp = a1; | - | ||||||||||||||||||
595 | tmp &= a2; | - | ||||||||||||||||||
596 | return tmp; never executed: return tmp; | 0 | ||||||||||||||||||
597 | } | - | ||||||||||||||||||
598 | - | |||||||||||||||||||
599 | /*! | - | ||||||||||||||||||
600 | \relates QBitArray | - | ||||||||||||||||||
601 | - | |||||||||||||||||||
602 | Returns a bit array that is the OR of the bit arrays \a a1 and \a | - | ||||||||||||||||||
603 | a2. | - | ||||||||||||||||||
604 | - | |||||||||||||||||||
605 | The result has the length of the longest of the two bit arrays, | - | ||||||||||||||||||
606 | with any missing bits (if one array is shorter than the other) | - | ||||||||||||||||||
607 | taken to be 0. | - | ||||||||||||||||||
608 | - | |||||||||||||||||||
609 | Example: | - | ||||||||||||||||||
610 | \snippet code/src_corelib_tools_qbitarray.cpp 13 | - | ||||||||||||||||||
611 | - | |||||||||||||||||||
612 | \sa QBitArray::operator|=(), operator&(), operator^() | - | ||||||||||||||||||
613 | */ | - | ||||||||||||||||||
614 | - | |||||||||||||||||||
615 | QBitArray operator|(const QBitArray &a1, const QBitArray &a2) | - | ||||||||||||||||||
616 | { | - | ||||||||||||||||||
617 | QBitArray tmp = a1; | - | ||||||||||||||||||
618 | tmp |= a2; | - | ||||||||||||||||||
619 | return tmp; never executed: return tmp; | 0 | ||||||||||||||||||
620 | } | - | ||||||||||||||||||
621 | - | |||||||||||||||||||
622 | /*! | - | ||||||||||||||||||
623 | \relates QBitArray | - | ||||||||||||||||||
624 | - | |||||||||||||||||||
625 | Returns a bit array that is the XOR of the bit arrays \a a1 and \a | - | ||||||||||||||||||
626 | a2. | - | ||||||||||||||||||
627 | - | |||||||||||||||||||
628 | The result has the length of the longest of the two bit arrays, | - | ||||||||||||||||||
629 | with any missing bits (if one array is shorter than the other) | - | ||||||||||||||||||
630 | taken to be 0. | - | ||||||||||||||||||
631 | - | |||||||||||||||||||
632 | Example: | - | ||||||||||||||||||
633 | \snippet code/src_corelib_tools_qbitarray.cpp 14 | - | ||||||||||||||||||
634 | - | |||||||||||||||||||
635 | \sa {QBitArray}{operator^=()}, {QBitArray}{operator&()}, {QBitArray}{operator|()} | - | ||||||||||||||||||
636 | */ | - | ||||||||||||||||||
637 | - | |||||||||||||||||||
638 | QBitArray operator^(const QBitArray &a1, const QBitArray &a2) | - | ||||||||||||||||||
639 | { | - | ||||||||||||||||||
640 | QBitArray tmp = a1; | - | ||||||||||||||||||
641 | tmp ^= a2; | - | ||||||||||||||||||
642 | return tmp; never executed: return tmp; | 0 | ||||||||||||||||||
643 | } | - | ||||||||||||||||||
644 | - | |||||||||||||||||||
645 | /*! | - | ||||||||||||||||||
646 | \class QBitRef | - | ||||||||||||||||||
647 | \inmodule QtCore | - | ||||||||||||||||||
648 | \reentrant | - | ||||||||||||||||||
649 | \brief The QBitRef class is an internal class, used with QBitArray. | - | ||||||||||||||||||
650 | - | |||||||||||||||||||
651 | \internal | - | ||||||||||||||||||
652 | - | |||||||||||||||||||
653 | The QBitRef is required by the indexing [] operator on bit arrays. | - | ||||||||||||||||||
654 | It is not for use in any other context. | - | ||||||||||||||||||
655 | */ | - | ||||||||||||||||||
656 | - | |||||||||||||||||||
657 | /*! \fn QBitRef::QBitRef (QBitArray& a, int i) | - | ||||||||||||||||||
658 | - | |||||||||||||||||||
659 | Constructs a reference to element \a i in the QBitArray \a a. | - | ||||||||||||||||||
660 | This is what QBitArray::operator[] constructs its return value | - | ||||||||||||||||||
661 | with. | - | ||||||||||||||||||
662 | */ | - | ||||||||||||||||||
663 | - | |||||||||||||||||||
664 | /*! \fn QBitRef::operator bool() const | - | ||||||||||||||||||
665 | - | |||||||||||||||||||
666 | Returns the value referenced by the QBitRef. | - | ||||||||||||||||||
667 | */ | - | ||||||||||||||||||
668 | - | |||||||||||||||||||
669 | /*! \fn bool QBitRef::operator!() const | - | ||||||||||||||||||
670 | - | |||||||||||||||||||
671 | \internal | - | ||||||||||||||||||
672 | */ | - | ||||||||||||||||||
673 | - | |||||||||||||||||||
674 | /*! \fn QBitRef& QBitRef::operator= (const QBitRef& v) | - | ||||||||||||||||||
675 | - | |||||||||||||||||||
676 | Sets the value referenced by the QBitRef to that referenced by | - | ||||||||||||||||||
677 | QBitRef \a v. | - | ||||||||||||||||||
678 | */ | - | ||||||||||||||||||
679 | - | |||||||||||||||||||
680 | /*! \fn QBitRef& QBitRef::operator= (bool v) | - | ||||||||||||||||||
681 | \overload | - | ||||||||||||||||||
682 | - | |||||||||||||||||||
683 | Sets the value referenced by the QBitRef to \a v. | - | ||||||||||||||||||
684 | */ | - | ||||||||||||||||||
685 | - | |||||||||||||||||||
686 | - | |||||||||||||||||||
687 | /***************************************************************************** | - | ||||||||||||||||||
688 | QBitArray stream functions | - | ||||||||||||||||||
689 | *****************************************************************************/ | - | ||||||||||||||||||
690 | - | |||||||||||||||||||
691 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||
692 | /*! | - | ||||||||||||||||||
693 | \relates QBitArray | - | ||||||||||||||||||
694 | - | |||||||||||||||||||
695 | Writes bit array \a ba to stream \a out. | - | ||||||||||||||||||
696 | - | |||||||||||||||||||
697 | \sa {Serializing Qt Data Types}{Format of the QDataStream operators} | - | ||||||||||||||||||
698 | */ | - | ||||||||||||||||||
699 | - | |||||||||||||||||||
700 | QDataStream &operator<<(QDataStream &out, const QBitArray &ba) | - | ||||||||||||||||||
701 | { | - | ||||||||||||||||||
702 | quint32 len = ba.size(); | - | ||||||||||||||||||
703 | out << len; | - | ||||||||||||||||||
704 | if (len > 0)
| 140-256 | ||||||||||||||||||
705 | out.writeRawData(ba.d.constData() + 1, ba.d.size() - 1); executed 140 times by 4 tests: out.writeRawData(ba.d.constData() + 1, ba.d.size() - 1); Executed by:
| 140 | ||||||||||||||||||
706 | return out; executed 396 times by 9 tests: return out; Executed by:
| 396 | ||||||||||||||||||
707 | } | - | ||||||||||||||||||
708 | - | |||||||||||||||||||
709 | /*! | - | ||||||||||||||||||
710 | \relates QBitArray | - | ||||||||||||||||||
711 | - | |||||||||||||||||||
712 | Reads a bit array into \a ba from stream \a in. | - | ||||||||||||||||||
713 | - | |||||||||||||||||||
714 | \sa {Serializing Qt Data Types}{Format of the QDataStream operators} | - | ||||||||||||||||||
715 | */ | - | ||||||||||||||||||
716 | - | |||||||||||||||||||
717 | QDataStream &operator>>(QDataStream &in, QBitArray &ba) | - | ||||||||||||||||||
718 | { | - | ||||||||||||||||||
719 | ba.clear(); | - | ||||||||||||||||||
720 | quint32 len; | - | ||||||||||||||||||
721 | in >> len; | - | ||||||||||||||||||
722 | if (len == 0) {
| 181-284 | ||||||||||||||||||
723 | ba.clear(); | - | ||||||||||||||||||
724 | return in; executed 284 times by 9 tests: return in; Executed by:
| 284 | ||||||||||||||||||
725 | } | - | ||||||||||||||||||
726 | - | |||||||||||||||||||
727 | const quint32 Step = 8 * 1024 * 1024; | - | ||||||||||||||||||
728 | quint32 totalBytes = (len + 7) / 8; | - | ||||||||||||||||||
729 | quint32 allocated = 0; | - | ||||||||||||||||||
730 | - | |||||||||||||||||||
731 | while (allocated < totalBytes) {
| 171-181 | ||||||||||||||||||
732 | int blockSize = qMin(Step, totalBytes - allocated); | - | ||||||||||||||||||
733 | ba.d.resize(allocated + blockSize + 1); | - | ||||||||||||||||||
734 | if (in.readRawData(ba.d.data() + 1 + allocated, blockSize) != blockSize) {
| 10-171 | ||||||||||||||||||
735 | ba.clear(); | - | ||||||||||||||||||
736 | in.setStatus(QDataStream::ReadPastEnd); | - | ||||||||||||||||||
737 | return in; executed 10 times by 1 test: return in; Executed by:
| 10 | ||||||||||||||||||
738 | } | - | ||||||||||||||||||
739 | allocated += blockSize; | - | ||||||||||||||||||
740 | } executed 171 times by 4 tests: end of block Executed by:
| 171 | ||||||||||||||||||
741 | - | |||||||||||||||||||
742 | int paddingMask = ~((0x1 << (len & 0x7)) - 1); | - | ||||||||||||||||||
743 | if (paddingMask != ~0x0 && (ba.d.constData()[ba.d.size() - 1] & paddingMask)) {
| 13-114 | ||||||||||||||||||
744 | ba.clear(); | - | ||||||||||||||||||
745 | in.setStatus(QDataStream::ReadCorruptData); | - | ||||||||||||||||||
746 | return in; executed 13 times by 1 test: return in; Executed by:
| 13 | ||||||||||||||||||
747 | } | - | ||||||||||||||||||
748 | - | |||||||||||||||||||
749 | *ba.d.data() = ba.d.size() * 8 - len; | - | ||||||||||||||||||
750 | return in; executed 158 times by 4 tests: return in; Executed by:
| 158 | ||||||||||||||||||
751 | } | - | ||||||||||||||||||
752 | #endif // QT_NO_DATASTREAM | - | ||||||||||||||||||
753 | - | |||||||||||||||||||
754 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||
755 | QDebug operator<<(QDebug dbg, const QBitArray &array) | - | ||||||||||||||||||
756 | { | - | ||||||||||||||||||
757 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||
758 | dbg.nospace() << "QBitArray("; | - | ||||||||||||||||||
759 | for (int i = 0; i < array.size();) {
| 2-3 | ||||||||||||||||||
760 | if (array.testBit(i))
| 0-3 | ||||||||||||||||||
761 | dbg << '1'; executed 3 times by 1 test: dbg << '1'; Executed by:
| 3 | ||||||||||||||||||
762 | else | - | ||||||||||||||||||
763 | dbg << '0'; never executed: dbg << '0'; | 0 | ||||||||||||||||||
764 | i += 1; | - | ||||||||||||||||||
765 | if (!(i % 4) && (i < array.size()))
| 0-3 | ||||||||||||||||||
766 | dbg << ' '; never executed: dbg << ' '; | 0 | ||||||||||||||||||
767 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
768 | dbg << ')'; | - | ||||||||||||||||||
769 | return dbg; executed 2 times by 1 test: return dbg; Executed by:
| 2 | ||||||||||||||||||
770 | } | - | ||||||||||||||||||
771 | #endif | - | ||||||||||||||||||
772 | - | |||||||||||||||||||
773 | /*! | - | ||||||||||||||||||
774 | \fn DataPtr &QBitArray::data_ptr() | - | ||||||||||||||||||
775 | \internal | - | ||||||||||||||||||
776 | */ | - | ||||||||||||||||||
777 | - | |||||||||||||||||||
778 | /*! | - | ||||||||||||||||||
779 | \typedef QBitArray::DataPtr | - | ||||||||||||||||||
780 | \internal | - | ||||||||||||||||||
781 | */ | - | ||||||||||||||||||
782 | - | |||||||||||||||||||
783 | QT_END_NAMESPACE | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |