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