ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::bitbuffer::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 54 of file bitbuffer.inl.

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.
 

Field Details:

◆ bit

lang::ShiftOpRHS alib::bitbuffer::BitBufferBase::Index::bit = 0
private

Current bit index in the current word.

Definition at line 63 of file bitbuffer.inl.

◆ pos

uinteger alib::bitbuffer::BitBufferBase::Index::pos = 0
private

Index of the current word to read/write.

Definition at line 62 of file bitbuffer.inl.

Constructor(s) / Destructor Details:

◆ Index()

alib::bitbuffer::BitBufferBase::Index::Index ( uinteger pPos,
lang::ShiftOpRHS pBit )
inline

Constructor

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

Definition at line 73 of file bitbuffer.inl.

Method Details:

◆ Bit()

lang::ShiftOpRHS alib::bitbuffer::BitBufferBase::Index::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 84 of file bitbuffer.inl.

◆ Clear()

void alib::bitbuffer::BitBufferBase::Index::Clear ( )
inline

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

Definition at line 96 of file bitbuffer.inl.

◆ CountBits()

uinteger alib::bitbuffer::BitBufferBase::Index::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 126 of file bitbuffer.inl.

◆ Decode32()

Index alib::bitbuffer::BitBufferBase::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 168 of file bitbuffer.inl.

Here is the call graph for this function:

◆ Decode64()

Index alib::bitbuffer::BitBufferBase::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 181 of file bitbuffer.inl.

Here is the call graph for this function:

◆ Encode32()

uint32_t alib::bitbuffer::BitBufferBase::Index::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 145 of file bitbuffer.inl.

Here is the call graph for this function:

◆ Encode64()

uint64_t alib::bitbuffer::BitBufferBase::Index::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 159 of file bitbuffer.inl.

Here is the call graph for this function:

◆ GetByteOffset()

integer alib::bitbuffer::BitBufferBase::Index::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 107 of file bitbuffer.inl.

Here is the call graph for this function:

◆ IsAligned()

bool alib::bitbuffer::BitBufferBase::Index::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 93 of file bitbuffer.inl.

◆ operator!=()

bool alib::bitbuffer::BitBufferBase::Index::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 203 of file bitbuffer.inl.

Here is the call graph for this function:

◆ operator<()

bool alib::bitbuffer::BitBufferBase::Index::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 214 of file bitbuffer.inl.

Here is the call graph for this function:

◆ operator<=()

bool alib::bitbuffer::BitBufferBase::Index::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 226 of file bitbuffer.inl.

Here is the call graph for this function:

◆ operator==()

bool alib::bitbuffer::BitBufferBase::Index::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 191 of file bitbuffer.inl.

Here is the call graph for this function:

◆ operator>()

bool alib::bitbuffer::BitBufferBase::Index::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 249 of file bitbuffer.inl.

Here is the call graph for this function:

◆ operator>=()

bool alib::bitbuffer::BitBufferBase::Index::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 238 of file bitbuffer.inl.

Here is the call graph for this function:

◆ Pos()

uinteger alib::bitbuffer::BitBufferBase::Index::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 80 of file bitbuffer.inl.

◆ SetFromByteOffset()

void alib::bitbuffer::BitBufferBase::Index::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 118 of file bitbuffer.inl.


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