44 lines
755 B
C++
44 lines
755 B
C++
#include <cstddef>
|
|
|
|
#ifndef BITSTREAM
|
|
#define BITSTREAM
|
|
|
|
class ibitstream
|
|
{
|
|
private:
|
|
// read bits from byte
|
|
int count;
|
|
|
|
// last byte from stream
|
|
uint8_t cache;
|
|
|
|
// Input stream
|
|
std::basic_istream<char> &is;
|
|
public:
|
|
ibitstream(std::basic_istream<char> &is) : count(-1), cache('\0'), is(is) {};
|
|
|
|
// Get n bits from stream; at most - 32
|
|
int getbits(size_t n);
|
|
};
|
|
|
|
class obitstream
|
|
{
|
|
private:
|
|
// written bits to byte
|
|
int count;
|
|
|
|
// last byte from stream
|
|
uint8_t cache;
|
|
|
|
std::basic_ostream<char> &os;
|
|
public:
|
|
obitstream(std::basic_ostream<char> &os) : count(0), cache(0), os(os) {};
|
|
|
|
// Get n bits from stream; at most - 32
|
|
void writebits(short bits, size_t n);
|
|
|
|
void flush();
|
|
};
|
|
|
|
#endif
|