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

BitParser Class Reference
[Parsers]

#include <bitparser.hpp>

Inheritance diagram for BitParser:

OctaneParser OctaneClass List of all members.

Detailed Description

Sample parser class is just character based, uses one symbol for each ascii character plus one for end-of-stream.

Because it uses a fixed symbol set it is ready to parse without any training.

Definition at line 41 of file bitparser.hpp.

Public Member Functions

 BitParser ()
 constructor

 ~BitParser ()
 destructor

virtual bool CreateSymbolSetUsingStream (bitreader &from)
 Process (train on) an input stream to update/create a symbol set from it.

virtual bool IsReadyToParse ()
 are we ready to parse? i.e. has symbol set been built.

virtual bool RewindAnyBufferedInput (bitreader &from)
 Let go of any buffered stream - this is an odd function that can be called be compressor if it wants to hand off the input stream to a new parser or otherwise access the input bitstream from after last symbol parsed.

virtual void SynchronizeStateForNewStream ()
 Synchronize state for a new stream - this will always be called before beginning a new parsing stream, and should be used to reset the parse into any initial predictable state.

virtual int GetSymbolCount ()
 Get a count of the number of symbols stored in the parser.

virtual bool ParseNextSymbolFromInput (bitreader &from, int &symbolnum)
 Parse the next symbol from the input and return its #.

virtual bool WriteSymbolText (bitwriter &to, int symbolnum, bool &isendofstreamsymbol)
 Parse the next symbol from the input, and set symbolnum to the symbol id#,.

virtual string LookupSymbolText (int symbolnum)
 Helper function to return the text string of a symbol number.

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 SaveState (bitwriter &to, bool fortempdecompressiononly)
 Save state of object to output stream (if appropriate).

virtual bool LoadState (bitreader &from)
 Load state of object from input stream (if appropriate).


Protected Attributes

int Parameter_bitlength
 The number of bits per chunk.

bool senteos
 We need to track whether we sent an EOS yet.


Member Function Documentation

virtual bool BitParser::CreateSymbolSetUsingStream bitreader from  )  [inline, virtual]
 

Process (train on) an input stream to update/create a symbol set from it.

Returns:
true on success

Reimplemented from OctaneParser.

Definition at line 60 of file bitparser.hpp.

00060 {return true;};

virtual bool BitParser::RewindAnyBufferedInput bitreader from  )  [inline, virtual]
 

Let go of any buffered stream - this is an odd function that can be called be compressor if it wants to hand off the input stream to a new parser or otherwise access the input bitstream from after last symbol parsed.

it is necessary because some parsers can read-ahead in input buffer, and so must rewind the bitstream.

Reimplemented from OctaneParser.

Definition at line 62 of file bitparser.hpp.

00062 {return true;};

bool BitParser::ParseNextSymbolFromInput bitreader from,
int &  symbolnum
[virtual]
 

Parse the next symbol from the input and return its #.

Note:
The end of stream situation must to be handled specially:

When a parser encounters the end of a stream, it *MUST* return a symbol signifying an end-of-stream symbol.

This end of stream symbol must be a unique symbol from the symbol set.

Returns:
false *after* the end of stream symbol is returned on prior call.

Implements OctaneParser.

Definition at line 32 of file bitparser.cpp.

References bitreader::empty(), bitreader::get(), and senteos.

00033 {
00034         // grab an input stream symbol and set its INDEX (in symbol vector) for symbolnum
00035         // return false after EOS
00036         unsigned char c;
00037 
00038         // are we at end of from input - this is the only non-intuitive step
00039         // the issue is that only the parser knows about end-of-stream symbols, and when it hits and end of input
00040         // it basically needs to reply TWICE, first with an end-of-stream, and then with a reply saying 'no more symbols'
00041         if (from.empty())
00042                 {
00043                 // no more symbols left - BUT the question now is, do we return an EOS symbol, or false for no symbols left
00044                 if (senteos)
00045                         {
00046                         // we already sent an EOS so from now on any requests for a symbol returns false saying no more symbols available
00047                         return false;
00048                         }
00049                 else
00050                         {
00051                         // we are going to drop down to return the EOS signal, but we set flag so we don't do it again
00052                         senteos=true;
00053                         }
00054                 // end of stream symbol number
00055                 symbolnum=SampleParser_EndOfStreamSYMBOL;
00056                 }
00057         else
00058                 {
00059                 // grab an unsigned character from input and assign the symbol # to its ascii number
00060                 from.get(c);
00061                 symbolnum=(int)c;
00062                 }
00063 
00064         // return true, saying we read a symbol
00065         return true;
00066 }

bool BitParser::WriteSymbolText bitwriter to,
int  symbolnum,
bool &  isendofstreamsymbol
[virtual]
 

Parse the next symbol from the input, and set symbolnum to the symbol id#,.

Returns:
false *after* end of stream (i.e. first response at end of stream should be the end-of-stream symbol).

Implements OctaneParser.

Definition at line 69 of file bitparser.cpp.

References bitwriter::put().

00070 {
00071         // write the symbol indexed by symbolnum
00072         // sets isendofostreamsymbol to true or false depending on if the symbol written is the EOS symbol
00073         // return true on success
00074 
00075         if (symbolnum==SampleParser_EndOfStreamSYMBOL)
00076                 {
00077                 // this is end of stream symbol, so do nothing but set EOS flag
00078                 isendofstreamsymbol=true;
00079                 }
00080         else
00081                 {
00082                 // not EOS, so write it and set EOS flag false
00083                 to.put((unsigned char)symbolnum);
00084                 isendofstreamsymbol=false;
00085                 }
00086 
00087         // return success
00088         return true;
00089 }

string BitParser::LookupSymbolText int  symbolnum  )  [virtual]
 

Helper function to return the text string of a symbol number.

Returns:
a string with the text of the symbol
Note:
this should be the empty string to signify end of stream symbol.

Implements OctaneParser.

Definition at line 92 of file bitparser.cpp.

00093         {
00094         // return the string text corresponding to symbol 'symbolnum'
00095         if (symbolnum==SampleParser_EndOfStreamSYMBOL)
00096                 return "";
00097         char cstr[2];
00098         cstr[0]=(unsigned char)symbolnum;
00099         cstr[1]='\0';
00100         return string(cstr);
00101         }

bool BitParser::SetParameter const std::string &  parametername,
const std::string &  parametervalue
[inline, 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 81 of file bitparser.hpp.

00081 {return false;};

bool BitParser::SaveState bitwriter to,
bool  fortempdecompressiononly
[inline, virtual]
 

Save state of object to output stream (if appropriate).

Returns:
true on success (or if no information needs to be saved).

Reimplemented from OctaneClass.

Definition at line 82 of file bitparser.hpp.

00082 {return true;};

bool BitParser::LoadState bitreader from  )  [inline, virtual]
 

Load state of object from input stream (if appropriate).

Returns:
true on success (or if no information needs to be loaded).

Reimplemented from OctaneClass.

Definition at line 83 of file bitparser.hpp.

00083 {return true;};


Member Data Documentation

bool BitParser::senteos [protected]
 

We need to track whether we sent an EOS yet.

Todo:
there should be a way to do this automatically perhaps with a wrapper, rather than insisting all derived parsers deal with returning an EOS symbol.

Definition at line 49 of file bitparser.hpp.

Referenced by ParseNextSymbolFromInput(), and SynchronizeStateForNewStream().


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