Octane v1.01.20 - The Open Compression Toolkit for C++ http://octane.sourceforge.net/
Homepage | Main | Modules | Class Hierarchy | Compound List | File List | Compound Members | Related Pages

SampleCompressor Class Reference
[Compressors]

#include <samplecompressor.hpp>

Inheritance diagram for SampleCompressor:

OctaneCompressor OctaneClass List of all members.

Detailed Description

This Sample Statistical Compressor is a minimal example of how to coordinate the 3 components of the statistical compressor framework, a sample parser,modeler,and coder.

Definition at line 34 of file samplecompressor.hpp.

Public Member Functions

 SampleCompressor (bool registerme=false)
 constructor

 ~SampleCompressor ()
 destructor

virtual std::string GetClassName ()
 Get the assigned name of an instantiated compressor.

virtual std::string GetDescription ()
 optionally provide a longer (maybe 20-60 characters) description

virtual OctaneCompressorMakeCompressorInstantiation ()
 Instantiate a compressor from this class (like a factory).

virtual void ShowDebuggingInfo ()
 show any debugging info on request (used by various derived classes) [optional]

virtual unsigned int GetMemoryUsed ()
 Report actual current memory usage (in bytes).

virtual unsigned int GetDiskspaceUsed (bool fortempdecompressiononly)
 Report disk space (in bytes) that would be used when saving state to file (in bytes).

virtual std::string GetParametersInformation ()
 Reports information about any parameters available.

virtual void SetDefaultParameters ()
 Reset any parameters to their default values.

virtual bool SetParameter (const std::string &parametername, const std::string &parametervalue)
 This function is called to set a variable value.

virtual bool IsReadyToCompress ()
 is the compressor ready to compress? Normally this is false until a dictionary is built or loaded.


Protected Member Functions

virtual bool DoProtectedCompress (bitreader &from, bitwriter &to)
 This is the member function which does the actual compression, and this is the function that should be subclasses by derived classes.

virtual bool DoProtectedDecompress (bitreader &from, bitwriter &to)
 This is the member function which does the actual decompression, and this is the function that should be subclasses by derived classes.

virtual bool DoProtectedCreateSymbolsAndModelsUsingStream (bitreader &from)
 This is the member function which does the actual training on an input in order to generate parsers/modelers/coders, and this is the function that should be subclasses by derived classes.

virtual bool DoProtectedSaveState (bitwriter &to, bool fortempdecompressiononly)
 This is the member function which does the actual saving of state, and this is the function that should be subclasses by derived classes.

virtual bool DoProtectedLoadState (bitreader &from)
 This is the member function which does the actual loading of state, and this is the function that should be subclasses by derived classes.


Protected Attributes

unsigned char Parameter_xorbyte
 a byte which the sample compressor xors with incoming or outgoing bytes


Member Function Documentation

virtual std::string SampleCompressor::GetDescription  )  [inline, virtual]
 

optionally provide a longer (maybe 20-60 characters) description

Returns:
a one line description

Reimplemented from OctaneCompressor.

Definition at line 48 of file samplecompressor.hpp.

00048 {return "Sample Compressor";}

bool SampleCompressor::SetParameter const std::string &  parametername,
const std::string &  parametervalue
[virtual]
 

This function is called to set a variable value.

Note:
this can be called with a variable not owned by this class, in which case the function should return false.
Returns:
true if the variable was found (whether it was set properly or not).

Reimplemented from OctaneClass.

Definition at line 87 of file samplecompressor.cpp.

References Parameter_xorbyte, and OctaneClass::ParseParameter().

00088 {
00089         // Generic function for user-interactive modification of parameters
00090         // Return true if we know this variable and use it
00091         bool bretv=false;
00092         
00093         // we have 1 variable we use, called xorbyte
00094         if (parametername=="xorbyte")
00095                 bretv=ParseParameter(parametervalue,Parameter_xorbyte);
00096                 
00097         // return success
00098         return bretv;
00099 }

bool SampleCompressor::IsReadyToCompress  )  [virtual]
 

is the compressor ready to compress? Normally this is false until a dictionary is built or loaded.

Returns:
true on success

Reimplemented from OctaneCompressor.

Definition at line 105 of file samplecompressor.cpp.

00106 {
00107         // Are we ready to compress?
00108         // This sample compressor is always ready (needs no training)
00109         return true;
00110 }

bool SampleCompressor::DoProtectedCompress bitreader from,
bitwriter to
[protected, virtual]
 

This is the member function which does the actual compression, and this is the function that should be subclasses by derived classes.

It is wrapped by the public API call Compress() which performs some measurements on compression speed and streamsize.

Note:
this function should never be called by an outside class - the API interface should be called instead.
Returns:
true on success

Implements OctaneCompressor.

Definition at line 117 of file samplecompressor.cpp.

References bitreader::empty(), bitreader::get_byte(), Parameter_xorbyte, and bitwriter::put_byte().

00118 {
00119         // Here is the main compression routine
00120         // Our sample compressor doesn't actually compress, instead it just xors 
00121 
00122         // loop through input and 'compress' (xor) it
00123         unsigned char c;
00124         while (!from.empty())
00125                 {
00126                 // grab a character from input
00127                 c=from.get_byte();
00128                 // xor it with our parameter
00129                 c= c ^ Parameter_xorbyte;
00130                 // send it to output
00131                 to.put_byte(c);
00132                 }
00133 
00134         // return success
00135         return true;
00136 }

bool SampleCompressor::DoProtectedDecompress bitreader from,
bitwriter to
[protected, virtual]
 

This is the member function which does the actual decompression, and this is the function that should be subclasses by derived classes.

It is wrapped by the public API call Decompress() which performs some measurements on decompression speed and streamsize.

Note:
this function should never be called by an outside class - the API interface should be called instead.
Returns:
true on success

Implements OctaneCompressor.

Definition at line 139 of file samplecompressor.cpp.

References bitreader::empty(), bitreader::get_byte(), Parameter_xorbyte, and bitwriter::put_byte().

00140 {
00141         // Here is the main decompression routine
00142         // Our sample compressor doesn't actually decompress, instead it just xors 
00143 
00144         // loop through input and 'compress' (xor) it
00145         unsigned char c;
00146         while (!from.empty())
00147                 {
00148                 // grab a character from input
00149                 c=from.get_byte();
00150                 // xor it with our parameter
00151                 c= Parameter_xorbyte ^ c;
00152                 // send it to output
00153                 to.put_byte(c);
00154                 }
00155 
00156         // return success
00157         return true;
00158 }

bool SampleCompressor::DoProtectedCreateSymbolsAndModelsUsingStream bitreader from  )  [protected, virtual]
 

This is the member function which does the actual training on an input in order to generate parsers/modelers/coders, and this is the function that should be subclasses by derived classes.

It is wrapped by the public API call CreateSymbolsAndModelsUsingStream() which performs some measurements on speed and streamsize.

Note:
this function should never be called by an outside class - the API interface should be called instead.
Returns:
true on success

Reimplemented from OctaneCompressor.

Definition at line 165 of file samplecompressor.cpp.

References bitreader::empty(), and bitreader::get_byte().

00166 {
00167         // OPTIONAL: this is called to 'train' a compressor, to let a compressor gather statistics from an input stream.
00168         // Our sample compressor does not need to implement this, but we include it here just for fun so you see what it looks like.
00169         // return false only on an error.
00170         
00171         // let's read the training input stream, just to show you how its done.
00172         unsigned char c;
00173         while (!from.empty())
00174                 {
00175                 // grab a character, but we dont do anything with it.
00176                 c=from.get_byte();
00177                 }
00178 
00179         // return success
00180         return true;
00181 }

bool SampleCompressor::DoProtectedSaveState bitwriter to,
bool  fortempdecompressiononly
[protected, virtual]
 

This is the member function which does the actual saving of state, and this is the function that should be subclasses by derived classes.

It is wrapped by the public API call SaveState() which performs some measurements on speed and streamsize.

Note:
this function should never be called by an outside class - the API interface should be called instead.
Returns:
true on success

Reimplemented from OctaneCompressor.

Definition at line 183 of file samplecompressor.cpp.

References Parameter_xorbyte, and bitwriter::put().

00184 {
00185         // OPTIONAL: save any compressor internal state (like variables or learned statistics).
00186         // Many compressors have no interenal state to save, but this sample compressor has a variable
00187         //  which should be saved.
00188         // The flag fortempdecompressiononly will be set if the state is being saved for decompression *only*
00189         //  so that if there is some information is only needed for compression, we dont have to save it if we dont need it.
00190 
00191         // just tell the bitwriter to save the variables
00192         to.put(Parameter_xorbyte);
00193 
00194         // return true on success
00195         return true;
00196 }

bool SampleCompressor::DoProtectedLoadState bitreader from  )  [protected, virtual]
 

This is the member function which does the actual loading of state, and this is the function that should be subclasses by derived classes.

It is wrapped by the public API call LoadState() which performs some measurements on speed and streamsize.

Note:
this function should never be called by an outside class - the API interface should be called instead.
Returns:
true on success

Reimplemented from OctaneCompressor.

Definition at line 198 of file samplecompressor.cpp.

References bitreader::get(), and Parameter_xorbyte.

00199 {
00200         // OPTIONAL: load any compressor internal state (like variables or learned statistics).
00201         // Many compressors have no interenal state to save, but this sample compressor has a variable
00202         //  which should be saved.
00203 
00204         // just tell the bitwriter to save the variables
00205         from.get(Parameter_xorbyte);
00206 
00207         // return true on success
00208         return true;
00209 }


The documentation for this class was generated from the following files:  
Generated on 20 May 2004 by doxygen 1.3.3