Slim numerical data compression 1.0
ibitstream Class Reference

Input bit stream. More...

Inheritance diagram for ibitstream:
bitstream

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 (int fd, int buffersize=DEFAULT_IOBUFFER_SIZE)
 Start inputbitstream by file descriptor.
 
 ~ibitstream ()
 Destructor only uses base class destructor.
 
virtual void close ()
 Close the IO file.
 
virtual bool is_open () const
 Is the IO file closed?
 
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 (const char *filename, int buffersize=DEFAULT_IOBUFFER_SIZE)
 Start bitstream by filename.
 
virtual ~bitstream ()
 Destructor deletes output buffer, closes file.
 
int get_bitptr ()
 Get the position of the bitptr.
 

Protected Attributes

FILE * fp
 
- Protected Attributes inherited from bitstream
size_t bufsize
 Size of I/O buffer (bytes)
 
size_t buf_used
 
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.
 

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 }
 
- 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

◆ close()

void ibitstream::close ( )
virtual

Close the IO file.

Implements bitstream.

Referenced by ~ibitstream().

◆ fill()

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, and bitstream::bufsize.

Referenced by next_word(), and setupstream().

◆ get_bytes_used()

int ibitstream::get_bytes_used ( )
virtual

Return the number of bytes used so far in this stream.

Reimplemented from bitstream.

References bitstream::beyondbuffer, bitstream::bitptr, bitstream::buf_used, and bitstream::buffptr.

◆ is_open()

bool ibitstream::is_open ( ) const
virtual

Is the IO file closed?

Implements bitstream.

◆ print()

void ibitstream::print ( ) const
virtual

Print buffer contents.

Implements bitstream.

References bitstream::bitptr, bitstream::buffer_base, and bitstream::buffptr.

◆ read_unary()

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().

◆ readbits()

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().

◆ readbits_int()

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().

◆ readstring()

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().

◆ setupstream()

void ibitstream::setupstream ( )
virtual

Allocate a buffer and set up all pointers, then fill buffer.

Reimplemented from bitstream.

References bitstream::bufsize, fill(), and bitstream::setupstream().

Referenced by ibitstream(), ibitstream(), and ibitstream().

◆ windup()

void ibitstream::windup ( )
virtual

Put the current word to the buffer with upper 0 bits as needed.

Implements bitstream.

References bitstream::bitptr, and readbits().


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