#include <bit/obstream.h>
Public Member Functions | |
obstream () | |
Create an obstream without an output sink. | |
obstream (std::ostream &output) | |
Create an obstream from a standard output stream. | |
virtual | ~obstream () |
Performs any stream cleanup including output of any remaining bits. | |
size_t | write_octets (unsigned char *buf, size_t octets) |
MSB write of up to n octets from a memory buffer. | |
size_t | write_octets (const unsigned char *buf, size_t octets) |
size_t | write_octets (unsigned char *buf, size_t bufsize, size_t octets) |
LSB write of up to n octets from a memory buffer of size m. | |
size_t | write_octets (const unsigned char *buf, size_t bufsize, size_t octets) |
size_t | write_bits (unsigned char *buf, size_t bits) |
MSB bit write of up to n bits from a memory buffer. | |
size_t | write_bits (const unsigned char *buf, size_t bits) |
size_t | write_bits (unsigned char *buf, size_t bufsize, size_t bits) |
LSB bit write of up to n bits from a memory buffer of size m octets with zero padding. | |
size_t | write_bits (const unsigned char *buf, size_t bufsize, size_t bits) |
template<typename T> | |
size_t | write_octets (T t, size_t n=sizeof(T)) |
LSB write of up to n octets from variable t with zero padding. | |
size_t | write_octets (uint16_t t, size_t n=2) |
size_t | write_octets (uint32_t t, size_t n=4) |
size_t | write_octets (uint64_t t, size_t n=8) |
size_t | write_octets (int16_t t, size_t n=2) |
size_t | write_octets (int32_t t, size_t n=4) |
size_t | write_octets (int64_t t, size_t n=8) |
template<typename T> | |
size_t | write_bits (T t, size_t n=sizeof(T)*8) |
LSB write of up to n bits from variable t with zero padding. | |
size_t | write_bits (uint16_t t, size_t n=2) |
size_t | write_bits (uint32_t t, size_t n=4) |
size_t | write_bits (uint64_t t, size_t n=8) |
size_t | write_bits (int16_t t, size_t n=2) |
size_t | write_bits (int32_t t, size_t n=4) |
size_t | write_bits (int64_t t, size_t n=8) |
void | flush (bool msb=true) |
Flush any remaining bits into the output stream using a default MSB ordering or LSB with one-octet width if parameter is false. | |
void | attach_stream (std::ostream &stream, bool clearbits=false) |
Set the associated output stream to stream. | |
void | detach_stream (bool clearbits=false) |
Remove the currently attached stream. | |
Protected Attributes | |
std::ostream * | m_output |
A pointer to the associated output stream. | |
Friends | |
obstream & | operator<< (obstream &s, const bits &b) |
obstream & | operator<< (obstream &s, const octets &o) |
obstream & | operator<< (obstream &s, const whole &w) |
template<typename T> | |
obstream & | operator<< (obstream &s, T &t) |
obstream::obstream | ( | ) |
Create an obstream without an output sink.
obstream::obstream | ( | std::ostream & | output | ) |
Create an obstream from a standard output stream.
The output stream will be the ultimate destination of the data.
obstream::~obstream | ( | ) | [virtual] |
size_t bit::obstream::write_octets | ( | unsigned char * | buf, | |
size_t | octets | |||
) | [inline] |
MSB write of up to n octets from a memory buffer.
Referenced by bit::operator<<(), write_bits(), and write_octets().
size_t obstream::write_octets | ( | const unsigned char * | buf, | |
size_t | octets | |||
) |
References bit::bstream::m_leftoverbits, bit::bstream::m_masks, bit::bstream::m_numleftoverbits, and m_output.
size_t bit::obstream::write_octets | ( | unsigned char * | buf, | |
size_t | bufsize, | |||
size_t | octets | |||
) | [inline] |
LSB write of up to n octets from a memory buffer of size m.
LSB, is not necessarily x86 little endian! A write of 4 octets from a 6 octet buffer of 123456 results in 3456. If n is greater than m the result will be zero padded.
References write_octets().
size_t obstream::write_octets | ( | const unsigned char * | buf, | |
size_t | bufsize, | |||
size_t | octets | |||
) |
References m_output, and write_octets().
size_t bit::obstream::write_bits | ( | unsigned char * | buf, | |
size_t | bits | |||
) | [inline] |
MSB bit write of up to n bits from a memory buffer.
Referenced by bit::operator<<(), and write_bits().
size_t obstream::write_bits | ( | const unsigned char * | buf, | |
size_t | bits | |||
) |
size_t bit::obstream::write_bits | ( | unsigned char * | buf, | |
size_t | bufsize, | |||
size_t | bits | |||
) | [inline] |
LSB bit write of up to n bits from a memory buffer of size m octets with zero padding.
No adjustment is made for x86 integer or any other architectures or types.
References write_bits().
size_t obstream::write_bits | ( | const unsigned char * | buf, | |
size_t | bufsize, | |||
size_t | bits | |||
) |
size_t bit::obstream::write_octets | ( | T | t, | |
size_t | n = sizeof(T) | |||
) | [inline] |
LSB write of up to n octets from variable t with zero padding.
For architecture specific integer types the "right" thing is done to result in a big-endian write. The default is to write the entire variable into the stream.
References m_output, and write_octets().
size_t obstream::write_octets | ( | uint16_t | t, | |
size_t | n = 2 | |||
) |
References m_output, and write_octets().
size_t obstream::write_octets | ( | uint32_t | t, | |
size_t | n = 4 | |||
) |
References m_output, and write_octets().
size_t obstream::write_octets | ( | uint64_t | t, | |
size_t | n = 8 | |||
) |
References m_output, and write_octets().
size_t obstream::write_octets | ( | int16_t | t, | |
size_t | n = 2 | |||
) |
References m_output, and write_octets().
size_t obstream::write_octets | ( | int32_t | t, | |
size_t | n = 4 | |||
) |
References m_output, and write_octets().
size_t obstream::write_octets | ( | int64_t | t, | |
size_t | n = 8 | |||
) |
References m_output, and write_octets().
size_t bit::obstream::write_bits | ( | T | t, | |
size_t | n = sizeof(T)*8 | |||
) | [inline] |
LSB write of up to n bits from variable t with zero padding.
For architecture specific integer types the "right" thing is done to result in a big-endian write. The default is to write the entire variable into the stream.
References m_output, and write_bits().
size_t obstream::write_bits | ( | uint16_t | t, | |
size_t | n = 2 | |||
) |
References m_output, and write_bits().
size_t obstream::write_bits | ( | uint32_t | t, | |
size_t | n = 4 | |||
) |
References m_output, and write_bits().
size_t obstream::write_bits | ( | uint64_t | t, | |
size_t | n = 8 | |||
) |
References m_output, and write_bits().
size_t obstream::write_bits | ( | int16_t | t, | |
size_t | n = 2 | |||
) |
References m_output, and write_bits().
size_t obstream::write_bits | ( | int32_t | t, | |
size_t | n = 4 | |||
) |
References m_output, and write_bits().
size_t obstream::write_bits | ( | int64_t | t, | |
size_t | n = 8 | |||
) |
References m_output, and write_bits().
void obstream::flush | ( | bool | msb = true |
) |
Flush any remaining bits into the output stream using a default MSB ordering or LSB with one-octet width if parameter is false.
References bit::bstream::m_leftoverbits, bit::bstream::m_numleftoverbits, and m_output.
Referenced by ~obstream().
void obstream::attach_stream | ( | std::ostream & | stream, | |
bool | clearbits = false | |||
) |
Set the associated output stream to stream.
clearbits | If true any cached bits will be cleared, and if false (default) cached bits remain in the stream for the next write. |
References bit::bstream::m_leftoverbits, bit::bstream::m_numleftoverbits, and m_output.
void obstream::detach_stream | ( | bool | clearbits = false |
) |
Remove the currently attached stream.
Futher attempts to write will fail, including subsequent attempts to flush any remaining bits. Therefore, if you're going to flush do it before this function call or set flushbits to true.
clearbits | If true any cached bits will be cleared, and if false (default) cached bits remain in the stream for the next write. |
References bit::bstream::m_leftoverbits, bit::bstream::m_numleftoverbits, and m_output.
std::ostream* bit::obstream::m_output [protected] |
A pointer to the associated output stream.
A reference is not used since it is anticipated that future versions will provide a constructor that does not require an associated stream.
Referenced by attach_stream(), detach_stream(), flush(), write_bits(), and write_octets().