Slim numerical data compression 1.0
obitstream Class Reference

Output bit stream. More...

Inheritance diagram for obitstream:
bitstream

Public Member Functions

 obitstream (FILE *file, int buffersize=DEFAULT_IOBUFFER_SIZE)
 Start obitstream using a FILE ptr to an open file.
 
 obitstream (const char *filename, int buffersize=DEFAULT_IOBUFFER_SIZE)
 Start outputbitstream by filename.
 
void writebits (uint32_t data, int nbits)
 Write data to the buffer.
 
void writestring (const char *str, bool write_trailing_null=false)
 Write 8-bit character strings to the buffer.
 
template<typename T >
void writeword (const T data)
 Write all the bits of a word.
 
void write_unary (unsigned int value)
 Write a unary code for the value.
 
virtual void print () const
 Print buffer contents.
 
virtual void close ()
 Close the output stream by flushing and closing the FILE *.
 
virtual bool is_open () const
 Is the IO file closed?
 
void windup ()
 Put the current word to the buffer with upper 0 bits as needed.
 
void flush (bool flush_trailing_bits)
 Flush the write buffer and reset for more data.
 
- 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.
 
virtual void setupstream ()
 Allocate a buffer and set up all pointers.
 
virtual int get_bytes_used ()
 Return the number of bytes used so far in this stream.
 
int get_bitptr ()
 Get the position of the bitptr.
 

Protected Attributes

FILE * fp
 The I/O stream.
 
- 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.
 

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

Output bit stream.

Allows you to write data one bit at a time with buffered writing.

Member Function Documentation

◆ close()

void obitstream::close ( )
virtual

Close the output stream by flushing and closing the FILE *.

Implements bitstream.

References flush(), fp, and windup().

◆ flush()

void obitstream::flush ( bool flush_trailing_bits)

Flush the write buffer and reset for more data.

Do we need to flush even the partial words, as at EOF?

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

Referenced by close(), and writebits().

◆ is_open()

bool obitstream::is_open ( ) const
virtual

Is the IO file closed?

Implements bitstream.

References fp.

◆ print()

void obitstream::print ( ) const
virtual

Print buffer contents.

Implements bitstream.

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

◆ windup()

void obitstream::windup ( )
virtual

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

Implements bitstream.

References bitstream::bitptr, and writebits().

Referenced by close().

◆ write_unary()

void obitstream::write_unary ( unsigned int value)

Write a unary code for the value.

Code will be (value) 1s followed by a zero. Since low-order bits are "first" in our convention, this means that the code for 4 is the 5-bit value 01111, interpreted by the reader as 1,1,1,1,0.

Parameters
valueThe value to be coded.

The length of the code for (value) is 1+value bits.

References bitstream::Bits_per_word, and writebits().

Referenced by mexp_golomb_write().

◆ writebits()

void obitstream::writebits ( uint32_t data32,
int nbits )

Write data to the buffer.

Parameters
nbitsNumber of bits to use
dataData to write (in the lowest nbits bits).

References bitstream::beyondbuffer, bitstream::bitptr, bitstream::Bits_per_word, bitstream::buffptr, and flush().

Referenced by mexp_golomb_write(), windup(), write_unary(), writestring(), and writeword().

◆ writestring()

void obitstream::writestring ( const char * str,
bool write_trailing_null = false )

Write 8-bit character strings to the buffer.

Parameters
strThe string to write. 0-terminated
write_trailing_nullWhether to put the 0 terminator to the output.

References writebits().

◆ writeword()

template<typename T >
template void obitstream::writeword< uint32_t > ( const T data)

Write all the bits of a word.

Instantiation for several types.

Parameters
dataThe word to write.

References writebits().


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