21 #ifndef G_BIT_STREAM__H
22 #define G_BIT_STREAM__H
58 typedef T bit_iterator_type ;
59 typedef typename T::byte_iterator_type static_assert_T_is_bit_iterator ;
77 unsigned char get(
int bits ) ;
100 bool at_end(
bool default_ =
false )
const ;
113 size_t tellg()
const ;
117 template <
typename U> U get_imp(
int nbits =
sizeof(U) * 8 ) ;
127 template <
typename T>
132 m_end_defined(true) ,
137 template <
typename T>
142 m_end_defined(false) ,
147 template <
typename T>
151 for(
int i = 0 ; i < nbits ; i++ )
153 if( m_end_defined && m_p == m_end )
164 template <
typename T>
167 return get_imp<unsigned char>( 1 ) == 1U ;
170 template <
typename T>
173 return get_imp<unsigned char>( 8 ) ;
176 template <
typename T>
179 return get_imp<unsigned char>( n ) ;
182 template <
typename T>
185 return get_imp<unsigned char>( 8 ) ;
188 template <
typename T>
191 return get_imp<g_uint16_t>( 16 ) ;
194 template <
typename T>
197 return get_imp<g_uint32_t>( 32 ) ;
200 template <
typename T>
203 unsigned int u = ExpGolomb::decode<unsigned int>( m_p , m_end , &m_failbit ) ;
204 return ExpGolomb::make_signed<int>( u ) ;
207 template <
typename T>
210 return ExpGolomb::decode<unsigned int>( m_p , m_end , &m_failbit ) ;
213 template <
typename T>
216 return m_end_defined ? ( m_p == m_end ) : default_ ;
219 template <
typename T>
225 template <
typename T>
231 template <
typename T>
235 throw std::underflow_error(
"bitstream underflow") ;
238 template <
typename T>
241 return m_p - m_begin ;
244 template <
typename T>
251 template <
typename T>
252 bit_stream<T> & operator>>( bit_stream<T> & stream ,
unsigned char & value )
254 value = stream.get_byte() ;
258 template <
typename T>
259 bit_stream<T> & operator>>( bit_stream<T> & stream , g_uint16_t & value )
261 value = stream.get_word() ;
265 template <
typename T>
266 bit_stream<T> & operator>>( bit_stream<T> & stream , g_uint32_t & value )
268 value = stream.get_dword() ;
272 template <
typename T>
273 bit_stream<T> & operator>>( bit_stream<T> & stream , ExpGolomb::value<unsigned int> & value )
275 value.n = stream.get_unsigned_golomb() ;
279 template <
typename T>
280 bit_stream<T> & operator>>( bit_stream<T> & stream , ExpGolomb::value<int> & value )
282 value.n = stream.get_signed_golomb() ;
void check()
Checks for a failed state and throws if failed.
g_uint16_t get_word()
Gets a word. Sets the fail state on underflow.
bit_stream(T begin, T end)
Constructor taking a G::bit_iterator<X> pair where the underlying byte source has a well-defined end...
bool good() const
Returns !fail().
unsigned int get_unsigned_golomb()
Gets an exp-golomb encoded unsigned value. Sets the fail state on underflow.
unsigned char get_byte()
Gets a byte. Sets the fail state on underflow.
bool at_end(bool default_=false) const
Returns true if the bit iterator is equal to the end iterator.
int get_signed_golomb()
Gets an exp-golomb encoded signed value. Sets the fail state on underflow.
A class for pulling integer values of various widths out of a bit stream.
bool fail() const
Returns the fail state.
size_t tellg() const
Returns the current bit offset.
bool get_bool()
Extracts a boolean. Sets the fail state on underflow.
unsigned char get()
Gets a byte.
g_uint32_t get_dword()
Gets a dword. Sets the fail state on underflow.