ALib C++ Library
Library Version: 2312 R0
Documentation generated by doxygen
Public Methods | Private Static Fields | Private Fields | Protected Methods | Private Types | List of all members
BitReader Class Reference

#include <bitbuffer.hpp>

Inheritance diagram for BitReader:
[legend]
Collaboration diagram for BitReader:
[legend]

Class Description


Reads bits from a BitBufferBase.

Definition at line 1095 of file bitbuffer.hpp.

Public Methods

 BitReader (BitBufferBase &buffer)
 
 BitReader (BitBufferBase &buffer, const BitBufferBase::Index &index)
 
 ~BitReader ()
 
template<ShiftOpRHS TWidth, typename TResult >
TResult Read ()
 
template<typename TIntegral >
TIntegral Read ()
 
template<typename TResult >
TResult Read (ShiftOpRHS width)
 
void Reset ()
 
void Reset (const BitBufferBase::Index &index)
 
BitReaderSync ()
 
- Public Methods inherited from BitRWBase
BitBufferBaseGetBuffer () const
 
BitBufferBase::Index GetIndex () const
 
uinteger RemainingSize () const
 
uinteger Usage () const
 

Private Static Fields

static constexpr ShiftOpRHS TStorageWidth = sizeof( TStorage ) * 8
 

Private Fields

BitBufferBase::TStorage word
 

Protected Methods

ALIB_API uint16_t readUIntegral16 ()
 
ALIB_API uint32_t readUIntegral32 ()
 
ALIB_API uint64_t readUIntegral64 ()
 
ALIB_API uint8_t readUIntegral8 ()
 
- Protected Methods inherited from BitRWBase
 BitRWBase (BitBufferBase &buffer)
 

Private Types

using TStorage = BitBufferBase::TStorage
 

Additional Inherited Members

- Protected Fields inherited from BitRWBase
BitBufferBasebb
 The bit buffer to write into. Provided on construction.
 
BitBufferBase::Index idx
 The current reading/writing index within bb.
 

Member Typedef Documentation

◆ TStorage

Local type alias (shortcut)

Definition at line 1098 of file bitbuffer.hpp.

Constructor & Destructor Documentation

◆ BitReader() [1/2]

BitReader ( BitBufferBase buffer)
inlineexplicit

Constructs a bit reader using the given bit buffer and starting to read at the beginning.

Parameters
bufferThe buffer to read from.

Definition at line 1112 of file bitbuffer.hpp.

Here is the call graph for this function:

◆ BitReader() [2/2]

BitReader ( BitBufferBase buffer,
const BitBufferBase::Index index 
)
inlineexplicit

Constructs a bit reader using the given bit buffer, starting to read at the given Index.

Parameters
bufferThe buffer to read from.
indexAn index providing the postion of the first bit to read in buffer.

Definition at line 1125 of file bitbuffer.hpp.

Here is the call graph for this function:

◆ ~BitReader()

~BitReader ( )
inline

Destructs a bit reader. In debug compilations an ALib assertion is raised if the a read operation passed the end of the underlying buffer was performed.

Definition at line 1135 of file bitbuffer.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ Read() [1/3]

TResult Read ( )

Reads the given number of bits from the stream into the given unsigned integral value.

Note
Internally, different template functions selected with std::enable_if are selected for the different integral types.
See also
This method uses a template parameter for the number of bits to read. A slightly slower, non-templated version is available with Read<TResult>(ShiftOpRHS), which is to be used when the number of bits to write is determined only at run-time.
Template Parameters
TWidthThe number of bits in val to write.
TResultThe type of the value to return.
Returns
The value read.

◆ Read() [2/3]

TIntegral Read ( )

Reads the given integral value from the stream. Information about the encoding of the values is given with the documentation of BitWriter::Write<TIntegral>(TIntegral).

Returns
The value read from the bit buffer.

◆ Read() [3/3]

TResult Read ( ShiftOpRHS  width)

Reads the given number of bits from tif( )he stream into the given unsigned integral value.

Note
Internally, different template functions selected with std::enable_if are selected for different integral types.
See also
A method that uses a template parameter for the number of bits to read, is is available with Read<TWidth,TResult>if( ) (TIntegral). This might be slightly faster and should be used instead of this method, whenever the number of bits to read is known at compilation time.
Template Parameters
TResultThe type of the value to return. Defaults to type int.
Parameters
widthThe number of bits to read.
Returns
The value read.

◆ readUIntegral16()

uint16_t readUIntegral16 ( )
protected

Internal method that reads a unsigned 16-bit value.

Returns
The value read.

Definition at line 254 of file bitbuffer.cpp.

◆ readUIntegral32()

uint32_t readUIntegral32 ( )
protected

Internal method that reads a unsigned 32-bit value.

Returns
The value read.

Definition at line 264 of file bitbuffer.cpp.

◆ readUIntegral64()

uint64_t readUIntegral64 ( )
protected

Internal method that reads a unsigned 64-bit value.

Returns
The value read.

Definition at line 276 of file bitbuffer.cpp.

◆ readUIntegral8()

uint8_t readUIntegral8 ( )
protected

Internal method that reads a unsigned 8-bit value.

Returns
The value read.

Definition at line 244 of file bitbuffer.cpp.

◆ Reset() [1/2]

void Reset ( )
inline

Resets this reader to the start of the bit buffer.

Definition at line 1142 of file bitbuffer.hpp.

Here is the call graph for this function:

◆ Reset() [2/2]

void Reset ( const BitBufferBase::Index index)
inline

Resets this reader to the given index position and calls Sync().

Parameters
indexThe next read position.

Definition at line 1153 of file bitbuffer.hpp.

Here is the call graph for this function:

◆ Sync()

BitReader& Sync ( )
inline

Re-reads the currently fetched storage word from the memory.

Note
This method is not needed in common use cases and implemented solely for the purpose to support unit-tests which write and write in parallel to the same bit buffer.
Returns
A reference to this BitReader to allow concatenated operations.

Definition at line 1167 of file bitbuffer.hpp.

Here is the call graph for this function:

Member Data Documentation

◆ TStorageWidth

constexpr ShiftOpRHS TStorageWidth = sizeof( TStorage ) * 8
staticconstexprprivate

The width in bits of the storage type which is of type int. Consequently, this evaluates to 32 or 64 on most common platforms.

Definition at line 1102 of file bitbuffer.hpp.

◆ word

The current word, which is partly read and shifted to start with current bit.

Definition at line 1105 of file bitbuffer.hpp.


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