added BitReader class

This commit is contained in:
Martchus 2015-06-08 22:09:09 +02:00
parent f3329b8592
commit 3ede66098f
2 changed files with 52 additions and 0 deletions

37
io/bitreader.cpp Normal file
View File

@ -0,0 +1,37 @@
#include "bitreader.h"
using namespace std;
namespace IoUtilities {
/*!
* \class IoUtilities::BitReader
* \brief The BitReader class allows bitwise reading of buffered data.
*/
/*!
* \brief Skips the specified number of bits without reading it.
* \param Specifies the number of bits to skip.
* \throws Throws ios_base::failure if the end of the buffer is exceeded.
* The reader becomes invalid in that case.
*/
void BitReader::skipBits(std::size_t bitCount)
{
if(bitCount < m_bitsAvail) {
m_bitsAvail -= bitCount;
if(!m_bitsAvail) {
m_bitsAvail = 8;
if(++m_buffer >= m_end) {
throw ios_base::failure("end of buffer exceeded");
}
}
} else {
if((m_buffer += (bitCount -= m_bitsAvail) / 8) >= m_end) {
throw ios_base::failure("end of buffer exceeded");
}
m_bitsAvail = 8 - (bitCount % 8);
}
}
} // namespace IoUtilities

15
io/bitreader.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef IOUTILITIES_BITREADER_H
#define IOUTILITIES_BITREADER_H
namespace IoUtilities {
class BitReader
{
public:
BitReader();
};
} // namespace IoUtilities
#endif // IOUTILITIES_BITREADER_H