diff --git a/io/bitreader.h b/io/bitreader.h index 74efa32..b11e308 100644 --- a/io/bitreader.h +++ b/io/bitreader.h @@ -17,7 +17,9 @@ public: BitReader(const char *buffer, const char *end); template intType readBits(byte bitCount); + template intType showBits(byte bitCount); void skipBits(std::size_t bitCount); + void align(); std::size_t bitsAvailable(); void reset(const char *buffer, std::size_t bufferSize); void reset(const char *buffer, const char *end); @@ -51,7 +53,7 @@ inline BitReader::BitReader(const char *buffer, const char *end) : {} /*! - * \brief Reads the specified number of bits from the buffer. + * \brief Reads the specified number of bits from the buffer advancing the current position by \a bitCount bits. * \param bitCount Specifies the number of bits read. * \tparam intType Specifies the type of the returned value. * \remarks Does not check whether intType is big enough to hold result. @@ -75,6 +77,16 @@ intType BitReader::readBits(byte bitCount) return val; } +/*! + * \brief Reads the specified number of bits from the buffer without advancing the current position. + */ +template +intType BitReader::showBits(byte bitCount) +{ + auto tmp = this; + return tmp->readBits(bitCount); +} + /*! * \brief Returns the number of bits which are still available to read. */ @@ -107,6 +119,14 @@ inline void BitReader::reset(const char *buffer, const char *end) m_bitsAvail = 8; } +/*! + * \brief Re-establishes alignment. + */ +inline void BitReader::align() +{ + skipBits(m_bitsAvail); +} + } // namespace IoUtilities #endif // IOUTILITIES_BITREADER_H