Slim numerical data compression 1.0
|
Output bit stream. More...
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. | |
![]() | |
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. | ||
![]() | ||
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 | |
![]() | |
enum | { DEFAULT_IOBUFFER_SIZE =1024*1024 } |
Make *Dptr always point to same place as Bptr. More... | |
enum | { MAX_BITSTREAM_BUFSIZE =16*1024*1024 } |
![]() | |
static const int | Bits_per_word = 8*sizeof(Word_t) |
Bits per buffer word. | |
Output bit stream.
Allows you to write data one bit at a time with buffered writing.
|
virtual |
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().
|
virtual |
|
virtual |
Print buffer contents.
Implements bitstream.
References bitstream::bitptr, bitstream::buffer_base, and bitstream::buffptr.
|
virtual |
Put the current word to the buffer with upper 0 bits as needed.
Implements bitstream.
References bitstream::bitptr, and writebits().
Referenced by close().
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.
value | The 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().
void obitstream::writebits | ( | uint32_t | data32, |
int | nbits ) |
Write data to the buffer.
nbits | Number of bits to use |
data | Data 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().
void obitstream::writestring | ( | const char * | str, |
bool | write_trailing_null = false ) |
Write 8-bit character strings to the buffer.
str | The string to write. 0-terminated |
write_trailing_null | Whether to put the 0 terminator to the output. |
References writebits().
template void obitstream::writeword< uint32_t > | ( | const T | data | ) |
Write all the bits of a word.
Instantiation for several types.
data | The word to write. |
References writebits().