added method to read without advancing the current position, added
method to re-establish alignment
This commit is contained in:
parent
3ef06785fc
commit
7956635de1
|
@ -17,7 +17,9 @@ public:
|
|||
BitReader(const char *buffer, const char *end);
|
||||
|
||||
template<typename intType> intType readBits(byte bitCount);
|
||||
template<typename intType> 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<typename intType>
|
||||
intType BitReader::showBits(byte bitCount)
|
||||
{
|
||||
auto tmp = this;
|
||||
return tmp->readBits<intType>(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
|
||||
|
|
Loading…
Reference in New Issue