| Octane v1.01.20 - The Open Compression Toolkit for C++ | http://octane.sourceforge.net/ |
#include <bitwriter.hpp>
Inheritance diagram for bitwriter:

The bitwriter class is a wrapper which provides bit output functionality to anything supporting output of 8-bit chars (bytes). It attempts to be as clean and transparent as possible, while maintaining a fairly decent efficiency.
The base class contains functions for handling the output by collecting bits in a temporary store (a byte), writing them out when the store is full.
It is used by creating a sub-class and implementing the write_next_byte() member function.
The destructor of the derived class should call finalize().
Definition at line 40 of file bitwriter.hpp.
Public Member Functions | |
| bitwriter () | |
| Constructor. | |
| virtual | ~bitwriter () |
| Destructor. | |
| virtual bool | error () const |
| Check for error. | |
| void | align_byte () |
| Align bitwriter on a byte boundary. | |
Size Functions | |
| size_t | bits_done () const |
| Return the number of bits written. | |
| size_t | bytes_done () const |
| Return the number of bytes written. | |
| size_t | tell_bit () const |
| Return the current bit position within the bit stream. | |
| size_t | tell_byte () const |
| Return the current byte position within the bit stream. | |
Output Functions | |
| void | put_bit (bool v) |
| Write one bit to the output. | |
| void | put_byte (unsigned char v) |
| Write one byte (8-bit unsigned value). | |
| void | put_word (unsigned short v) |
| Write one word (16-bit unsigned value). | |
| void | put_dword (unsigned long v) |
| Write one dword (32-bit unsigned value). | |
| void | put_float (float v) |
| Write one float. | |
| void | put_double (double v) |
| Write one double. | |
| void | put_string (std::string &s) |
| Write a string. | |
| void | write (const char *buffer, size_t length) |
| Copy bytes from an array to the bitwriter. | |
Polymorphic Output Function Wrappers | |
| void | put (bool v) |
| void | put (char v) |
| void | put (unsigned char v) |
| void | put (short v) |
| void | put (unsigned short v) |
| void | put (int v) |
| void | put (unsigned int v) |
| void | put (long v) |
| void | put (unsigned long v) |
| void | put (float v) |
| void | put (double v) |
| void | put (std::string &s) |
Protected Member Functions | |
| void | finalize () |
| Perform cleanup. | |
| virtual void | write_next_byte (char c)=0 |
| Defines the method of writing a single byte of output. | |
Protected Attributes | |
| size_t | num |
| Number of bytes written. | |
|
|
Destructor. Derived classes should implement a destructor which calls the finalize() member function. Definition at line 48 of file bitwriter.hpp.
00048 { ; }
|
|
|
Check for error.
Reimplemented in file_bitwriter. Definition at line 53 of file bitwriter.hpp.
00053 { return false; }
|
|
|
Return the number of bits written.
Definition at line 72 of file bitwriter.hpp. References num. Referenced by tell_bit().
00072 { return 8*num + 8 - log2_tab[mask]; }
|
|
|
Return the number of bytes written.
Definition at line 75 of file bitwriter.hpp. References num. Referenced by tell_byte().
00075 { return num; }
|
|
|
Return the current bit position within the bit stream.
Definition at line 79 of file bitwriter.hpp. References bits_done().
00079 { return bits_done(); }
|
|
|
Return the current byte position within the bit stream.
Definition at line 83 of file bitwriter.hpp. References bytes_done(). Referenced by OctaneCompressor::Compress(), OctaneCompressor::Decompress(), and OctaneCompressor::Save().
00083 { return bytes_done(); }
|
|
|
Write one bit to the output.
Definition at line 93 of file bitwriter.hpp. References num, and write_next_byte(). Referenced by HuffNode_Leaf::AddBitsToBitWriter().
00094 {
00095 if (v) current |= mask;
00096 if (!(mask >>= 1))
00097 {
00098 ++num; write_next_byte(current);
00099 current = 0;
00100 mask = 0x80;
00101 }
00102 }
|
|
|
Write one byte (8-bit unsigned value).
Definition at line 106 of file bitwriter.hpp. References num, and write_next_byte(). Referenced by zleCompressor::DoProtectedCompress(), SampleCompressor::DoProtectedCompress(), mtfllCompressor::DoProtectedCompress(), zleCompressor::DoProtectedDecompress(), SampleCompressor::DoProtectedDecompress(), mtfllCompressor::DoProtectedDecompress(), put_dword(), put_word(), OctaneCompressor::SaveCompressionHeader(), OctaneCompressor::SaveGUID(), and write().
00107 {
00108 ++num;
00109
00110 if (mask == 0x80) { write_next_byte(v); return; }
00111
00112 unsigned char ml = log2_tab[mask];
00113 current |= v >> (8 - ml);
00114 write_next_byte(current);
00115 current = v << ml;
00116 }
|
|
|
Write one word (16-bit unsigned value).
Definition at line 120 of file bitwriter.hpp. References put_byte(). Referenced by put_string().
|
|
|
Write one dword (32-bit unsigned value).
Definition at line 128 of file bitwriter.hpp. References put_byte(). Referenced by put_string().
|
|
|
Write one float.
Definition at line 140 of file bitwriter.hpp. References write().
00140 { write((char*)&v, sizeof(float)); }
|
|
|
Write one double.
Definition at line 146 of file bitwriter.hpp. References write().
00146 { write((char*)&v, sizeof(double)); }
|
|
|
Write a string.
Definition at line 150 of file bitwriter.hpp. References put_dword(), put_word(), and write().
|
|
||||||||||||
|
Copy bytes from an array to the bitwriter.
Definition at line 168 of file bitwriter.hpp. References put_byte(). Referenced by put_double(), put_float(), put_string(), and SubstringParser::WriteSymbolText().
00169 {
00170 for ( ; length; --length) put_byte(*buffer++);
00171 }
|
|
|
Perform cleanup. Derived classes should call this method from their destructor. Definition at line 203 of file bitwriter.hpp. References align_byte().
00203 { align_byte(); }
|
|
|
Defines the method of writing a single byte of output. Derived classes should implement this function.
Implemented in null_bitwriter, stream_bitwriter, vector_bitwriter, string_bitwriter, array_bitwriter, and file_bitwriter. Referenced by align_byte(), put_bit(), and put_byte(). |