NCBI C++ ToolKit
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
mu::ParserByteCode Class Reference

Search Toolkit Book for mu::ParserByteCode

Bytecode implementation of the Math Parser. More...

#include <gui/utils/muparser/muParserBytecode.h>

+ Collaboration diagram for mu::ParserByteCode:

Public Types

typedef bytecode_type map_type
 Underlying type of the container. More...
 

Public Member Functions

 ParserByteCode ()
 Bytecode default constructor. More...
 
 ~ParserByteCode ()
 Destructor (trivial). More...
 
 ParserByteCode (const ParserByteCode &a_ByteCode)
 Copy constructor. More...
 
ParserByteCodeoperator= (const ParserByteCode &a_ByteCode)
 Assignment operator. More...
 
void Assign (const ParserByteCode &a_ByteCode)
 Copy state of another object to this. More...
 
void AddVar (value_type *a_pVar)
 Add a Variable pointer to bytecode. More...
 
void AddVal (value_type a_fVal)
 Add a Variable pointer to bytecode. More...
 
void AddOp (ECmdCode a_Oprt)
 Add an operator identifier to bytecode. More...
 
void AddAssignOp (value_type *a_pVar)
 Add an assignement operator. More...
 
void AddFun (void *a_pFun, int a_iArgc)
 Add function to bytecode. More...
 
void AddStrFun (void *a_pFun, int a_iArgc, int a_iIdx)
 Add Strung function entry to the parser bytecode. More...
 
void Finalize ()
 Add end marker to bytecode. More...
 
void clear ()
 Delete the bytecode. More...
 
std::size_t GetBufSize () const
 
const map_typeGetRawData () const
 Get Pointer to bytecode data storage. More...
 
unsigned GetValSize () const
 Return size of a value entry. More...
 
unsigned GetPtrSize () const
 Return size of a pointer entry. More...
 
void RemoveValEntries (unsigned a_iNumber)
 Remove a value number of entries from the bytecode. More...
 
void AsciiDump ()
 Dump bytecode (for debugging only!). More...
 

Private Types

typedef ParserToken< value_type, string_typetoken_type
 Token type for internal use only. More...
 
typedef std::vector< map_typestorage_type
 Core type of the bytecode. More...
 

Private Member Functions

void StorePtr (void *a_pAddr)
 Store an address in bytecode. More...
 

Private Attributes

unsigned m_iStackPos
 Position in the Calculation array. More...
 
storage_type m_vBase
 Core type of the bytecode. More...
 
const int mc_iSizeVal
 Size of a value entry in the bytecode, relative to TMapType size. More...
 
const int mc_iSizePtr
 Size of a pointer, relative to size of underlying TMapType. More...
 
const int mc_iSizeValEntry
 A value entry requires that much entires in the bytecode. More...
 

Detailed Description

Bytecode implementation of the Math Parser.

The bytecode contains the formula converted to revers polish notation stored in a continious memory area. Associated with this data are operator codes, variable pointers, constant values and function pointers. Those are necessary in order to calculate the result. All those data items will be casted to the underlying datatype of the bytecode.

Author
(C) 2004, 2005 Ingo Berg

Definition at line 55 of file muParserBytecode.h.

Member Typedef Documentation

◆ map_type

Underlying type of the container.

The bytecode is a vector of this type containing control codes, values and pointers. Values and pointer will be casted to this type before their storage.

Definition at line 64 of file muParserBytecode.h.

◆ storage_type

typedef std::vector<map_type> mu::ParserByteCode::storage_type
private

Core type of the bytecode.

Definition at line 72 of file muParserBytecode.h.

◆ token_type

Token type for internal use only.

Definition at line 69 of file muParserBytecode.h.

Constructor & Destructor Documentation

◆ ParserByteCode() [1/2]

mu::ParserByteCode::ParserByteCode ( )

Bytecode default constructor.

Definition at line 47 of file muParserBytecode.cpp.

References m_vBase.

◆ ~ParserByteCode()

mu::ParserByteCode::~ParserByteCode ( )

Destructor (trivial).

Definition at line 59 of file muParserBytecode.cpp.

◆ ParserByteCode() [2/2]

mu::ParserByteCode::ParserByteCode ( const ParserByteCode a_ByteCode)

Copy constructor.

Implemented in Terms of Assign(const ParserByteCode &a_ByteCode)

Definition at line 67 of file muParserBytecode.cpp.

References Assign().

Member Function Documentation

◆ AddAssignOp()

void mu::ParserByteCode::AddAssignOp ( value_type a_pVar)

Add an assignement operator.

Operator entries in byte code consist of:

  • cmASSIGN code
  • the pointer of the destination variable
See also
ParserToken::ECmdCode

Definition at line 207 of file muParserBytecode.cpp.

References mu::cmASSIGN, m_iStackPos, m_vBase, and StorePtr().

Referenced by mu::ParserBase::ApplyBinOprt().

◆ AddFun()

void mu::ParserByteCode::AddFun ( void *  a_pFun,
int  a_iArgc 
)

Add function to bytecode.

Parameters
a_iArgcNumber of arguments, negative numbers indicate multiarg functions.
a_pFunPointer to function callback.

Definition at line 220 of file muParserBytecode.cpp.

References mu::cmFUNC, m_iStackPos, m_vBase, and StorePtr().

Referenced by mu::ParserBase::ApplyNumFunc().

◆ AddOp()

void mu::ParserByteCode::AddOp ( ECmdCode  a_Oprt)

Add an operator identifier to bytecode.

Operator entries in byte code consist of:

  • value array position of the result
  • the operator code according to ParserToken::ECmdCode
See also
ParserToken::ECmdCode

Definition at line 190 of file muParserBytecode.cpp.

References m_iStackPos, and m_vBase.

Referenced by mu::ParserBase::ApplyBinOprt().

◆ AddStrFun()

void mu::ParserByteCode::AddStrFun ( void *  a_pFun,
int  a_iArgc,
int  a_iIdx 
)

Add Strung function entry to the parser bytecode.

Exceptions
nothrowA string function entry consists of the stack position of the return value, followed by a cmSTRFUNC code, the function pointer and an index into the string buffer maintained by the parser.

Definition at line 246 of file muParserBytecode.cpp.

References mu::cmFUNC_STR, m_iStackPos, m_vBase, and StorePtr().

Referenced by mu::ParserBase::ApplyStrFunc().

◆ AddVal()

void mu::ParserByteCode::AddVal ( value_type  a_fVal)

Add a Variable pointer to bytecode.

Value entries in byte code consist of:

  • value array position of the value
  • the operator code according to ParserToken::cmVAL
  • the value stored in mc_iSizeVal number of bytecode entries.
Parameters
a_pValValue to be added.
Exceptions
nothrow

Definition at line 170 of file muParserBytecode.cpp.

References mu::cmVAL, i, m_iStackPos, m_vBase, and mc_iSizeVal.

Referenced by mu::ParserBase::ApplyBinOprt(), mu::ParserBase::ApplyNumFunc(), and mu::ParserBase::ParseString().

◆ AddVar()

void mu::ParserByteCode::AddVar ( value_type a_pVar)

Add a Variable pointer to bytecode.

Parameters
a_pVarPointer to be added.
Exceptions
nothrow

Definition at line 141 of file muParserBytecode.cpp.

References assert, mu::cmVAR, i, m_iStackPos, m_vBase, mc_iSizePtr, mc_iSizeVal, and StorePtr().

Referenced by mu::ParserBase::ParseString().

◆ AsciiDump()

void mu::ParserByteCode::AsciiDump ( )

◆ Assign()

void mu::ParserByteCode::Assign ( const ParserByteCode a_ByteCode)

Copy state of another object to this.

Exceptions
nowthrow

Definition at line 127 of file muParserBytecode.cpp.

References m_iStackPos, and m_vBase.

Referenced by operator=(), and ParserByteCode().

◆ clear()

void mu::ParserByteCode::clear ( void  )

Delete the bytecode.

Exceptions
nothrowThe name of this function is a violation of my own coding guidelines but this way it's more in line with the STL functions thus more intuitive.

Definition at line 295 of file muParserBytecode.cpp.

References m_iStackPos, and m_vBase.

Referenced by mu::ParserBase::ClearFormula(), and mu::ParserBase::ReInit().

◆ Finalize()

void mu::ParserByteCode::Finalize ( void  )

Add end marker to bytecode.

Exceptions
nothrow

Definition at line 262 of file muParserBytecode.cpp.

References mu::cmEND, and m_vBase.

Referenced by mu::ParserBase::ParseString().

◆ GetBufSize()

std::size_t mu::ParserByteCode::GetBufSize ( ) const

Definition at line 281 of file muParserBytecode.cpp.

References m_vBase.

Referenced by mu::ParserBase::ParseString().

◆ GetPtrSize()

unsigned mu::ParserByteCode::GetPtrSize ( ) const
inline

Return size of a pointer entry.

That many bytecode entries are necessary to store a pointer.

See also
mc_iSizePtr

Definition at line 142 of file muParserBytecode.h.

References mc_iSizePtr.

Referenced by mu::ParserBase::ParseCmdCode().

◆ GetRawData()

const ParserByteCode::map_type * mu::ParserByteCode::GetRawData ( ) const

Get Pointer to bytecode data storage.

Definition at line 274 of file muParserBytecode.cpp.

References assert, and m_vBase.

Referenced by mu::ParserBase::ParseString().

◆ GetValSize()

unsigned mu::ParserByteCode::GetValSize ( ) const
inline

Return size of a value entry.

That many bytecode entries are necessary to store a value.

See also
mc_iSizeVal

Definition at line 131 of file muParserBytecode.h.

References mc_iSizeVal.

Referenced by mu::ParserBase::ParseCmdCode(), and mu::ParserBase::ParseString().

◆ operator=()

ParserByteCode & mu::ParserByteCode::operator= ( const ParserByteCode a_ByteCode)

Assignment operator.

Implemented in Terms of Assign(const ParserByteCode &a_ByteCode)

Definition at line 80 of file muParserBytecode.cpp.

References Assign().

◆ RemoveValEntries()

void mu::ParserByteCode::RemoveValEntries ( unsigned  a_iNumber)

Remove a value number of entries from the bytecode.

Attention
Currently I don't test if the entries are really value entries.

Definition at line 306 of file muParserBytecode.cpp.

References assert, m_iStackPos, m_vBase, and mc_iSizeValEntry.

Referenced by mu::ParserBase::ApplyBinOprt(), and mu::ParserBase::ApplyNumFunc().

◆ StorePtr()

void mu::ParserByteCode::StorePtr ( void *  a_pAddr)
private

Store an address in bytecode.

Parameters
a_pAddrAddress to be stored.
Exceptions
nothrow

Definition at line 92 of file muParserBytecode.cpp.

References i, m_vBase, and mc_iSizePtr.

Referenced by AddAssignOp(), AddFun(), AddStrFun(), and AddVar().

Member Data Documentation

◆ m_iStackPos

unsigned mu::ParserByteCode::m_iStackPos
private

Position in the Calculation array.

Definition at line 75 of file muParserBytecode.h.

Referenced by AddAssignOp(), AddFun(), AddOp(), AddStrFun(), AddVal(), AddVar(), Assign(), clear(), and RemoveValEntries().

◆ m_vBase

storage_type mu::ParserByteCode::m_vBase
private

◆ mc_iSizePtr

const int mu::ParserByteCode::mc_iSizePtr
private

Size of a pointer, relative to size of underlying TMapType.

Attention
The size is related to the size of TMapType not bytes!

Definition at line 87 of file muParserBytecode.h.

Referenced by AddVar(), AsciiDump(), GetPtrSize(), and StorePtr().

◆ mc_iSizeVal

const int mu::ParserByteCode::mc_iSizeVal
private

Size of a value entry in the bytecode, relative to TMapType size.

Definition at line 81 of file muParserBytecode.h.

Referenced by AddVal(), AddVar(), AsciiDump(), and GetValSize().

◆ mc_iSizeValEntry

const int mu::ParserByteCode::mc_iSizeValEntry
private

A value entry requires that much entires in the bytecode.

Value entry consists of:

  • One entry for Stack index
  • One entry for Token identifier
  • mc_iSizeVal entries for the value
    AddVal(TBaseData a_fVal)

Definition at line 100 of file muParserBytecode.h.

Referenced by RemoveValEntries().


The documentation for this class was generated from the following files:
Modified on Wed Apr 17 13:09:21 2024 by modify_doxy.py rev. 669887