#include <bit/ibstream.h>
Public Member Functions | |
ibstream () | |
Create an ibstream with no attached stream source. | |
ibstream (std::istream &input) | |
Create an ibstream from a standard stream source. | |
virtual | ~ibstream () |
Performs any stream cleanup including output of any remaining bits. | |
size_t | read_octets (unsigned char *buf, size_t octets) |
MSB read of up to n octets into a memory buffer. | |
size_t | read_octets (unsigned char *buf, size_t bufsize, size_t octets) |
LSB read of up to n octets into a memory buffer of size m with zero padding. | |
size_t | read_bits (unsigned char *buf, size_t bits) |
MSB bit read of up to n bits into a memory buffer. | |
size_t | read_bits (unsigned char *buf, size_t bufsize, size_t bits) |
LSB bit read of up to n bits into a memory buffer of size m octets with zero padding. | |
template<typename T> | |
size_t | read_octets (T &t, size_t n=sizeof(T)) |
LSB read of up to n octets into variable t with zero padding. | |
size_t | read_octets (uint16_t &t, size_t n=2) |
size_t | read_octets (uint32_t &t, size_t n=4) |
size_t | read_octets (uint64_t &t, size_t n=8) |
size_t | read_octets (int16_t &t, size_t n=2) |
size_t | read_octets (int32_t &t, size_t n=4) |
size_t | read_octets (int64_t &t, size_t n=8) |
template<typename T> | |
size_t | read_bits (T &t, size_t n=sizeof(T)*8) |
LSB read of up to n bits into variable t with zero padding. | |
size_t | read_bits (uint16_t &t, size_t n=2) |
size_t | read_bits (uint32_t &t, size_t n=4) |
size_t | read_bits (uint64_t &t, size_t n=8) |
size_t | read_bits (int16_t &t, size_t n=2) |
size_t | read_bits (int32_t &t, size_t n=4) |
size_t | read_bits (int64_t &t, size_t n=8) |
void | attach_stream (std::istream &stream, bool clearbits=false) |
Set the associated input stream to stream. | |
void | detach_stream (bool clearbits=false) |
Remove the currently attached stream. | |
Protected Attributes | |
std::istream * | m_input |
A pointer to the associated input stream. | |
Friends | |
ibstream & | operator>> (ibstream &s, const bits &b) |
ibstream & | operator>> (ibstream &s, const octets &o) |
ibstream & | operator>> (ibstream &s, const whole &w) |
template<typename T> | |
ibstream & | operator>> (ibstream &s, T &t) |
ibstream::ibstream | ( | ) |
Create an ibstream with no attached stream source.
ibstream::ibstream | ( | std::istream & | input | ) |
Create an ibstream from a standard stream source.
The stream source will be used to retrieve actual data from.
ibstream::~ibstream | ( | ) | [virtual] |
Performs any stream cleanup including output of any remaining bits.
size_t ibstream::read_octets | ( | unsigned char * | buf, | |
size_t | octets | |||
) |
MSB read of up to n octets into a memory buffer.
This method will only result in whole octet reads. Thus, if there are 4 bits buffered, a request for 4 octets is made, and 2 octets are actually available only 2 octets will be read with 4 bits still buffered.
References m_input, bit::bstream::m_leftoverbits, bit::bstream::m_masks, and bit::bstream::m_numleftoverbits.
Referenced by bit::operator>>(), read_bits(), and read_octets().
size_t ibstream::read_octets | ( | unsigned char * | buf, | |
size_t | bufsize, | |||
size_t | octets | |||
) |
LSB read of up to n octets into a memory buffer of size m with zero padding.
LSB, is not necessarily x86 little endian! A read of 1234 into a 6 octet buffer results in 001234. If n is greater than m, only m octets will be read.
References m_input, and read_octets().
size_t ibstream::read_bits | ( | unsigned char * | buf, | |
size_t | bits | |||
) |
MSB bit read of up to n bits into a memory buffer.
References m_input, bit::bstream::m_leftoverbits, bit::bstream::m_masks, bit::bstream::m_numleftoverbits, and read_octets().
Referenced by bit::operator>>(), and read_bits().
size_t ibstream::read_bits | ( | unsigned char * | buf, | |
size_t | bufsize, | |||
size_t | bits | |||
) |
LSB bit read of up to n bits into a memory buffer of size m octets with zero padding.
No adjustment is made for x86 integer or any other architectures or types.
References m_input, bit::bstream::m_numleftoverbits, and read_bits().
size_t bit::ibstream::read_octets | ( | T & | t, | |
size_t | n = sizeof(T) | |||
) | [inline] |
LSB read of up to n octets into variable t with zero padding.
For architecture specific integer types the "right" thing is done to result in a usable value. The default is to read the entire variable off the stream.
References m_input, and read_octets().
size_t ibstream::read_octets | ( | uint16_t & | t, | |
size_t | n = 2 | |||
) |
References m_input, and read_octets().
size_t ibstream::read_octets | ( | uint32_t & | t, | |
size_t | n = 4 | |||
) |
References m_input, and read_octets().
size_t ibstream::read_octets | ( | uint64_t & | t, | |
size_t | n = 8 | |||
) |
References m_input, and read_octets().
size_t ibstream::read_octets | ( | int16_t & | t, | |
size_t | n = 2 | |||
) |
References m_input, and read_octets().
size_t ibstream::read_octets | ( | int32_t & | t, | |
size_t | n = 4 | |||
) |
References m_input, and read_octets().
size_t ibstream::read_octets | ( | int64_t & | t, | |
size_t | n = 8 | |||
) |
References m_input, and read_octets().
size_t bit::ibstream::read_bits | ( | T & | t, | |
size_t | n = sizeof(T)*8 | |||
) | [inline] |
LSB read of up to n bits into variable t with zero padding.
For architecture specific integer types the "right" thing is done to result in a usable value. The default is to read the entire variable off the stream.
References m_input, bit::bstream::m_numleftoverbits, and read_bits().
size_t ibstream::read_bits | ( | uint16_t & | t, | |
size_t | n = 2 | |||
) |
References m_input, bit::bstream::m_numleftoverbits, and read_bits().
size_t ibstream::read_bits | ( | uint32_t & | t, | |
size_t | n = 4 | |||
) |
References m_input, bit::bstream::m_numleftoverbits, and read_bits().
size_t ibstream::read_bits | ( | uint64_t & | t, | |
size_t | n = 8 | |||
) |
References m_input, bit::bstream::m_numleftoverbits, and read_bits().
size_t ibstream::read_bits | ( | int16_t & | t, | |
size_t | n = 2 | |||
) |
References m_input, bit::bstream::m_numleftoverbits, and read_bits().
size_t ibstream::read_bits | ( | int32_t & | t, | |
size_t | n = 4 | |||
) |
References m_input, bit::bstream::m_numleftoverbits, and read_bits().
size_t ibstream::read_bits | ( | int64_t & | t, | |
size_t | n = 8 | |||
) |
References m_input, bit::bstream::m_numleftoverbits, and read_bits().
void ibstream::attach_stream | ( | std::istream & | stream, | |
bool | clearbits = false | |||
) |
Set the associated input stream to stream.
clearbits | If true any cached bits will be cleared, and if false (default) cached bits remain available for reading. |
References m_input, bit::bstream::m_leftoverbits, and bit::bstream::m_numleftoverbits.
void ibstream::detach_stream | ( | bool | clearbits = false |
) |
Remove the currently attached stream.
Futher attempts to read will fail unless there are cached bits.
clearbits | If true any cached bits will be cleared, and if false (default) cached bits remain available for reading. |
References m_input, bit::bstream::m_leftoverbits, and bit::bstream::m_numleftoverbits.
std::istream* bit::ibstream::m_input [protected] |
A pointer to the associated input 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(), read_bits(), and read_octets().