QBitArray Class | Qt Core 5.15.19 (original) (raw)
Member Function Documentation
QBitArray::QBitArray(QBitArray &&other)
Move-constructs a QBitArray instance, making it point at the same object that other was pointing to.
This function was introduced in Qt 5.2.
QBitArray::QBitArray(const QBitArray &other)
Constructs a copy of other.
This operation takes constant time, because QBitArray is implicitly shared. This makes returning a QBitArray from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes linear time.
See also operator=().
QBitArray::QBitArray(int size, bool value = false)
Constructs a bit array containing size bits. The bits are initialized with value, which defaults to false (0).
QBitArray::QBitArray()
Constructs an empty bit array.
See also isEmpty().
QBitArray &QBitArray::operator=(QBitArray &&other)
Moves other to this bit array and returns a reference to this bit array.
This function was introduced in Qt 5.2.
QBitArray &QBitArray::operator=(const QBitArray &other)
Assigns other to this bit array and returns a reference to this bit array.
bool QBitArray::at(int i) const
Returns the value of the bit at index position i.
i must be a valid index position in the bit array (i.e., 0 <= i < size()).
See also operator[]().
const char *QBitArray::bits() const
Returns a pointer to a dense bit array for this QBitArray. Bits are counted upwards from the least significant bit in each byte. The number of bits relevant in the last byte is given by size() % 8
.
This function was introduced in Qt 5.11.
See also fromBits() and size().
void QBitArray::clear()
Clears the contents of the bit array and makes it empty.
See also resize() and isEmpty().
void QBitArray::clearBit(int i)
Sets the bit at index position i to 0.
i must be a valid index position in the bit array (i.e., 0 <= i < size()).
See also setBit() and toggleBit().
int QBitArray::count() const
Same as size().
int QBitArray::count(bool on) const
If on is true, this function returns the number of 1-bits stored in the bit array; otherwise the number of 0-bits is returned.
bool QBitArray::fill(bool value, int size = -1)
Sets every bit in the bit array to value, returning true if successful; otherwise returns false
. If size is different from -1 (the default), the bit array is resized to size beforehand.
Example:
QBitArray ba(8); ba.fill(true); // ba: [ 1, 1, 1, 1, 1, 1, 1, 1 ]
ba.fill(false, 2); // ba: [ 0, 0 ]
See also resize().
void QBitArray::fill(bool value, int begin, int end)
This is an overloaded function.
Sets bits at index positions begin up to (but not including) end to value.
begin must be a valid index position in the bit array (0 <= begin < size()).
end must be either a valid index position or equal to size(), in which case the fill operation runs until the end of the array (0 <= end <= size()).
Example:
QBitArray ba(4); ba.fill(true, 1, 2); // ba: [ 0, 1, 0, 0 ] ba.fill(true, 1, 3); // ba: [ 0, 1, 1, 0 ] ba.fill(true, 1, 4); // ba: [ 0, 1, 1, 1 ]
[static]
QBitArray QBitArray::fromBits(const char *data, int size)
Creates a QBitArray with the dense bit array located at data, with size bits. The byte array at data must be at least size / 8 (rounded up) bytes long.
If size is not a multiple of 8, this function will include the lowest size % 8 bits from the last byte in data.
This function was introduced in Qt 5.11.
See also bits().
bool QBitArray::isEmpty() const
Returns true
if this bit array has size 0; otherwise returns false.
See also size().
bool QBitArray::isNull() const
Returns true
if this bit array is null; otherwise returns false
.
Example:
Qt makes a distinction between null bit arrays and empty bit arrays for historical reasons. For most applications, what matters is whether or not a bit array contains any data, and this can be determined using isEmpty().
See also isEmpty().
void QBitArray::resize(int size)
Resizes the bit array to size bits.
If size is greater than the current size, the bit array is extended to make it size bits with the extra bits added to the end. The new bits are initialized to false (0).
If size is less than the current size, bits are removed from the end.
See also size().
void QBitArray::setBit(int i)
Sets the bit at index position i to 1.
i must be a valid index position in the bit array (i.e., 0 <= i < size()).
See also clearBit() and toggleBit().
void QBitArray::setBit(int i, bool value)
This is an overloaded function.
Sets the bit at index position i to value.
int QBitArray::size() const
Returns the number of bits stored in the bit array.
See also resize().
void QBitArray::swap(QBitArray &other)
Swaps bit array other with this bit array. This operation is very fast and never fails.
This function was introduced in Qt 4.8.
bool QBitArray::testBit(int i) const
Returns true
if the bit at index position i is 1; otherwise returns false
.
i must be a valid index position in the bit array (i.e., 0 <= i < size()).
See also setBit() and clearBit().
bool QBitArray::toggleBit(int i)
Inverts the value of the bit at index position i, returning the previous value of that bit as either true (if it was set) or false (if it was unset).
If the previous value was 0, the new value will be 1. If the previous value was 1, the new value will be 0.
i must be a valid index position in the bit array (i.e., 0 <= i < size()).
See also setBit() and clearBit().
void QBitArray::truncate(int pos)
Truncates the bit array at index position pos.
If pos is beyond the end of the array, nothing happens.
See also resize().
bool QBitArray::operator!=(const QBitArray &other) const
Returns true
if other is not equal to this bit array; otherwise returns false
.
See also operator==().
QBitArray &QBitArray::operator&=(const QBitArray &other)
Performs the AND operation between all bits in this bit array and other. Assigns the result to this bit array, and returns a reference to it.
The result has the length of the longest of the two bit arrays, with any missing bits (if one array is shorter than the other) taken to be 0.
Example:
QBitArray a(3); QBitArray b(2); a[0] = 1; a[1] = 0; a[2] = 1; // a: [ 1, 0, 1 ] b[0] = 1; b[1] = 1; // b: [ 1, 1 ] a &= b; // a: [ 1, 0, 0 ]
See also operator&(), operator|=(), operator^=(), and operator~().
bool QBitArray::operator==(const QBitArray &other) const
Returns true
if other is equal to this bit array; otherwise returns false
.
See also operator!=().
QBitRef QBitArray::operator[](int _i_)
Returns the bit at index position i as a modifiable reference.
i must be a valid index position in the bit array (i.e., 0 <= i < size()).
Example:
QBitArray a(3); a[0] = false; a[1] = true; a[2] = a[0] ^ a[1];
The return value is of type QBitRef, a helper class for QBitArray. When you get an object of type QBitRef, you can assign to it, and the assignment will apply to the bit in the QBitArray from which you got the reference.
The functions testBit(), setBit(), and clearBit() are slightly faster.
See also at(), testBit(), setBit(), and clearBit().
bool QBitArray::operator[](int _i_) const
This is an overloaded function.
QBitRef QBitArray::operator[](uint i)
This is an overloaded function.
bool QBitArray::operator[](uint i) const
This is an overloaded function.
QBitArray &QBitArray::operator^=(const QBitArray &other)
Performs the XOR operation between all bits in this bit array and other. Assigns the result to this bit array, and returns a reference to it.
The result has the length of the longest of the two bit arrays, with any missing bits (if one array is shorter than the other) taken to be 0.
Example:
QBitArray a(3); QBitArray b(2); a[0] = 1; a[1] = 0; a[2] = 1; // a: [ 1, 0, 1 ] b[0] = 1; b[1] = 1; // b: [ 1, 1 ] a ^= b; // a: [ 0, 1, 1 ]
See also operator^(), operator&=(), operator|=(), and operator~().
QBitArray &QBitArray::operator|=(const QBitArray &other)
Performs the OR operation between all bits in this bit array and other. Assigns the result to this bit array, and returns a reference to it.
The result has the length of the longest of the two bit arrays, with any missing bits (if one array is shorter than the other) taken to be 0.
Example:
QBitArray a(3); QBitArray b(2); a[0] = 1; a[1] = 0; a[2] = 1; // a: [ 1, 0, 1 ] b[0] = 1; b[1] = 1; // b: [ 1, 1 ] a |= b; // a: [ 1, 1, 1 ]
See also operator|(), operator&=(), operator^=(), and operator~().
QBitArray QBitArray::operator~() const
Returns a bit array that contains the inverted bits of this bit array.
Example:
QBitArray a(3); QBitArray b; a[0] = 1; a[1] = 0; a[2] = 1; // a: [ 1, 0, 1 ] b = ~a; // b: [ 0, 1, 0 ]