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

#include <bit_stream.hpp>

Inheritance diagram for fly::detail::BitStream:

Public Member Functions

virtual ~BitStream ()
 

Protected Member Functions

 BitStream (std::streambuf *stream_buffer, byte_type starting_position) noexcept
 
template<detail::BitStreamInteger DataType>
DataType bit_mask (const DataType bits)
 

Protected Attributes

std::streambuf * m_stream_buffer
 
buffer_type m_buffer {0}
 
byte_type m_position {0}
 

Detailed Description

Base class for writing to and reading from a binary stream. The first byte of the binary stream is reserved as a header for internal use.

The BitStream implementations allow reading and writing content bit-by-bit. Of course, files cannot contain partial bytes. If a BitStream is closed with a partial byte remaining to be written, that byte is zero-filled, and the number of extra bits written is encoded into the header.

The format of the header byte is then:

|    5 bits    |           3 bits           |
---------------------------------------------
| Magic number | Number of zero-filled bits |

Each BitStream implementation essentially serves as a wrapper around an already existing std::istream or std::ostream. It is expected that the pre-existing stream outlive the wrapper BitStream instance.

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

Constructor & Destructor Documentation

◆ ~BitStream()

fly::detail::BitStream::~BitStream ( )
virtualdefault

Destructor.

◆ BitStream()

fly::detail::BitStream::BitStream ( std::streambuf *  stream_buffer,
byte_type  starting_position 
)
protectednoexcept

Protected constructor to prevent instantiating this class directly.

Parameters
stream_bufferPointer to the stream's underlying stream buffer.
starting_positionInitial cursor position.

Member Function Documentation

◆ bit_mask()

template<detail::BitStreamInteger DataType>
DataType fly::detail::BitStream::bit_mask ( const DataType  bits)
inlineprotected

Create a bit-mask with the least-significant bits set. The size of the mask is determined by the template DataType parameter.

Template Parameters
DataTypeThe data type storing the number of bits to set.
Parameters
starting_positionThe number of bits to set.
Returns
The created mask.

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