📄 sampleparser.hpp
字号:
/// @file sampleparser.hpp
/// A simple sample parser for use in statistical compression
///
/// @remarks
/// This is a sample parser that can be used as the skeleton for building
/// new parsers. It is a simple character parser - that is, it builder 256
/// symbols, one for each character plus one for end-of-stream, and just
/// returns the ascii character # it reads.
///
/// @author mouser
/// @date 2003.07.29
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// recursive header protection
#ifndef SampleParserH
#define SampleParserH
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// application includes
#include "../parser.hpp"
#include "../../bitio/bitio.hpp"
// system includes
using namespace std;
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// this parser uses 256 symbols
// symbols 0-255 are ascii characters, symbol 255 is used for end of stream
#define SampleParser_EndOfStreamSYMBOL 255
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
/// 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.
/// @ingroup Parsers
class SampleParser : public OctaneParser
{
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.
bool senteos;
public:
//---------------------------------------------------------------------------
/// constructor
SampleParser() {;};
/// destructor
~SampleParser() {;};
//---------------------------------------------------------------------------
public:
//---------------------------------------------------------------------------
// PARSER PUBLIC API - PREPARATIONS FOR PARSING
virtual bool CreateSymbolSetUsingStream(bitreader &from) {return true;};
virtual bool IsReadyToParse() {return true;};
virtual bool RewindAnyBufferedInput(bitreader &from) {return true;};
//---------------------------------------------------------------------------
public:
//---------------------------------------------------------------------------
// PARSER PUBLIC API - MAIN PARSING FUNCTIONS
virtual void SynchronizeStateForNewStream();
virtual int GetSymbolCount() {return 256;};
virtual bool ParseNextSymbolFromInput(bitreader &from, int &symbolnum);
virtual bool WriteSymbolText(bitwriter &to, int symbolnum,bool &isendofstreamsymbol);
virtual string LookupSymbolText(int symbolnum);
//---------------------------------------------------------------------------
public:
//---------------------------------------------------------------------------
// OCTANE PUBLIC API - AUXILIARY FUNCTIONS - these are supported by all derived classes
virtual void ShowDebuggingInfo() {;};
virtual unsigned int GetMemoryUsed() {return (unsigned int)(sizeof(this));};
virtual unsigned int GetDiskspaceUsed(bool fortempdecompressiononly) {return (unsigned int)0;};
virtual std::string GetParametersInformation() {return "";};
virtual void SetDefaultParameters() {;};
virtual bool SetParameter(const std::string ¶metername,const std::string ¶metervalue) {return false;};
virtual bool SaveState(bitwriter &to,bool fortempdecompressiononly) {return true;};
virtual bool LoadState(bitreader &from) {return true;};
//---------------------------------------------------------------------------
};
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -