C++ Utilities  4.17.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Public Member Functions | List of all members
IoUtilities::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. More...
 
 BitReader (const char *buffer, const char *end)
 Constructs a new BitReader. More...
 
template<typename intType >
intType readBits (byte bitCount)
 Reads the specified number of bits from the buffer advancing the current position by bitCount bits. More...
 
byte readBit ()
 Reads the one bit from the buffer advancing the current position by one bit. More...
 
template<typename intType >
intType readUnsignedExpGolombCodedBits ()
 Reads "Exp-Golomb coded" bits (unsigned). More...
 
template<typename intType >
intType readSignedExpGolombCodedBits ()
 Reads "Exp-Golomb coded" bits (signed). More...
 
template<typename intType >
intType showBits (byte bitCount)
 Reads the specified number of bits from the buffer without advancing the current position. More...
 
void skipBits (std::size_t bitCount)
 Skips the specified number of bits without reading it. More...
 
void align ()
 Re-establishes alignment. More...
 
std::size_t bitsAvailable ()
 Returns the number of bits which are still available to read. More...
 
void reset (const char *buffer, std::size_t bufferSize)
 Resets the reader. More...
 
void reset (const char *buffer, const char *end)
 Resets the reader. More...
 

Detailed Description

The BitReader class provides bitwise reading of buffered data.

Definition at line 14 of file bitreader.h.

Constructor & Destructor Documentation

◆ BitReader() [1/2]

IoUtilities::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 greather than 1.

Definition at line 42 of file bitreader.h.

◆ BitReader() [2/2]

IoUtilities::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 greather than buffer.

Definition at line 53 of file bitreader.h.

Member Function Documentation

◆ align()

void IoUtilities::BitReader::align ( )
inline

Re-establishes alignment.

Definition at line 171 of file bitreader.h.

◆ bitsAvailable()

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

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

Definition at line 137 of file bitreader.h.

◆ readBit()

byte IoUtilities::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 IoUtilities::BitReader::readBits ( byte  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 68 of file bitreader.h.

◆ readSignedExpGolombCodedBits()

template<typename intType >
intType IoUtilities::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 IoUtilities::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 IoUtilities::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 greather than 1.

Definition at line 148 of file bitreader.h.

◆ reset() [2/2]

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

Resets the reader.

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

Definition at line 161 of file bitreader.h.

◆ showBits()

template<typename intType >
intType IoUtilities::BitReader::showBits ( byte  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 IoUtilities::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 19 of file bitreader.cpp.


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