#include <bitbuffer.hpp>
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 85 of file bitbuffer.hpp.
Public Static Methods | |
static Index | Decode32 (uint32_t code) |
static Index | Decode64 (uint64_t code) |
Public Methods | |
Index ()=default | |
Index (uinteger pPos, ShiftOpRHS pBit) | |
ShiftOpRHS | Bit () const |
void | Clear () |
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 size) |
Private Static Fields | |
static constexpr ShiftOpRHS | BIT_COUNT_SIZE = sizeof(TStorage) == 8 ? 6 : 5 |
Private Fields | |
ShiftOpRHS | bit = 0 |
Current bit index in the current word. | |
uinteger | pos = 0 |
Index of the current word to read/write. | |
|
inline |
Constructor
Definition at line 112 of file bitbuffer.hpp.
|
inline |
Returns the number of the actual bit in the actual word of the buffer buffer.
Definition at line 127 of file bitbuffer.hpp.
|
inline |
Sets this index to zero, hence pointing to the first bit in the buffer.
Definition at line 143 of file bitbuffer.hpp.
|
inline |
Returns the number of bits used in respect to this index.
Definition at line 179 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 229 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 249 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 202 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 218 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 156 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 138 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 271 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 282 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 294 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 259 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 317 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 306 of file bitbuffer.hpp.
|
inline |
Returns the index of the actual storage word in the buffer.
Definition at line 121 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.
size | The position within the buffer in bytes. |
Definition at line 169 of file bitbuffer.hpp.
|
staticconstexprprivate |
The number of bits needed to encode the bit number.
Definition at line 94 of file bitbuffer.hpp.