|
CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
|
This class is made to help reading datas of custom bit length. More...
#include <bit_istream.hpp>
Public Member Functions | |
| bit_istream (stream_type &f) | |
| Constructor. | |
| void | read (char *buf, unsigned int n) |
| Read some bits. | |
| operator bool () const | |
| Tell if the input stream is still valid. | |
Private Types | |
| typedef Stream | stream_type |
| The type of the stream we will read. | |
Private Attributes | |
| stream_type & | m_stream |
| The stream we're reading. | |
| unsigned char | m_pending |
| Some bits available for reading. | |
| unsigned char | m_pending_length |
| The number of valid bits in m_pending. | |
This class is made to help reading datas of custom bit length.
Definition at line 40 of file bit_istream.hpp.
typedef Stream claw::bit_istream< Stream >::stream_type [private] |
The type of the stream we will read.
Definition at line 44 of file bit_istream.hpp.
| claw::bit_istream< Stream >::bit_istream | ( | stream_type & | f | ) |
Constructor.
| f | The stream in which we read. |
Definition at line 38 of file bit_istream.tpp.
: m_stream(f), m_pending(0), m_pending_length(0) { } // bit_istream::bit_istream()
| claw::bit_istream< Stream >::operator bool | ( | ) | const |
Tell if the input stream is still valid.
Definition at line 93 of file bit_istream.tpp.
{
return m_stream || (m_pending_length > 0);
} // bit_istream::operator bool()
| void claw::bit_istream< Stream >::read | ( | char * | buf, |
| unsigned int | n | ||
| ) |
Read some bits.
| buf | A buffer in which we write the bits. |
| n | The number of bits to read. |
Definition at line 51 of file bit_istream.tpp.
{
if ( n == 0 )
return;
unsigned int cur_size = 0;
while ( (n != 0) && !!(*this) )
{
while( (m_pending_length != 0) && (n!=0) && !!(*this) )
{
unsigned int bits = std::min((unsigned int)m_pending_length, n);
if ( CHAR_BIT - cur_size < bits )
bits = CHAR_BIT - cur_size;
unsigned int mask = (1 << bits) - 1;
*buf |= (m_pending & mask) << cur_size;
cur_size += bits;
m_pending_length -= bits;
m_pending >>= bits;
n -= bits;
if ( cur_size == CHAR_BIT )
{
++buf;
cur_size = 0;
}
}
if ( m_pending_length == 0 )
if ( m_stream.read( (char*)&m_pending, sizeof(m_pending) ) )
m_pending_length = CHAR_BIT;
}
} // bit_istream::read()
unsigned char claw::bit_istream< Stream >::m_pending [private] |
Some bits available for reading.
Definition at line 58 of file bit_istream.hpp.
unsigned char claw::bit_istream< Stream >::m_pending_length [private] |
The number of valid bits in m_pending.
Definition at line 61 of file bit_istream.hpp.
stream_type& claw::bit_istream< Stream >::m_stream [private] |
The stream we're reading.
Definition at line 55 of file bit_istream.hpp.
1.7.3