bitparser.hpp

来自「Octane v1.01.20 The Open Compression To」· HPP 代码 · 共 96 行

HPP
96
字号
/// @file bitparser.hpp
/// A bit-level parser that can be told how many bits per symbol, and returns numbers converted bit chunks
///
/// @remarks
/// the basic idea is you can set bitlength from 1 to 99, and it will parse
/// the input in chunks of bitlength bytes, returning a symbol #
/// corresponding to the index of the bitstring in the list of possible
/// bit patterns of bitlength.
///
/// @author mouser
/// @date   2004.01.25
///
/// @todo:
/// this is not finished yet
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// recursive header protection
#ifndef BitParserH
#define BitParserH
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// application includes
#include "../parser.hpp"
#include "../../bitio/bitio.hpp"
// system includes
using namespace std;
//---------------------------------------------------------------------------






//---------------------------------------------------------------------------
/// 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 BitParser : public OctaneParser
{
protected:
	/// The number of bits per chunk
	int Parameter_bitlength;
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
	BitParser() {bitlength=1;};
	/// destructor
	~BitParser() {;};
	//---------------------------------------------------------------------------
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 &parametername,const std::string &parametervalue) {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 + =
减小字号Ctrl + -
显示快捷键?