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

SampleParser Class Reference
[Parsers]

#include <sampleparser.hpp>

Inheritance diagram for SampleParser:

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 45 of file sampleparser.hpp.

Public Member Functions

 SampleParser ()
 constructor

 ~SampleParser ()
 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

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


Member Function Documentation

virtual bool SampleParser::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 61 of file sampleparser.hpp.

00061 {return true;};

virtual bool SampleParser::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 63 of file sampleparser.hpp.

00063 {return true;};

bool SampleParser::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 28 of file sampleparser.cpp.

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

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

bool SampleParser::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 65 of file sampleparser.cpp.

References bitwriter::put().

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

string SampleParser::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 88 of file sampleparser.cpp.

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

virtual bool SampleParser::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 82 of file sampleparser.hpp.

00082 {return false;};

virtual bool SampleParser::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 83 of file sampleparser.hpp.

00083 {return true;};

virtual bool SampleParser::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 84 of file sampleparser.hpp.

00084 {return true;};


Member Data Documentation

bool SampleParser::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 50 of file sampleparser.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