37 template<
typename Stream>
39 : m_stream(f), m_pending(0), m_pending_length(0)
48 template<
typename Stream>
51 if (m_pending_length != 0)
52 m_stream.
write( (
char*)&m_pending,
sizeof(m_pending) );
61 template<
typename Stream>
67 unsigned int cur_size = 0;
68 unsigned char data = *buf;
72 while( (m_pending_length != CHAR_BIT) && (n!=0) )
75 std::min(CHAR_BIT - (
unsigned int)m_pending_length, n);
77 if ( CHAR_BIT - cur_size < bits )
78 bits = CHAR_BIT - cur_size;
80 unsigned int mask = (1 << bits) - 1;
82 m_pending |= (data & mask) << m_pending_length;
84 m_pending_length += bits;
88 if ( (cur_size == CHAR_BIT) && (n!=0) )
96 if ( m_pending_length == CHAR_BIT )
98 m_stream.write( (
char*)&m_pending,
sizeof(m_pending) );
100 m_pending_length = 0;