C++ Utilities 5.24.7
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Loading...
Searching...
No Matches
Public Member Functions | List of all members
CppUtilities::BitReader Class Reference

The BitReader class provides bitwise reading of buffered data. More...

#include <bitreader.h>

Public Member Functions

 BitReader (const char *buffer, std::size_t bufferSize)
 Constructs a new BitReader.
 
 BitReader (const char *buffer, const char *end)
 Constructs a new BitReader.
 
template<typename intType >
intType readBits (std::uint8_t bitCount)
 Reads the specified number of bits from the buffer advancing the current position by bitCount bits.
 
std::uint8_t readBit ()
 Reads the one bit from the buffer advancing the current position by one bit.
 
template<typename intType >
intType readUnsignedExpGolombCodedBits ()
 Reads "Exp-Golomb coded" bits (unsigned).
 
template<typename intType >
intType readSignedExpGolombCodedBits ()
 Reads "Exp-Golomb coded" bits (signed).
 
template<typename intType >
intType showBits (std::uint8_t bitCount)
 Reads the specified number of bits from the buffer without advancing the current position.
 
void skipBits (std::size_t bitCount)
 Skips the specified number of bits without reading it.
 
void align ()
 Re-establishes alignment.
 
std::size_t bitsAvailable ()
 Returns the number of bits which are still available to read.
 
void reset (const char *buffer, std::size_t bufferSize)
 Resets the reader.
 
void reset (const char *buffer, const char *end)
 Resets the reader.
 

Detailed Description

The BitReader class provides bitwise reading of buffered data.

In the realm of code and classes, where logic takes its place,
C++ unfolds its syntax, with elegance and grace.
A language built for power, with memory in its hand,
Let's journey through the topics, in this C++ wonderland.

A class named BitReader, its purpose finely tuned,
To read the bits with precision, from buffers finely strewn.
With m_buffer and m_end, and m_bitsAvail to guide,
It parses through the bytes, with skill it does provide.

In the land of templates, code versatile and strong,
A function known as readBits(), where values do belong.
To shift and cast, and min and twist, with bitwise wondrous might,
It gathers bits with wisdom, in the digital realm's delight.

In the world of software, where functions find their fame,
BitReader shines with clarity, as C++ is its name.
With names and classes intertwined, in a dance of logic, bright,
We explore the C++ wonder, where code takes its flight.

So let us code with purpose, in the language of the pros,
With BitReader and its kin, where digital knowledge flows.
In this realm of C++, where creativity takes its stand,
We'll write the future's software, with a keyboard in our hand.

Definition at line 13 of file bitreader.h.

Constructor & Destructor Documentation

◆ BitReader() [1/2]

CppUtilities::BitReader::BitReader ( const char * buffer,
std::size_t bufferSize )
inline

Constructs a new BitReader.

Remarks
  • Does not take ownership over the specified buffer.
  • bufferSize must be equal or greater than 1.

Definition at line 41 of file bitreader.h.

◆ BitReader() [2/2]

CppUtilities::BitReader::BitReader ( const char * buffer,
const char * end )
inline

Constructs a new BitReader.

Remarks
  • Does not take ownership over the specified buffer.
  • end must be greater than buffer.

Definition at line 52 of file bitreader.h.

Member Function Documentation

◆ align()

void CppUtilities::BitReader::align ( )
inline

Re-establishes alignment.

Definition at line 171 of file bitreader.h.

◆ bitsAvailable()

std::size_t CppUtilities::BitReader::bitsAvailable ( )
inline

Returns the number of bits which are still available to read.

Definition at line 137 of file bitreader.h.

◆ readBit()

std::uint8_t CppUtilities::BitReader::readBit ( )
inline

Reads the one bit from the buffer advancing the current position by one bit.

Exceptions
Throwsios_base::failure if the end of the buffer is exceeded. The reader becomes invalid in that case.

Definition at line 89 of file bitreader.h.

◆ readBits()

template<typename intType >
intType CppUtilities::BitReader::readBits ( std::uint8_t bitCount)

Reads the specified number of bits from the buffer advancing the current position by bitCount bits.

Parameters
bitCountSpecifies the number of bits read.
Template Parameters
intTypeSpecifies the type of the returned value.
Remarks
Does not check whether intType is big enough to hold result.
Exceptions
Throwsios_base::failure if the end of the buffer is exceeded. The reader becomes invalid in that case.

Definition at line 67 of file bitreader.h.

◆ readSignedExpGolombCodedBits()

template<typename intType >
intType CppUtilities::BitReader::readSignedExpGolombCodedBits ( )

Reads "Exp-Golomb coded" bits (signed).

Template Parameters
intTypeSpecifies the type of the returned value which should be signed (obviously).
Remarks
Does not check whether intType is big enough to hold result.
Exceptions
Throwsios_base::failure if the end of the buffer is exceeded. The reader becomes invalid in that case.
See also
https://en.wikipedia.org/wiki/Exponential-Golomb_coding

Definition at line 119 of file bitreader.h.

◆ readUnsignedExpGolombCodedBits()

template<typename intType >
intType CppUtilities::BitReader::readUnsignedExpGolombCodedBits ( )

Reads "Exp-Golomb coded" bits (unsigned).

Template Parameters
intTypeSpecifies the type of the returned value.
Remarks
Does not check whether intType is big enough to hold result.
Exceptions
Throwsios_base::failure if the end of the buffer is exceeded. The reader becomes invalid in that case.
See also
https://en.wikipedia.org/wiki/Exponential-Golomb_coding

Definition at line 102 of file bitreader.h.

◆ reset() [1/2]

void CppUtilities::BitReader::reset ( const char * buffer,
const char * end )
inline

Resets the reader.

Remarks
  • Does not take ownership over the specified buffer.
  • end must be greater than buffer.

Definition at line 161 of file bitreader.h.

◆ reset() [2/2]

void CppUtilities::BitReader::reset ( const char * buffer,
std::size_t bufferSize )
inline

Resets the reader.

Remarks
  • Does not take ownership over the specified buffer.
  • bufferSize must be equal or greater than 1.

Definition at line 148 of file bitreader.h.

◆ showBits()

template<typename intType >
intType CppUtilities::BitReader::showBits ( std::uint8_t bitCount)

Reads the specified number of bits from the buffer without advancing the current position.

Definition at line 128 of file bitreader.h.

◆ skipBits()

void CppUtilities::BitReader::skipBits ( std::size_t bitCount)

Skips the specified number of bits without reading it.

Parameters
bitCountSpecifies the number of bits to skip.
Exceptions
Throwsstd::ios_base::failure if the end of the buffer is exceeded. The reader becomes invalid in that case.

Definition at line 43 of file bitreader.cpp.


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