1#ifndef IOUTILITIES_BITREADER_H
2#define IOUTILITIES_BITREADER_H
15 BitReader(
const char *buffer, std::size_t bufferSize);
16 BitReader(
const char *buffer,
const char *end);
18 template <
typename intType> intType readBits(std::uint8_t bitCount);
19 std::uint8_t readBit();
20 template <
typename intType> intType readUnsignedExpGolombCodedBits();
21 template <
typename intType> intType readSignedExpGolombCodedBits();
22 template <
typename intType> intType showBits(std::uint8_t bitCount);
23 void skipBits(std::size_t bitCount);
25 std::size_t bitsAvailable();
26 void reset(
const char *buffer, std::size_t bufferSize);
27 void reset(
const char *buffer,
const char *end);
30 const std::uint8_t *m_buffer;
31 const std::uint8_t *m_end;
32 std::uint8_t m_bitsAvail;
72 if (++m_buffer >= m_end) {
73 throw std::ios_base::failure(
"end of buffer exceeded");
104 std::uint8_t
count = 0;
122 return (value % 2) ?
static_cast<intType>((value + 1) / 2) : (-
static_cast<intType>(value / 2));
139 return m_buffer != m_end ?
static_cast<std::size_t
>(((m_end - m_buffer - 1) * 8) + m_bitsAvail) :
static_cast<std::size_t
>(0);
150 m_buffer =
reinterpret_cast<const std::uint8_t *
>(buffer);
151 m_end =
reinterpret_cast<const std::uint8_t *
>(buffer +
bufferSize);
163 m_buffer =
reinterpret_cast<const std::uint8_t *
>(buffer);
164 m_end =
reinterpret_cast<const std::uint8_t *
>(end);
The BitReader class provides bitwise reading of buffered data.
void reset(const char *buffer, std::size_t bufferSize)
Resets the reader.
std::uint8_t readBit()
Reads the one bit from the buffer advancing the current position by one bit.
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.
BitReader(const char *buffer, std::size_t bufferSize)
Constructs a new BitReader.
intType readSignedExpGolombCodedBits()
Reads "Exp-Golomb coded" bits (signed).
intType readUnsignedExpGolombCodedBits()
Reads "Exp-Golomb coded" bits (unsigned).
intType readBits(std::uint8_t bitCount)
Reads the specified number of bits from the buffer advancing the current position by bitCount bits.
intType showBits(std::uint8_t bitCount)
Reads the specified number of bits from the buffer without advancing the current position.
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
Contains all utilities provides by the c++utilities library.
IntegralType stringToNumber(const StringType &string, BaseType base=10)
Converts the given string to an unsigned/signed number assuming string uses the specified base.