ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
BitBufferBase::Index Class Reference

Description:

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 81 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
 
 Index (uinteger pPos, lang::ShiftOpRHS pBit)
 
lang::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 byteOffset)
 

Field Details:

◆ bit

lang::ShiftOpRHS bit = 0
private

Current bit index in the current word.

Definition at line 90 of file bitbuffer.hpp.

◆ pos

uinteger pos = 0
private

Index of the current word to read/write.

Definition at line 89 of file bitbuffer.hpp.

Constructor(s) / Destructor Details::

◆ Index() [1/2]

Index ( )
default

Default constructor initializing members pos and bit to zero.

◆ Index() [2/2]

Index ( uinteger pPos,
lang::ShiftOpRHS pBit )
inline

Constructor

Parameters
pPosThe initial value for member pos.
pBitThe initial value for member bit.

Definition at line 104 of file bitbuffer.hpp.

Method Details:

◆ Bit()

lang::ShiftOpRHS Bit ( ) const
inline

Returns the number of the actual bit in the actual word of the buffer buffer.

Returns
The number of the next bit to read/write.

Definition at line 119 of file bitbuffer.hpp.

◆ Clear()

void Clear ( )
inline

Sets this index to zero, hence pointing to the first bit in the buffer.

Definition at line 135 of file bitbuffer.hpp.

◆ CountBits()

uinteger CountBits ( ) const
inline

Returns the number of bits used in respect to this index.

Returns
The number of bits written or read.

Definition at line 171 of file bitbuffer.hpp.

◆ Decode32()

static Index Decode32 ( uint32_t code)
inlinestatic

Static method that decodes an index information, encoded with Encode32, to an instance of this class.

Parameters
codeThe encoded information.
Returns
The decoded index.

Definition at line 219 of file bitbuffer.hpp.

Here is the call graph for this function:

◆ Decode64()

static Index Decode64 ( uint64_t code)
inlinestatic

Static method that decodes an index information, encoded with Encode64, to an instance of this class.

Parameters
codeThe encoded information.
Returns
The decoded index.

Definition at line 234 of file bitbuffer.hpp.

Here is the call graph for this function:

◆ Encode32()

uint32_t Encode32 ( )
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:

  • TStorage 64-bit: 2^(32-6) * 8 bytes = 512 megabytes
  • TStorage 32-bit: 2^(32-5) * 4 bytes = 512 megabytes

In case bit buffers grow to over half a gigabyte, 64-bit encoding should be performed by using alternative method Encode64.

Returns
The encoded index.

Definition at line 192 of file bitbuffer.hpp.

◆ Encode64()

uint64_t Encode64 ( )
inline

Encodes this index information into a 64-bit value by using the upper 5 5 (or 6) bits for the bit index.

See also
For a shorter encoding, limited to bit buffer sizes of 512 megabytes, see method Encode32.
Returns
The encoded index.

Definition at line 208 of file bitbuffer.hpp.

◆ GetByteOffset()

integer GetByteOffset ( Index startIdx = Index(0, 0)) const
inline

Returns the size of the memory from given startIdx to this index occupied by the internal storage words of the buffer.

Parameters
startIdxThe starting index. Defaults to {0,0}.
Returns
The size of the buffer (part) in bytes.

Definition at line 148 of file bitbuffer.hpp.

◆ IsAligned()

bool IsAligned ( ) const
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.

Returns
The result of Bit() == 0.

Definition at line 130 of file bitbuffer.hpp.

◆ operator!=()

bool operator!= ( const Index & rhs) const
inline

Comparison operator.

Parameters
rhsThe right hand side argument of the comparison.
Returns
true if this object does not equal rhs , false otherwise.

Definition at line 256 of file bitbuffer.hpp.

◆ operator<()

bool operator< ( const Index & rhs) const
inline

Comparison operator.

Parameters
rhsThe right hand side argument of the comparison.
Returns
true if this object is smaller than rhs , false otherwise.

Definition at line 267 of file bitbuffer.hpp.

◆ operator<=()

bool operator<= ( const Index & rhs) const
inline

Comparison operator.

Parameters
rhsThe right hand side argument of the comparison.
Returns
true if this object is smaller or equal than rhs , false otherwise.

Definition at line 279 of file bitbuffer.hpp.

◆ operator==()

bool operator== ( const Index & rhs) const
inline

Comparison operator.

Parameters
rhsThe right hand side argument of the comparison.
Returns
true if this object equals rhs , false otherwise.

Definition at line 244 of file bitbuffer.hpp.

◆ operator>()

bool operator> ( const Index & rhs) const
inline

Comparison operator.

Parameters
rhsThe right hand side argument of the comparison.
Returns
true if this object is greater than rhs , false otherwise.

Definition at line 302 of file bitbuffer.hpp.

◆ operator>=()

bool operator>= ( const Index & rhs) const
inline

Comparison operator.

Parameters
rhsThe right hand side argument of the comparison.
Returns
true if this object is greater or equal than rhs , false otherwise.

Definition at line 291 of file bitbuffer.hpp.

◆ Pos()

uinteger Pos ( ) const
inline

Returns the index of the actual storage word in the buffer.

Returns
The index of the current word containing the next bit to read/write.

Definition at line 113 of file bitbuffer.hpp.

◆ SetFromByteOffset()

void SetFromByteOffset ( uinteger byteOffset)
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.

Parameters
byteOffsetThe position within the buffer in bytes.

Definition at line 161 of file bitbuffer.hpp.


The documentation for this class was generated from the following file: