C++ Utilities 5.26.1
Useful C++ classes and routines such as argument parser, IO and conversion utilities
|
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. | |
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.
|
inline |
Constructs a new BitReader.
Definition at line 41 of file bitreader.h.
|
inline |
Constructs a new BitReader.
Definition at line 52 of file bitreader.h.
|
inline |
Re-establishes alignment.
Definition at line 171 of file bitreader.h.
|
inline |
Returns the number of bits which are still available to read.
Definition at line 137 of file bitreader.h.
|
inline |
Reads the one bit from the buffer advancing the current position by one bit.
Throws | ios_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.
intType CppUtilities::BitReader::readBits | ( | std::uint8_t | bitCount | ) |
Reads the specified number of bits from the buffer advancing the current position by bitCount bits.
bitCount | Specifies the number of bits read. |
intType | Specifies the type of the returned value. |
Throws | ios_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.
intType CppUtilities::BitReader::readSignedExpGolombCodedBits | ( | ) |
Reads "Exp-Golomb coded" bits (signed).
intType | Specifies the type of the returned value which should be signed (obviously). |
Throws | ios_base::failure if the end of the buffer is exceeded. The reader becomes invalid in that case. |
Definition at line 119 of file bitreader.h.
intType CppUtilities::BitReader::readUnsignedExpGolombCodedBits | ( | ) |
Reads "Exp-Golomb coded" bits (unsigned).
intType | Specifies the type of the returned value. |
Throws | ios_base::failure if the end of the buffer is exceeded. The reader becomes invalid in that case. |
Definition at line 102 of file bitreader.h.
|
inline |
Resets the reader.
Definition at line 161 of file bitreader.h.
|
inline |
Resets the reader.
Definition at line 148 of file bitreader.h.
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.
void CppUtilities::BitReader::skipBits | ( | std::size_t | bitCount | ) |
Skips the specified number of bits without reading it.
bitCount | Specifies the number of bits to skip. |
Throws | std::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.