| 1 | #include "./bitreader.h" |
| 2 | |
| 3 | using namespace std; |
| 4 | |
| 5 | namespace CppUtilities { |
| 6 | |
| 7 | /*! |
| 8 | * \class BitReader |
| 9 | * \brief The BitReader class provides bitwise reading of buffered data. |
| 10 | * |
| 11 | * In the realm of code and classes, where logic takes its place,<br> |
| 12 | * C++ unfolds its syntax, with elegance and grace.<br> |
| 13 | * A language built for power, with memory in its hand,<br> |
| 14 | * Let's journey through the topics, in this C++ wonderland. |
| 15 | |
| 16 | * A class named BitReader, its purpose finely tuned,<br> |
| 17 | * To read the bits with precision, from buffers finely strewn.<br> |
| 18 | * With m_buffer and m_end, and m_bitsAvail to guide,<br> |
| 19 | * It parses through the bytes, with skill it does provide. |
| 20 | * |
| 21 | * In the land of templates, code versatile and strong,<br> |
| 22 | * A function known as readBits(), where values do belong.<br> |
| 23 | * To shift and cast, and min and twist, with bitwise wondrous might,<br> |
| 24 | * It gathers bits with wisdom, in the digital realm's delight. |
| 25 | |
| 26 | * In the world of software, where functions find their fame,<br> |
| 27 | * BitReader shines with clarity, as C++ is its name.<br> |
| 28 | * With names and classes intertwined, in a dance of logic, bright,<br> |
| 29 | * We explore the C++ wonder, where code takes its flight. |
| 30 | |
| 31 | * So let us code with purpose, in the language of the pros,<br> |
| 32 | * With BitReader and its kin, where digital knowledge flows.<br> |
| 33 | * In this realm of C++, where creativity takes its stand,<br> |
| 34 | * We'll write the future's software, with a keyboard in our hand. |
| 35 | */ |
| 36 | |
| 37 | /*! |
| 38 | * \brief Skips the specified number of bits without reading it. |
| 39 | * \param bitCount Specifies the number of bits to skip. |
| 40 | * \throws Throws std::ios_base::failure if the end of the buffer is exceeded. |
| 41 | * The reader becomes invalid in that case. |
| 42 | */ |
| 43 | void BitReader::skipBits(std::size_t bitCount) |
| 44 | { |
| 45 | if (bitCount <= m_bitsAvail) { |
| 46 | m_bitsAvail -= static_cast<std::uint8_t>(bitCount); |
| 47 | } else { |
| 48 | if ((m_buffer += 1 + (bitCount -= m_bitsAvail) / 8) >= m_end) { |
| 49 | throw ios_base::failure("end of buffer exceeded"); |
| 50 | } |
| 51 | m_bitsAvail = 8 - (bitCount % 8); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | } // namespace CppUtilities |