tudocomp
– The TU Dortmund Compression Framework
tdc::io::BitOStream Class Reference

Wrapper for output streams that provides bitwise writing functionality. More...

#include <BitOStream.hpp>

Public Member Functions

 BitOStream (OutputStream &&output)
 Constructs a bitwise output stream. More...
 
 BitOStream (Output &output)
 Constructs a bitwise output stream. More...
 
 ~BitOStream ()
 
auto tellp () -> decltype(m_stream.tellp())
 Returns the output position indicator of the underlying stream, which should equal the amount of bytes written to it. More...
 
void write_bit (bool set)
 Writes a single bit to the output. More...
 
template<class T >
void write_int (T value, size_t bits=sizeof(T) *CHAR_BIT)
 Writes the bit representation of an integer in MSB first order to the output. More...
 
template<typename value_t >
void write_unary (value_t v)
 
template<typename value_t >
void write_ternary (value_t v)
 
template<typename value_t >
void write_elias_gamma (value_t v)
 
template<typename value_t >
void write_elias_delta (value_t v)
 
template<typename T >
void write_compressed_int (T v, size_t b=7)
 Writes a compressed integer to the input. More...
 

Detailed Description

Wrapper for output streams that provides bitwise writing functionality.

Bits are written into a buffer byte, which is written to the output when it is either filled or when a flush is explicitly requested.

Definition at line 17 of file BitOStream.hpp.

Constructor & Destructor Documentation

◆ BitOStream() [1/2]

tdc::io::BitOStream::BitOStream ( OutputStream &&  output)
inline

Constructs a bitwise output stream.

Parameters
outputThe underlying output stream.

Definition at line 43 of file BitOStream.hpp.

◆ BitOStream() [2/2]

tdc::io::BitOStream::BitOStream ( Output output)
inline

Constructs a bitwise output stream.

Parameters
outputThe underlying output.

Definition at line 50 of file BitOStream.hpp.

◆ ~BitOStream()

tdc::io::BitOStream::~BitOStream ( )
inline

Definition at line 53 of file BitOStream.hpp.

Member Function Documentation

◆ tellp()

auto tdc::io::BitOStream::tellp ( ) -> decltype(m_stream.tellp())
inline

Returns the output position indicator of the underlying stream, which should equal the amount of bytes written to it.

Note that this value does not include bits that have not yet been flushed.

Returns
the output position indicator of the underlying stream

Definition at line 73 of file BitOStream.hpp.

◆ write_bit()

void tdc::io::BitOStream::write_bit ( bool  set)
inline

Writes a single bit to the output.

Parameters
setThe bit value (0 or 1).

Definition at line 79 of file BitOStream.hpp.

◆ write_compressed_int()

template<typename T >
void tdc::io::BitOStream::write_compressed_int ( v,
size_t  b = 7 
)
inline

Writes a compressed integer to the input.

The compressed form of an integer n is achieved by splitting up the bit representation of n in blocks of width b. For each non-zero block (in little endian order), a bit flag and the block itself is written.

The flag is set to 1 if there is another block after the current one, and otherwise set to 0 to mark the block as the last one.

Template Parameters
Theinteger type to write.
Parameters
vThe integer to write.
bThe block width in bits. The default is 7 bits.

Definition at line 151 of file BitOStream.hpp.

◆ write_elias_delta()

template<typename value_t >
void tdc::io::BitOStream::write_elias_delta ( value_t  v)
inline

Definition at line 132 of file BitOStream.hpp.

◆ write_elias_gamma()

template<typename value_t >
void tdc::io::BitOStream::write_elias_gamma ( value_t  v)
inline

Definition at line 126 of file BitOStream.hpp.

◆ write_int()

template<class T >
void tdc::io::BitOStream::write_int ( value,
size_t  bits = sizeof(T) * CHAR_BIT 
)
inline

Writes the bit representation of an integer in MSB first order to the output.

Template Parameters
Thetype of integer to write.
Parameters
valueThe integer to write.
bitsThe amount of low bits of the value to write. By default, this equals the bit width of type T.

Definition at line 98 of file BitOStream.hpp.

◆ write_ternary()

template<typename value_t >
void tdc::io::BitOStream::write_ternary ( value_t  v)
inline

Definition at line 114 of file BitOStream.hpp.

◆ write_unary()

template<typename value_t >
void tdc::io::BitOStream::write_unary ( value_t  v)
inline

Definition at line 105 of file BitOStream.hpp.


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