Qx v0.5.8
Qt Extensions Library
|
The BitArray class is a more robust variant of QBitArray, which provides an array of bits. More...
#include <qx/core/qx-bitarray.h>
Public Member Functions | |
BitArray () | |
BitArray (int size, bool value=false) | |
void | append (bool bit=false) |
BitArray | operator+ (BitArray rhs) |
void | operator+= (const BitArray &rhs) |
BitArray | operator<< (int n) |
void | operator<<= (int n) |
BitArray | operator>> (int n) |
void | operator>>= (int n) |
void | replace (const BitArray &bits, int start=0, int length=-1) |
template<typename T > requires std::integral<T> | |
void | replace (T integer, int start=0, int length=-1) |
BitArray | subArray (int start, int length=-1) |
BitArray | takeFromEnd (int length=-1) |
BitArray | takeFromStart (int length=-1) |
QByteArray | toByteArray (QSysInfo::Endian endianness=QSysInfo::BigEndian) |
template<typename T > requires std::integral<T> | |
T | toInteger () |
Public Member Functions inherited from QBitArray | |
QBitArray (const QBitArray &other) | |
QBitArray (QBitArray &&other) | |
QBitArray (qsizetype size, bool value) | |
bool | at (qsizetype i) const const |
const char * | bits () const const |
void | clear () |
void | clearBit (qsizetype i) |
qsizetype | count () const const |
qsizetype | count (bool on) const const |
void | fill (bool value, qsizetype begin, qsizetype end) |
bool | fill (bool value, qsizetype size) |
bool | isEmpty () const const |
bool | isNull () const const |
bool | operator!= (const QBitArray &other) const const |
QBitArray | operator& (const QBitArray &a1, const QBitArray &a2) |
QBitArray | operator& (const QBitArray &a1, QBitArray &&a2) |
QBitArray | operator& (QBitArray &&a1, const QBitArray &a2) |
QBitArray | operator& (QBitArray &&a1, QBitArray &&a2) |
QBitArray & | operator&= (const QBitArray &other) |
QBitArray & | operator&= (QBitArray &&other) |
QDataStream & | operator<< (QDataStream &out, const QBitArray &ba) |
QBitArray & | operator= (const QBitArray &other) |
QBitArray & | operator= (QBitArray &&other) |
bool | operator== (const QBitArray &other) const const |
QDataStream & | operator>> (QDataStream &in, QBitArray &ba) |
QBitRef | operator[] (qsizetype i) |
bool | operator[] (qsizetype i) const const |
QBitArray | operator^ (const QBitArray &a1, const QBitArray &a2) |
QBitArray | operator^ (const QBitArray &a1, QBitArray &&a2) |
QBitArray | operator^ (QBitArray &&a1, const QBitArray &a2) |
QBitArray | operator^ (QBitArray &&a1, QBitArray &&a2) |
QBitArray & | operator^= (const QBitArray &other) |
QBitArray & | operator^= (QBitArray &&other) |
QBitArray | operator| (const QBitArray &a1, const QBitArray &a2) |
QBitArray | operator| (const QBitArray &a1, QBitArray &&a2) |
QBitArray | operator| (QBitArray &&a1, const QBitArray &a2) |
QBitArray | operator| (QBitArray &&a1, QBitArray &&a2) |
QBitArray & | operator|= (const QBitArray &other) |
QBitArray & | operator|= (QBitArray &&other) |
QBitArray | operator~ (QBitArray a) |
void | resize (qsizetype size) |
void | setBit (qsizetype i) |
void | setBit (qsizetype i, bool value) |
qsizetype | size () const const |
void | swap (QBitArray &other) |
bool | testBit (qsizetype i) const const |
bool | toggleBit (qsizetype i) |
quint32 | toUInt32 (QSysInfo::Endian endianness, bool *ok) const const |
void | truncate (qsizetype pos) |
Static Public Member Functions | |
template<typename T > requires std::integral<T> | |
static BitArray | fromInteger (const T &integer) |
Static Public Member Functions inherited from QBitArray | |
QBitArray | fromBits (const char *data, qsizetype size) |
BitArray derives from QBitArray and therefore shares all of its functionality, but this Qx variant provides additional data manipulation and conversion methods that are missing from its base class.
The implementation of this class assumes that it contents will be stored and manipulated in big-endian order when working with instances that may represent sets of bytes.
Qx::BitArray::BitArray | ( | ) |
Constructs an empty bit array.
Qx::BitArray::BitArray | ( | int | size, |
bool | value = false ) |
Constructs a bit array containing size bits. The bits are initialized with value, which defaults to false (0).
void Qx::BitArray::append | ( | bool | bit = false | ) |
Appends a 0 or 1 onto the end of this bit array depending on the value of bit.
|
inlinestatic |
Converts the primitive integer to a bit array, with the resultant contents encoded in big-endian format if a multibyte integer type is provided.
Returns a bit array which is the result of concatenating this bit array and rhs.
void Qx::BitArray::operator+= | ( | const BitArray & | rhs | ) |
Appends rhs onto the end of the bit array.
BitArray Qx::BitArray::operator<< | ( | int | n | ) |
Returns a new bit array with the contents of the original shifted left n times.
void Qx::BitArray::operator<<= | ( | int | n | ) |
Left shifts the contents of the bit array n times.
BitArray Qx::BitArray::operator>> | ( | int | n | ) |
Returns a new bit array with the contents of the original shifted right n times.
void Qx::BitArray::operator>>= | ( | int | n | ) |
Right shifts the contents of the bit array n times.
void Qx::BitArray::replace | ( | const BitArray & | bits, |
int | start = 0, | ||
int | length = -1 ) |
Replace at most length bits beginning at index start with bits.
A value of -1 for length will result in the replacement only being limited by the size of the bit array.
|
inline |
Replace at most length bits at index start with the bits that make up integer.
A value of -1 for length will result in the replacement only being limited by the size of the bit array.
BitArray Qx::BitArray::subArray | ( | int | start, |
int | length = -1 ) |
Returns a new bit array that contains length bits from the original, beggining at start.
A value of -1 for length will result all bits from start to the end of the array being included.
BitArray Qx::BitArray::takeFromEnd | ( | int | length = -1 | ) |
Removes length bits from the end of the array and returns them
A value of -1 for length will result in all bits being included.
BitArray Qx::BitArray::takeFromStart | ( | int | length = -1 | ) |
Removes length bits from the start of the array and returns them
A value of -1 for length will result in all bits being included.
QByteArray Qx::BitArray::toByteArray | ( | QSysInfo::Endian | endianness = QSysInfo::BigEndian | ) |
Constructs and returns a QByteArray using the contents of the bit array and endianness.
Each group of 8 bits within the bit array are converted to the equivalent byte in order starting from index position 0 and inserted into the returned byte array in the same order if endianness equals QSysInfo::BigEndian, or the reverse order if endianness equals QSysInfo::LittleEndian.
If the bit array's length is not evenly divisible by 8, the conversion is performed as if the end of the array was padded with zeroes until it would be.
|
inline |
Converts the contents of the bit array to an integer, with the contents interpreted as being in big-endian format if a multibyte integer type is specified.
If the specified integer type is not large enough to store the result, as many bits as possible will be used in the conversion instead.
If the bit array's length is not evenly divisible by 8, the conversion is performed as if the end of the array was padded with zeroes until it would be.