scantools
1.0.4
Graphics manipulation with a view towards scanned documents
|
The bitVector class provides an array of bits, similar to QBitArray. More...
#include <bitVector.h>
Classes | |
class | miniBitVector |
Simple array of bits, useful for static data. More... | |
Public Member Functions | |
bitVector () | |
Constructs an empty bit array. | |
bitVector (int numBits) | |
Constructs an array of size bits. More... | |
bitVector (QByteArray data) | |
Constructs a bitVector from a QByteArray. More... | |
quint8 | getBit (int index) const |
Returns the bit at position index. More... | |
void | setBit (int index, quint8 bit) |
Sets the bit at position index. More... | |
int | size () const |
Size of the bitVector in bits. More... | |
void | resize (int newSize) |
Sets the size of the bitVector array to newSize bits. More... | |
bool | startsWith (const miniBitVector &mbv, int index=0) const |
Check if the content of the given miniBitVector is found at a given position. More... | |
void | append (const miniBitVector &mbv) |
Appends a miniBitVector to the end of the bitVector. More... | |
operator QByteArray () | |
Converts the bitVector to a QByteArray. More... | |
operator QString () const | |
Convert bitVector to human-readable string. More... | |
Static Public Member Functions | |
static quint8 | getBit (const quint8 *ptr, int index) |
Convenience method for read access to a bit in a C-array of bytes. More... | |
static void | setBit (quint8 *ptr, int index, quint8 bit) |
Convenience method for write access to a bit in a C-array of bytes. More... | |
static void | fill (quint8 *ptr, int startIndex, int numBits, quint8 bit) |
Convenience method for write access to a continuous block of bits in a C-array of bytes. More... | |
static int | findEndOfRun (const quint8 *ptr, int startIndex, int endIndex, quint8 runValue) |
Searches for end of a run of consecutive bits with same value. More... | |
The bitVector class provides an array of bits, similar to QBitArray.
A bitVector is an array that gives access to individual bits. In this respect, the class is very similar to QBitArray. Unlike QBitArray, there are convenient and well-defined conversions from bitVectors to QByteArrays with guraranteed behaviour.
The bitVector class is based on QByteArray, and therefore uses implicit sharing (copy-on-write) to reduce memory usage and to avoid the needless copying of data. The methods of this class are reentrant, but not thread safe.
Definition at line 42 of file bitVector.h.
|
explicit |
Constructs an array of size bits.
numBits | Size of the newly created bit vector |
The bit are initialized to the value '0'.
|
explicit |
Constructs a bitVector from a QByteArray.
Constructs an array of 8*data.size() bits. Bit number 0 in the resulting bitVector corresponds to the most significant bit in byte 0 of the QByteArray. Bit number 1 corresponds to the second most significant bit in byte 0 of the QByteArray, etc.
data | QByteArray whose data is copied |
This operation uses implicit sharing and therefore takes constant time.
|
inline |
Appends a miniBitVector to the end of the bitVector.
The bitVector will be resized if necessary.
mbv | miniBitVector whose content is appended |
Definition at line 168 of file bitVector.h.
|
inlinestatic |
Convenience method for write access to a continuous block of bits in a C-array of bytes.
ptr | This is a pointer to an array by bytes (a.k.a. quint8). |
startIndex | This must be a valid index position in the bit array. Bit number 0 is the most significant bit in byte 0 of the array. Bit number 1 is the second most significant bit in byte 0 of the array, etc. Indices that point out of the array boundes will likely lead to segfault. |
numBits | Number of bits to be written. The array must be at least of size startIndex+numBits, or else a segfault will likely occur. |
bit | Either 0 or 1 |
Definition at line 251 of file bitVector.h.
|
inlinestatic |
Searches for end of a run of consecutive bits with same value.
ptr | Pointer to the data whose content is searched |
startIndex | Index of the first bit to be looked at |
endIndex | Index of the last bit to be looked at |
runValue | Value of the bits in the run |
Definition at line 304 of file bitVector.h.
|
inlinestatic |
Convenience method for read access to a bit in a C-array of bytes.
ptr | This is a pointer to an array by bytes (a.k.a. quint8). |
index | Number of the bit that is retrieved from the array. Bit number 0 is the most significant bit in byte 0 of the array. Bit number 1 is the second most significant bit in byte 0 of the array, etc. Indices that point out of the array boundes will likely lead to segfault. |
Definition at line 212 of file bitVector.h.
|
inline |
Returns the bit at position index.
index | This must be a valid index position in the bit array. In other words, index < size(). Invalid values will likely lead to segfault |
Definition at line 77 of file bitVector.h.
bitVector::operator QByteArray | ( | ) |
Converts the bitVector to a QByteArray.
Stores the bitVector in an array of (size()+7)/8 bytes. Bit number 0 in the bitVector corresponds to the most significant bit in byte 0 of the QByteArray. Bit number 1 corresponds to the second most significant bit in byte 0 of the QByteArray, etc. Unused bits in the last byte of the resulting array are set to zero.
bitVector::operator QString | ( | ) | const |
void bitVector::resize | ( | int | newSize | ) |
Sets the size of the bitVector array to newSize bits.
If size is greater than the current size, the bitVector is extended by adding the extra bits to the end. The new bits are uninitialized. If newSize is less than the current size, bits are removed from the end.
newSize | New size of the vector, in bits |
|
inline |
Sets the bit at position index.
index | This must be a valid index position in the bit array. In other words, index < size(). Invalid values for index will likely lead to segfault |
bit | Bit value, either 0 or 1. |
Definition at line 89 of file bitVector.h.
|
inlinestatic |
Convenience method for write access to a bit in a C-array of bytes.
ptr | This is a pointer to an array by bytes (a.k.a. quint8). |
index | This must be a valid index position in the bit array. Bit number 0 is the most significant bit in byte 0 of the array. Bit number 1 is the second most significant bit in byte 0 of the array, etc. Indices that point out of the array boundes will likely lead to segfault. |
bit | Either 0 or 1 |
Definition at line 227 of file bitVector.h.
|
inline |
Size of the bitVector in bits.
Definition at line 101 of file bitVector.h.
bool bitVector::startsWith | ( | const miniBitVector & | mbv, |
int | index = 0 |
||
) | const |
Check if the content of the given miniBitVector is found at a given position.
mbv | miniBitVector whose content is expected to by found at position index |
index | Position where the content of mbv is expected |