Slim numerical data compression  1.0
Public Member Functions | Private Member Functions | Private Attributes
ibitstream Class Reference

Input bit stream. More...

Inheritance diagram for ibitstream:
bitstream

List of all members.

Public Member Functions

 ibitstream (FILE *file, int buffersize=DEFAULT_IOBUFFER_SIZE)
 Start ibitstream using a FILE ptr to an open file.
 ibitstream (const char *filename, int buffersize=DEFAULT_IOBUFFER_SIZE)
 Start inputbitstream by filename.
 ~ibitstream ()
 Destructor only uses base class destructor.
void setupstream ()
 Allocate a buffer and set up all pointers, then fill buffer.
void windup ()
 Put the current word to the buffer with upper 0 bits as needed.
virtual void print () const
 Print buffer contents.
virtual int get_bytes_used ()
 Return the number of bytes used so far in this stream.
Word_t readbits (int nbits)
 Read data from the buffer as unsigned ints.
int32_t readbits_int (int nbits)
 Read data from the buffer as (signed) ints.
Word_t read_unary ()
 Read a single unary-coded value.
int readstring (char *s, int count=-1)
 Read a null-terminated string of 8-bit characters from the bit stream.
- Public Member Functions inherited from bitstream
 bitstream ()
 Dummy default constructor.
 bitstream (FILE *file, int buffersize=DEFAULT_IOBUFFER_SIZE)
 Start bitstream using a FILE ptr to an open file.
 bitstream (const char *filename, int buffersize=DEFAULT_IOBUFFER_SIZE)
 Start bitstream by filename.
 bitstream (const bitstream &b)
 Copy constructor.
bitstreamoperator= (const bitstream &b)
 Assignment operator.
virtual ~bitstream ()
 Destructor deletes output buffer, closes file.
virtual void close ()
 Close the IO file.
bool is_open () const
 Is the IO file closed?
int get_bitptr ()
 Get the position of the bitptr.

Private Member Functions

void next_word ()
 Move to next word in buffer, refilling it if needed.
int fill ()
 Fill the read buffer and reset for more data.

Private Attributes

Word_t partial_word
int partial_word_bitptr

Additional Inherited Members

- Public Types inherited from bitstream
enum  { DEFAULT_IOBUFFER_SIZE = 1024*1024 }
 Make *Dptr always point to same place as Bptr. More...
enum  { MAX_BITSTREAM_BUFSIZE = 16*1024*1024 }
- Protected Attributes inherited from bitstream
size_t bufsize
 Size of I/O buffer (bytes)
size_t buf_used
 

words ever I/O between buffer and disk.


FILE * fp
 The I/O stream.
Byte_t * buffer_base
 Pointer to the buffer.
Byte_t * beyondbuffer
 Pointer just beyond buffer (convenience).
union {
   Byte_t *   Bptr
 Pointer to the current word (as Byte_t *).
   Word_t *   Dptr
 Pointer to the current word (as Word_t *).
buffptr
 Pointer to the current word.
int bitptr
 Pointer to the current bits.
- Static Protected Attributes inherited from bitstream
static const int Bits_per_word = 8*sizeof(Word_t)
 Bits per buffer word.

Detailed Description

Input bit stream.

Allows you to read data N bits at a time with buffered reading.


Member Function Documentation

int ibitstream::fill ( )
private

Fill the read buffer and reset for more data.

Returns:
Bytes read from disk.

References bitstream::beyondbuffer, bitstream::bitptr, bitstream::buf_used, bitstream::buffer_base, bitstream::buffptr, bitstream::bufsize, and bitstream::fp.

Referenced by next_word(), and setupstream().

Word_t ibitstream::read_unary ( )

Read a single unary-coded value.

Returns:
The unary-coded value from the stream.

References readbits().

Referenced by mexp_golomb_read_u32().

Word_t ibitstream::readbits ( int  n_bits)

Read data from the buffer as unsigned ints.

Parameters:
n_bitsNumber of bits to use
Returns:
Data read (in the lowest n_bits bits).

References bitstream::bitptr, bitstream::Bits_per_word, bitstream::buffptr, and next_word().

Referenced by mexp_golomb_read_u32(), read_unary(), readbits_int(), readstring(), and windup().

int ibitstream::readbits_int ( int  n_bits)

Read data from the buffer as (signed) ints.

Parameters:
n_bitsNumber of bits to read.
Returns:
The data read from the stream.

References readbits().

int ibitstream::readstring ( char *  s,
int  count = -1 
)

Read a null-terminated string of 8-bit characters from the bit stream.

Parameters:
sPointer to the string (must be available memory).
countMaximum size of the string.
Returns:
Number of chars read (including null).

References readbits().


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