37 template<
typename Stream>
39 : m_stream(f), m_pending(0), m_pending_length(0)
50 template<
typename Stream>
56 unsigned int cur_size = 0;
58 while ( (n != 0) && !!(*
this) )
60 while( (m_pending_length != 0) && (n!=0) && !!(*
this) )
62 unsigned int bits = std::min((
unsigned int)m_pending_length, n);
64 if ( CHAR_BIT - cur_size < bits )
65 bits = CHAR_BIT - cur_size;
67 unsigned int mask = (1 << bits) - 1;
69 *buf |= (m_pending & mask) << cur_size;
71 m_pending_length -= bits;
75 if ( cur_size == CHAR_BIT )
82 if ( m_pending_length == 0 )
83 if ( m_stream.read( (
char*)&m_pending,
sizeof(m_pending) ) )
84 m_pending_length = CHAR_BIT;
92 template<
typename Stream>
95 return m_stream || (m_pending_length > 0);