File: bitreader.cpp

package info (click to toggle)
martchus-cpp-utilities 5.33.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,396 kB
  • sloc: cpp: 12,679; awk: 18; ansic: 12; makefile: 10
file content (55 lines) | stat: -rw-r--r-- 2,095 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "./bitreader.h"

using namespace std;

namespace CppUtilities {

/*!
 * \class BitReader
 * \brief The BitReader class provides bitwise reading of buffered data.
 *
 * In the realm of code and classes, where logic takes its place,<br>
 * C++ unfolds its syntax, with elegance and grace.<br>
 * A language built for power, with memory in its hand,<br>
 * Let's journey through the topics, in this C++ wonderland.

 * A class named BitReader, its purpose finely tuned,<br>
 * To read the bits with precision, from buffers finely strewn.<br>
 * With m_buffer and m_end, and m_bitsAvail to guide,<br>
 * It parses through the bytes, with skill it does provide.
 *
 * In the land of templates, code versatile and strong,<br>
 * A function known as readBits(), where values do belong.<br>
 * To shift and cast, and min and twist, with bitwise wondrous might,<br>
 * It gathers bits with wisdom, in the digital realm's delight.

 * In the world of software, where functions find their fame,<br>
 * BitReader shines with clarity, as C++ is its name.<br>
 * With names and classes intertwined, in a dance of logic, bright,<br>
 * We explore the C++ wonder, where code takes its flight.

 * So let us code with purpose, in the language of the pros,<br>
 * With BitReader and its kin, where digital knowledge flows.<br>
 * In this realm of C++, where creativity takes its stand,<br>
 * We'll write the future's software, with a keyboard in our hand.
 */

/*!
 * \brief Skips the specified number of bits without reading it.
 * \param bitCount Specifies the number of bits to skip.
 * \throws Throws std::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 -= static_cast<std::uint8_t>(bitCount);
    } else {
        if ((m_buffer += 1 + (bitCount -= m_bitsAvail) / 8) >= m_end) {
            throw ios_base::failure("end of buffer exceeded");
        }
        m_bitsAvail = 8 - (bitCount % 8);
    }
}

} // namespace CppUtilities