EMAN2
Public Member Functions | Private Attributes | Friends | List of all members
EMAN::BitStream< T > Class Template Reference

#include <eerio.h>

Collaboration diagram for EMAN::BitStream< T >:
Collaboration graph
[legend]

Public Member Functions

 BitStream (T *buf)
 
get_bits (int N)
 

Private Attributes

T * buffer
 
cur
 
const size_t max_num_bits = 8*sizeof(T)
 
size_t bit_counter = max_num_bits
 

Friends

std::ostream & operator<< (std::ostream &out, const BitStream &obj)
 

Detailed Description

template<class T>
class EMAN::BitStream< T >

Definition at line 44 of file eerio.h.

Constructor & Destructor Documentation

◆ BitStream()

template<class T >
EMAN::BitStream< T >::BitStream ( T *  buf)
inline

Definition at line 46 of file eerio.h.

47 : buffer(buf), cur(*buffer)
48 {}
T * buffer
Definition: eerio.h:71

Member Function Documentation

◆ get_bits()

template<class T >
T EMAN::BitStream< T >::get_bits ( int  N)
inline

Definition at line 50 of file eerio.h.

50 {
51 auto result = cur & ((1 << N) - 1);
52
53 if(N < bit_counter) {
54 cur >>= N;
55 bit_counter -= N;
56 }
57 else {
58 auto remaining_bits = N - bit_counter;
59
60 cur = *(++buffer);
61 result |= ((cur & ((1 << remaining_bits) - 1)) << bit_counter);
62
63 cur >>= remaining_bits;
64 bit_counter = max_num_bits - remaining_bits;
65 }
66
67 return result;
68 }
size_t bit_counter
Definition: eerio.h:74
const size_t max_num_bits
Definition: eerio.h:73

References EMAN::BitStream< T >::bit_counter, EMAN::BitStream< T >::buffer, EMAN::BitStream< T >::cur, and EMAN::BitStream< T >::max_num_bits.

Friends And Related Function Documentation

◆ operator<<

template<class T >
std::ostream & operator<< ( std::ostream &  out,
const BitStream< T > &  obj 
)
friend

Definition at line 76 of file eerio.h.

76 {
77 return out<<"cur: "<<std::bitset<8*sizeof(T)>(obj.cur)
78 <<endl
79 <<"bit_counter: "<<obj.bit_counter<<endl
80 <<"max_num_bits: "<<obj.max_num_bits<<endl;
81 }

Member Data Documentation

◆ bit_counter

template<class T >
size_t EMAN::BitStream< T >::bit_counter = max_num_bits
private

Definition at line 74 of file eerio.h.

Referenced by EMAN::BitStream< T >::get_bits().

◆ buffer

template<class T >
T* EMAN::BitStream< T >::buffer
private

Definition at line 71 of file eerio.h.

Referenced by EMAN::BitStream< T >::get_bits().

◆ cur

template<class T >
T EMAN::BitStream< T >::cur
private

Definition at line 72 of file eerio.h.

Referenced by EMAN::BitStream< T >::get_bits().

◆ max_num_bits

template<class T >
const size_t EMAN::BitStream< T >::max_num_bits = 8*sizeof(T)
private

Definition at line 73 of file eerio.h.

Referenced by EMAN::BitStream< T >::get_bits().


The documentation for this class was generated from the following file: