mCRL2
Loading...
Searching...
No Matches
mcrl2::utilities::obitstream Class Reference

A bitstream provides per bit writing of data to any stream (including stdout). More...

#include <bitstream.h>

Public Member Functions

 obitstream (std::ostream &stream)
 Provides the stream on which the write function operate.
 
 ~obitstream ()
 
void write_bits (std::size_t value, unsigned int num_of_bits)
 Write the num_of_bits least significant bits in descending order from value.
 
void write_string (const std::string &string)
 Write the given string to the output stream.
 
void write_integer (std::size_t value)
 Write the given value to the output stream.
 

Private Member Functions

void flush ()
 Flush the remaining bits in the buffer to the output stream.
 
void write (const std::uint8_t *buffer, std::size_t size)
 Writes size bytes from the given buffer.
 

Private Attributes

std::ostream & stream
 
std::bitset< 128 > write_buffer = 0
 Buffer that is filled starting from bit 127 when writing.
 
unsigned int bits_in_buffer = 0
 how many bits in are used in the buffer.
 
std::uint8_t integer_buffer [integer_encoding_size< std::size_t >()]
 Reserved space to store an n byte integer.
 

Detailed Description

A bitstream provides per bit writing of data to any stream (including stdout).

Internally uses bitpacking and buffering for compact and efficient IO.

Definition at line 31 of file bitstream.h.

Constructor & Destructor Documentation

◆ obitstream()

obitstream::obitstream ( std::ostream &  stream)

Provides the stream on which the write function operate.

Definition at line 101 of file bitstream.cpp.

◆ ~obitstream()

mcrl2::utilities::obitstream::~obitstream ( )
inline

Definition at line 36 of file bitstream.h.

Member Function Documentation

◆ flush()

void obitstream::flush ( )
private

Flush the remaining bits in the buffer to the output stream.

Note that this aligns it to the next byte, e.g. when bits_in_buffer is 6 then two zero bits are added redundantly.

Definition at line 234 of file bitstream.cpp.

◆ write()

void obitstream::write ( const std::uint8_t *  buffer,
std::size_t  size 
)
private

Writes size bytes from the given buffer.

Definition at line 247 of file bitstream.cpp.

◆ write_bits()

void obitstream::write_bits ( std::size_t  value,
unsigned int  num_of_bits 
)

Write the num_of_bits least significant bits in descending order from value.

Parameters
valueVariable that contains the bits.
num_of_bitsNumber of bits to write to the output stream.

Definition at line 115 of file bitstream.cpp.

◆ write_integer()

void obitstream::write_integer ( std::size_t  value)

Write the given value to the output stream.

Uses most significant bit encoding.

Definition at line 156 of file bitstream.cpp.

◆ write_string()

void obitstream::write_string ( const std::string &  string)

Write the given string to the output stream.

Encoded in bits using <length, string>

Definition at line 147 of file bitstream.cpp.

Member Data Documentation

◆ bits_in_buffer

unsigned int mcrl2::utilities::obitstream::bits_in_buffer = 0
private

how many bits in are used in the buffer.

Definition at line 64 of file bitstream.h.

◆ integer_buffer

std::uint8_t mcrl2::utilities::obitstream::integer_buffer[integer_encoding_size< std::size_t >()]
private

Reserved space to store an n byte integer.

Definition at line 66 of file bitstream.h.

◆ stream

std::ostream& mcrl2::utilities::obitstream::stream
private

Definition at line 59 of file bitstream.h.

◆ write_buffer

std::bitset<128> mcrl2::utilities::obitstream::write_buffer = 0
private

Buffer that is filled starting from bit 127 when writing.

Definition at line 62 of file bitstream.h.


The documentation for this class was generated from the following files: