Defines a bit position within outer class BitBufferBase. A bit position is determined by the index in the storage array along with the number of the currently written (or read) bit. Types BitWriter and BitReader use this type to define their current write (read) position.
Methods Encode32 and Encode64 shorten the information, by storing the bit position in the upper bits of a 32, respectively 64 bit value. This is useful whenever a broader number of bit buffer indices are to be stored. The use case to mention here is "lazy decoding of data", where only the index to the bit buffer is kept in memory.) positions
Definition at line 62 of file bitbuffer.hpp.
#include <bitbuffer.hpp>
Public Static Method Index: | |
static Index | Decode32 (uint32_t code) |
static Index | Decode64 (uint64_t code) |
Public Method Index: | |
Index ()=default | |
Default constructor initializing members pos and bit to zero. | |
Index (uinteger pPos, lang::ShiftOpRHS pBit) | |
lang::ShiftOpRHS | Bit () const |
void | Clear () |
Sets this index to zero, hence pointing to the first bit in the buffer. | |
uinteger | CountBits () const |
uint32_t | Encode32 () |
uint64_t | Encode64 () |
integer | GetByteOffset (Index startIdx=Index(0, 0)) const |
bool | IsAligned () const |
bool | operator!= (const Index &rhs) const |
bool | operator< (const Index &rhs) const |
bool | operator<= (const Index &rhs) const |
bool | operator== (const Index &rhs) const |
bool | operator> (const Index &rhs) const |
bool | operator>= (const Index &rhs) const |
uinteger | Pos () const |
void | SetFromByteOffset (uinteger byteOffset) |
Private Field Index: | |
lang::ShiftOpRHS | bit = 0 |
Current bit index in the current word. | |
uinteger | pos = 0 |
Index of the current word to read/write. | |
|
private |
Current bit index in the current word.
Definition at line 71 of file bitbuffer.hpp.
|
private |
Index of the current word to read/write.
Definition at line 70 of file bitbuffer.hpp.
Constructor
Definition at line 81 of file bitbuffer.hpp.
|
inline |
Returns the number of the actual bit in the actual word of the buffer buffer.
Definition at line 92 of file bitbuffer.hpp.
|
inline |
Sets this index to zero, hence pointing to the first bit in the buffer.
Definition at line 104 of file bitbuffer.hpp.
|
inline |
Returns the number of bits used in respect to this index.
Definition at line 134 of file bitbuffer.hpp.
|
inlinestatic |
Static method that decodes an index information, encoded with Encode32, to an instance of this class.
code | The encoded information. |
Definition at line 176 of file bitbuffer.hpp.
|
inlinestatic |
Static method that decodes an index information, encoded with Encode64, to an instance of this class.
code | The encoded information. |
Definition at line 189 of file bitbuffer.hpp.
|
inline |
Encodes this index information into a 32-bit variable by using the upper 5 (or 6) bits for the bit index. As a result, the possible value range of index data is reduced. The reduction depends on the platform's size of type int
. In case of 32-bit, five bits are needed to store the bit position. In the case of 64-bit, six bits are needed.
As the underlying TStorage type changes as well, in both cases, the resulting addressable storage bytes is limited to the same value:
In case bit buffers grow to over half a gigabyte, 64-bit encoding should be performed by using alternative method Encode64.
Definition at line 153 of file bitbuffer.hpp.
|
inline |
Encodes this index information into a 64-bit value by using the upper 5 5 (or 6) bits for the bit index.
Definition at line 167 of file bitbuffer.hpp.
Returns the size of the memory from given startIdx
to this index occupied by the internal storage words of the buffer.
startIdx | The starting index. Defaults to {0,0} . |
Definition at line 115 of file bitbuffer.hpp.
|
inline |
Returns true, if the next bit to read/write is the first of the current storage word in the buffer. Alignment of buffers may become important when buffers are serialized (e.g., to mass storage devices). Method BitBufferBase::Terminate may be used to receive an aligned index.
Bit() == 0
. Definition at line 101 of file bitbuffer.hpp.
|
inline |
Comparison operator.
rhs | The right hand side argument of the comparison. |
true
if this object does not equal rhs, false
otherwise. Definition at line 211 of file bitbuffer.hpp.
|
inline |
Comparison operator.
rhs | The right hand side argument of the comparison. |
true
if this object is smaller than rhs, false
otherwise. Definition at line 222 of file bitbuffer.hpp.
|
inline |
Comparison operator.
rhs | The right hand side argument of the comparison. |
true
if this object is smaller or equal than rhs, false
otherwise. Definition at line 234 of file bitbuffer.hpp.
|
inline |
Comparison operator.
rhs | The right hand side argument of the comparison. |
true
if this object equals rhs, false
otherwise. Definition at line 199 of file bitbuffer.hpp.
|
inline |
Comparison operator.
rhs | The right hand side argument of the comparison. |
true
if this object is greater than rhs, false
otherwise. Definition at line 257 of file bitbuffer.hpp.
|
inline |
Comparison operator.
rhs | The right hand side argument of the comparison. |
true
if this object is greater or equal than rhs, false
otherwise. Definition at line 246 of file bitbuffer.hpp.
|
inline |
Returns the index of the actual storage word in the buffer.
Definition at line 88 of file bitbuffer.hpp.
|
inline |
Sets this index to point to the word and bit given by a byte offset.
This method is useful when bit buffers are deserialized from character streams.
byteOffset | The position within the buffer in bytes. |
Definition at line 126 of file bitbuffer.hpp.