libfly  6.2.2
C++20 utility library for Linux, macOS, and Windows
fly::BitStreamWriter Class Reference

#include <bit_stream_writer.hpp>

Inheritance diagram for fly::BitStreamWriter:
Collaboration diagram for fly::BitStreamWriter:

Public Member Functions

 BitStreamWriter (std::ostream &stream) noexcept
 
void write_word (word_type word)
 
void write_byte (byte_type byte)
 
template<detail::BitStreamInteger DataType>
void write_bits (DataType bits, byte_type size)
 
bool finish ()
 
- Public Member Functions inherited from fly::detail::BitStream
virtual ~BitStream ()
 

Additional Inherited Members

- Protected Member Functions inherited from fly::detail::BitStream
 BitStream (std::streambuf *stream_buffer, byte_type starting_position) noexcept
 
template<detail::BitStreamInteger DataType>
DataType bit_mask (const DataType bits)
 
- Protected Attributes inherited from fly::detail::BitStream
std::streambuf * m_stream_buffer
 
buffer_type m_buffer {0}
 
byte_type m_position {0}
 

Detailed Description

Implementation of the BitStream interface for writing to a binary stream.

Bits are written to an in-memory byte buffer until that buffer is full, at which point that buffer is flushed to the stream. When done writing, callers should invoke the finish() method to flush the BitStream header and any bytes remaining in the buffer.

Author
Timothy Flynn (trfly.nosp@m.nn89.nosp@m.@pm.m.nosp@m.e)
Version
July 7, 2019

Constructor & Destructor Documentation

◆ BitStreamWriter()

fly::BitStreamWriter::BitStreamWriter ( std::ostream &  stream)
explicitnoexcept

Constructor. Write the header byte onto the stream.

Parameters
streamThe stream to write binary data into.

Member Function Documentation

◆ finish()

bool fly::BitStreamWriter::finish ( )

If needed, zero-fill the byte buffer, flush it to the stream, and update the header byte.

Returns
True if the stream remains in a good state.

◆ write_bits()

template<detail::BitStreamInteger DataType>
void fly::BitStreamWriter::write_bits ( DataType  bits,
byte_type  size 
)

Write a number of bits to the byte buffer. The least-significant bits in the provided data type will be written, starting from the position pointed to by the provided number of bits.

Flush the buffer to the stream if it is filled during this operation.

Template Parameters
DataTypeThe data type storing the bits to write.
Parameters
bitsThe bits to write.
sizeThe number of bits to write.

◆ write_byte()

void fly::BitStreamWriter::write_byte ( byte_type  byte)

Write a full byte to the byte buffer.

Flush the buffer to the stream if it is filled during this operation.

Parameters
byteThe byte to write.

◆ write_word()

void fly::BitStreamWriter::write_word ( word_type  word)

Write a multibyte word to the byte buffer.

Flush the buffer to the stream if it is filled during this operation.

Parameters
wordThe word to write.

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