NCBI C++ ToolKit
Public Types | Public Member Functions | Protected Member Functions | Static Protected Attributes | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
mu::ParserBase Class Referenceabstract

Search Toolkit Book for mu::ParserBase

Mathematical expressions parser (base parser engine). More...

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

+ Inheritance diagram for mu::ParserBase:
+ Collaboration diagram for mu::ParserBase:

Public Types

typedef ParserError exception_type
 Type of the error class. More...
 

Public Member Functions

 ParserBase ()
 Constructor. More...
 
 ParserBase (const ParserBase &a_Parser)
 
ParserBaseoperator= (const ParserBase &a_Parser)
 Assignement operator. More...
 
virtual ~ParserBase ()
 
value_type Eval () const
 Calculate the result. More...
 
void SetExpr (const string_type &a_sExpr)
 Set the formula. More...
 
void SetVarFactory (facfun_type a_pFactory, void *pUserData=NULL)
 
void EnableOptimizer (bool a_bIsOn=true)
 Enable or disable the formula optimization feature. More...
 
void EnableByteCode (bool a_bIsOn=true)
 Enable or disable parsing from Bytecode. More...
 
void EnableBuiltInOprt (bool a_bIsOn=true)
 Enable or disable the built in binary operators. More...
 
bool HasBuiltInOprt () const
 Query status of built in variables. More...
 
void AddValIdent (identfun_type a_pCallback)
 
void DefineFun (const string_type &a_strName, fun_type0 a_pFun, bool a_bAllowOpt=true)
 
void DefineFun (const string_type &a_strName, fun_type1 a_pFun, bool a_bAllowOpt=true)
 
void DefineFun (const string_type &a_strName, fun_type2 a_pFun, bool a_bAllowOpt=true)
 
void DefineFun (const string_type &a_strName, fun_type3 a_pFun, bool a_bAllowOpt=true)
 
void DefineFun (const string_type &a_strName, fun_type4 a_pFun, bool a_bAllowOpt=true)
 
void DefineFun (const string_type &a_strName, fun_type5 a_pFun, bool a_bAllowOpt=true)
 
void DefineFun (const string_type &a_strName, multfun_type a_pFun, bool a_bAllowOpt=true)
 
void DefineFun (const string_type &a_strName, strfun_type1 a_pFun, bool a_bAllowOpt=true)
 
void DefineFun (const string_type &a_strName, strfun_type2 a_pFun, bool a_bAllowOpt=true)
 
void DefineFun (const string_type &a_strName, strfun_type3 a_pFun, bool a_bAllowOpt=true)
 
void DefineOprt (const string_type &a_strName, fun_type2 a_pFun, unsigned a_iPri=0, bool a_bAllowOpt=false)
 Define a binary operator. More...
 
void DefineConst (const string_type &a_sName, value_type a_fVal)
 Add a user defined constant. More...
 
void DefineStrConst (const string_type &a_sName, const string_type &a_strVal)
 Define a new string constant. More...
 
void DefineVar (const string_type &a_sName, value_type *a_fVar)
 Add a user defined variable. More...
 
void DefinePostfixOprt (const string_type &a_strFun, fun_type1 a_pOprt, bool a_bAllowOpt=true)
 Add a user defined operator. More...
 
void DefineInfixOprt (const string_type &a_strName, fun_type1 a_pOprt, int a_iPrec=prINFIX, bool a_bAllowOpt=true)
 Add a user defined operator. More...
 
void ClearVar ()
 Clear all user defined variables. More...
 
void ClearFun ()
 Clear all functions. More...
 
void ClearConst ()
 Clear all user defined constants. More...
 
void ClearInfixOprt ()
 Clear the user defined Prefix operators. More...
 
void ClearPostfixOprt ()
 Clear all user defined postfix operators. More...
 
void ClearOprt ()
 Clear all user defined binary operators. More...
 
void RemoveVar (const string_type &a_strVarName)
 Remove a variable from internal storage. More...
 
const varmap_typeGetUsedVar () const
 Return a map containing the used variables only. More...
 
const varmap_typeGetVar () const
 Return a map containing the used variables only. More...
 
const valmap_typeGetConst () const
 Return a map containing all parser constants. More...
 
const string_typeGetExpr () const
 Retrieve the formula. More...
 
const funmap_typeGetFunDef () const
 Return prototypes of all parser functions. More...
 
const char_type ** GetOprtDef () const
 Get the default symbols used for the built in operators. More...
 
void DefineNameChars (const char_type *a_szCharset)
 Define the set of valid characters to be used in names of functions, variables, constants. More...
 
void DefineOprtChars (const char_type *a_szCharset)
 Define the set of valid characters to be used in names of binary operators and postfix operators. More...
 
void DefineInfixOprtChars (const char_type *a_szCharset)
 Define the set of valid characters to be used in names of infix operators. More...
 
const char_typeValidNameChars () const
 Virtual function that defines the characters allowed in name identifiers. More...
 
const char_typeValidOprtChars () const
 Virtual function that defines the characters allowed in operator definitions. More...
 
const char_typeValidInfixOprtChars () const
 Virtual function that defines the characters allowed in infix operator definitions. More...
 
void SetArgSep (char_type cArgSep)
 Set argument separator. More...
 
char_type GetArgSep () const
 Get the argument separator character. More...
 
void Error (EErrorCodes a_iErrc, int a_iPos=(int) mu::string_type::npos, const string_type &a_strTok=string_type()) const
 Create an error containing the parse error position. More...
 

Protected Member Functions

void Init ()
 Initialize user defined functions. More...
 
virtual void InitCharSets ()=0
 
virtual void InitFun ()=0
 
virtual void InitConst ()=0
 
virtual void InitOprt ()=0
 

Static Protected Attributes

static const char_typec_DefaultOprt []
 Identifiers for built in binary operators. More...
 

Private Types

typedef value_type(ParserBase::* ParseFunction) () const
 Typedef for the parse functions. More...
 
typedef std::vector< string_typestringbuf_type
 Type for a vector of strings. More...
 
typedef ParserTokenReader token_reader_type
 Typedef for the token reader. More...
 
typedef ParserToken< value_type, string_typetoken_type
 Type used for parser tokens. More...
 

Private Member Functions

void Assign (const ParserBase &a_Parser)
 Copy state of a parser object to this. More...
 
void InitTokenReader ()
 Initialize the token reader. More...
 
void ReInit () const
 Reset parser to string parsing mode and clear internal buffers. More...
 
void AddCallback (const string_type &a_strName, const ParserCallback &a_Callback, funmap_type &a_Storage, const char_type *a_szCharSet)
 Add a function or operator callback to the parser. More...
 
void ApplyBinOprt (ParserStack< token_type > &a_stOpt, ParserStack< token_type > &a_stVal) const
 
void ApplyFunc (ParserStack< token_type > &a_stOpt, ParserStack< token_type > &a_stVal, int iArgCount) const
 Apply a function token. More...
 
token_type ApplyNumFunc (const token_type &a_FunTok, const std::vector< token_type > &a_vArg) const
 
token_type ApplyStrFunc (const token_type &a_FunTok, const std::vector< token_type > &a_vArg) const
 Execute a function that takes a single string argument. More...
 
int GetOprtPri (const token_type &a_Tok) const
 Get operator priority. More...
 
value_type ParseString () const
 One of the two main parse functions. More...
 
value_type ParseCmdCode () const
 Parse the command code. More...
 
value_type ParseValue () const
 Return result for constant functions. More...
 
void ClearFormula ()
 Clear the formula. More...
 
void CheckName (const string_type &a_strName, const string_type &a_CharSet) const
 Check if a name contains invalid characters. More...
 

Private Attributes

ParseFunction m_pParseFormula
 Pointer to the parser function. More...
 
const ParserByteCode::map_typem_pCmdCode
 Formula converted to bytecode, points to the data of the bytecode class. More...
 
ParserByteCode m_vByteCode
 The Bytecode class. More...
 
stringbuf_type m_vStringBuf
 String buffer, used for storing string function arguments. More...
 
stringbuf_type m_vStringVarBuf
 
std::unique_ptr< token_reader_typem_pTokenReader
 Managed pointer to the token reader object. More...
 
funmap_type m_FunDef
 Map of function names and pointers. More...
 
funmap_type m_PostOprtDef
 Postfix operator callbacks. More...
 
funmap_type m_InfixOprtDef
 unary infix operator. More...
 
funmap_type m_OprtDef
 Binary operator callbacks. More...
 
valmap_type m_ConstDef
 user constants. More...
 
strmap_type m_StrVarDef
 user defined string constants More...
 
varmap_type m_VarDef
 user defind variables. More...
 
bool m_bOptimize
 Flag that indicates if the optimizer is on or off. More...
 
bool m_bUseByteCode
 Flag that indicates if bytecode parsing is on or off. More...
 
bool m_bBuiltInOp
 Flag that can be used for switching built in operators on and off. More...
 
string_type m_sNameChars
 Charset for names. More...
 
string_type m_sOprtChars
 Charset for postfix/ binary operator tokens. More...
 
string_type m_sInfixOprtChars
 Charset for infix operator tokens. More...
 

Friends

class ParserTokenReader
 

Detailed Description

Mathematical expressions parser (base parser engine).

Version 1.30 (20080413)

This is the implementation of a bytecode based mathematical expressions parser. The formula will be parsed from string and converted into a bytecode. Future calculations will be done with the bytecode instead the formula string resulting in a significant performance increase. Complementary to a set of internally implemented functions the parser is able to handle user defined functions and variables.

Author
(C) 2004-2008 Ingo Berg

Definition at line 63 of file muParserBase.h.

Member Typedef Documentation

◆ exception_type

Type of the error class.

Included for backwards compatibility.

Definition at line 92 of file muParserBase.h.

◆ ParseFunction

typedef value_type(ParserBase::* mu::ParserBase::ParseFunction) () const
private

Typedef for the parse functions.

The parse function do the actual work. The parser exchanges the function pointer to the parser function depending on which state it is in. (i.e. bytecode parser vs. string parser)

Definition at line 75 of file muParserBase.h.

◆ stringbuf_type

typedef std::vector<string_type> mu::ParserBase::stringbuf_type
private

Type for a vector of strings.

Definition at line 78 of file muParserBase.h.

◆ token_reader_type

Typedef for the token reader.

Definition at line 81 of file muParserBase.h.

◆ token_type

Type used for parser tokens.

Definition at line 84 of file muParserBase.h.

Constructor & Destructor Documentation

◆ ParserBase() [1/2]

mu::ParserBase::ParserBase ( )

Constructor.

Parameters
a_szFormulathe formula to interpret.
Exceptions
ParserExceptionif a_szFormula is null.

Definition at line 68 of file muParserBase.cpp.

References InitTokenReader().

◆ ParserBase() [2/2]

mu::ParserBase::ParserBase ( const ParserBase a_Parser)

Definition at line 92 of file muParserBase.cpp.

References Assign(), and m_pTokenReader.

◆ ~ParserBase()

mu::ParserBase::~ParserBase ( )
virtual

Definition at line 114 of file muParserBase.cpp.

Member Function Documentation

◆ AddCallback()

void mu::ParserBase::AddCallback ( const string_type a_strName,
const ParserCallback a_Callback,
funmap_type a_Storage,
const char_type a_szCharSet 
)
private

Add a function or operator callback to the parser.

Definition at line 211 of file muParserBase.cpp.

References CheckName(), mu::ecINVALID_FUN_PTR, mu::ecNAME_CONFLICT, Error(), mu::ParserCallback::GetAddr(), m_FunDef, m_InfixOprtDef, m_OprtDef, m_PostOprtDef, and ReInit().

Referenced by DefineInfixOprt(), DefineOprt(), and DefinePostfixOprt().

◆ AddValIdent()

void mu::ParserBase::AddValIdent ( identfun_type  a_pCallback)

◆ ApplyBinOprt()

void mu::ParserBase::ApplyBinOprt ( ParserStack< token_type > &  a_stOpt,
ParserStack< token_type > &  a_stVal 
) const
private

◆ ApplyFunc()

void mu::ParserBase::ApplyFunc ( ParserStack< token_type > &  a_stOpt,
ParserStack< token_type > &  a_stVal,
int  a_iArgCount 
) const
private

Apply a function token.

Parameters
iArgCountNumber of Arguments actually gathered used only for multiarg functions.
Postcondition
The result is pushed to the value stack
The function token is removed from the stack
Exceptions
exception_typeif Argument count does not mach function requirements.

Definition at line 717 of file muParserBase.cpp.

References ApplyNumFunc(), ApplyStrFunc(), assert, mu::cmFUNC_STR, mu::cmOPRT_BIN, mu::ecINTERNAL_ERROR, mu::ecTOO_FEW_PARAMS, mu::ecTOO_MANY_PARAMS, mu::ecVAL_EXPECTED, mu::ParserStack< TValueType >::empty(), Error(), mu::ParserToken< TBase, TString >::GetArgCount(), mu::ParserToken< TBase, TString >::GetAsString(), mu::ParserToken< TBase, TString >::GetCode(), mu::ParserToken< TBase, TString >::GetFuncAddr(), mu::ParserToken< TBase, TString >::GetType(), i, m_pTokenReader, mu::ParserStack< TValueType >::pop(), mu::ParserStack< TValueType >::push(), mu::ParserStack< TValueType >::top(), and mu::tpSTR.

Referenced by ApplyBinOprt(), and ParseString().

◆ ApplyNumFunc()

ParserBase::token_type mu::ParserBase::ApplyNumFunc ( const token_type a_FunTok,
const std::vector< token_type > &  a_vArg 
) const
private

◆ ApplyStrFunc()

ParserBase::token_type mu::ParserBase::ApplyStrFunc ( const token_type a_FunTok,
const std::vector< token_type > &  a_vArg 
) const
private

◆ Assign()

void mu::ParserBase::Assign ( const ParserBase a_Parser)
private

Copy state of a parser object to this.

Clears Variables and Functions of this parser. Copies the states of all internal variables. Resets parse function to string parse mode.

Parameters
a_Parserthe source object.

Definition at line 140 of file muParserBase.cpp.

References m_bBuiltInOp, m_bOptimize, m_bUseByteCode, m_ConstDef, m_FunDef, m_InfixOprtDef, m_PostOprtDef, m_pTokenReader, m_sInfixOprtChars, m_sNameChars, m_sOprtChars, m_StrVarDef, m_VarDef, m_vStringBuf, m_vStringVarBuf, and ReInit().

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

◆ CheckName()

void mu::ParserBase::CheckName ( const string_type a_sName,
const string_type a_szCharSet 
) const
private

Check if a name contains invalid characters.

Exceptions
ParserExceptionif the name contains invalid charakters.

Definition at line 244 of file muParserBase.cpp.

References mu::ecINVALID_NAME, and Error().

Referenced by AddCallback(), DefineConst(), DefineStrConst(), and DefineVar().

◆ ClearConst()

void mu::ParserBase::ClearConst ( )

Clear all user defined constants.

Both numeric and string constants will be removed from the internal storage.

Postcondition
Resets the parser to string parsing mode.
Exceptions
nothrow

Definition at line 1319 of file muParserBase.cpp.

References m_ConstDef, m_StrVarDef, and ReInit().

Referenced by mu::Test::ParserTester::TestNames().

◆ ClearFormula()

void mu::ParserBase::ClearFormula ( )
private

Clear the formula.

Postcondition
Resets the parser to string parsing mode.
Exceptions
nothrowClear the formula and existing bytecode.

Definition at line 1293 of file muParserBase.cpp.

References mu::ParserByteCode::clear(), m_pCmdCode, m_pTokenReader, m_vByteCode, ReInit(), and wxT.

◆ ClearFun()

void mu::ParserBase::ClearFun ( )

Clear all functions.

Postcondition
Resets the parser to string parsing mode.
Exceptions
nothrow

Definition at line 1306 of file muParserBase.cpp.

References m_FunDef, and ReInit().

◆ ClearInfixOprt()

void mu::ParserBase::ClearInfixOprt ( )

Clear the user defined Prefix operators.

Postcondition
Resets the parser to string parser mode.
Exceptions
nothrow

Definition at line 1353 of file muParserBase.cpp.

References m_InfixOprtDef, and ReInit().

◆ ClearOprt()

void mu::ParserBase::ClearOprt ( )

Clear all user defined binary operators.

Postcondition
Resets the parser to string parsing mode.
Exceptions
nothrow

Definition at line 1342 of file muParserBase.cpp.

References m_OprtDef, and ReInit().

◆ ClearPostfixOprt()

void mu::ParserBase::ClearPostfixOprt ( )

Clear all user defined postfix operators.

Postcondition
Resets the parser to string parsing mode.
Exceptions
nothrow

Definition at line 1331 of file muParserBase.cpp.

References m_PostOprtDef, and ReInit().

◆ ClearVar()

void mu::ParserBase::ClearVar ( )

Clear all user defined variables.

Exceptions
nothrowResets the parser to string parsing mode by calling ReInit.

Definition at line 1264 of file muParserBase.cpp.

References m_VarDef, and ReInit().

◆ DefineConst()

void mu::ParserBase::DefineConst ( const string_type a_sName,
value_type  a_fVal 
)

Add a user defined constant.

Parameters
[in]a_sNameThe name of the constant.
[in]a_fValthe value of the constant.
Postcondition
Will reset the Parser to string parsing mode.
Exceptions
ParserExceptionin case the name contains invalid signs.

Definition at line 467 of file muParserBase.cpp.

References CheckName(), m_ConstDef, ReInit(), and ValidNameChars().

Referenced by mu::Test::ParserTester::EqnTest(), mu::Test::ParserTester::EqnTestInt(), and mu::Parser::InitConst().

◆ DefineFun() [1/10]

void mu::ParserBase::DefineFun ( const string_type a_strName,
fun_type0  a_pFun,
bool  a_bAllowOpt = true 
)
inline

◆ DefineFun() [2/10]

void mu::ParserBase::DefineFun ( const string_type a_strName,
fun_type1  a_pFun,
bool  a_bAllowOpt = true 
)
inline

Definition at line 139 of file muParserBase.h.

◆ DefineFun() [3/10]

void mu::ParserBase::DefineFun ( const string_type a_strName,
fun_type2  a_pFun,
bool  a_bAllowOpt = true 
)
inline

Definition at line 140 of file muParserBase.h.

◆ DefineFun() [4/10]

void mu::ParserBase::DefineFun ( const string_type a_strName,
fun_type3  a_pFun,
bool  a_bAllowOpt = true 
)
inline

Definition at line 141 of file muParserBase.h.

◆ DefineFun() [5/10]

void mu::ParserBase::DefineFun ( const string_type a_strName,
fun_type4  a_pFun,
bool  a_bAllowOpt = true 
)
inline

Definition at line 142 of file muParserBase.h.

◆ DefineFun() [6/10]

void mu::ParserBase::DefineFun ( const string_type a_strName,
fun_type5  a_pFun,
bool  a_bAllowOpt = true 
)
inline

Definition at line 143 of file muParserBase.h.

◆ DefineFun() [7/10]

void mu::ParserBase::DefineFun ( const string_type a_strName,
multfun_type  a_pFun,
bool  a_bAllowOpt = true 
)
inline

Definition at line 144 of file muParserBase.h.

◆ DefineFun() [8/10]

void mu::ParserBase::DefineFun ( const string_type a_strName,
strfun_type1  a_pFun,
bool  a_bAllowOpt = true 
)
inline

Definition at line 145 of file muParserBase.h.

◆ DefineFun() [9/10]

void mu::ParserBase::DefineFun ( const string_type a_strName,
strfun_type2  a_pFun,
bool  a_bAllowOpt = true 
)
inline

Definition at line 146 of file muParserBase.h.

◆ DefineFun() [10/10]

void mu::ParserBase::DefineFun ( const string_type a_strName,
strfun_type3  a_pFun,
bool  a_bAllowOpt = true 
)
inline

Definition at line 147 of file muParserBase.h.

◆ DefineInfixOprt()

void mu::ParserBase::DefineInfixOprt ( const string_type a_sName,
fun_type1  a_pFun,
int  a_iPrec = prINFIX,
bool  a_bAllowOpt = true 
)

Add a user defined operator.

Postcondition
Will reset the Parser to string parsing mode.
Parameters
[in]a_sNameoperator Identifier
[in]a_pFunOperator callback function
[in]a_iPrecOperator Precedence (default=prSIGN)
[in]a_bAllowOptTrue if operator is volatile (default=false)
See also
EPrec

Definition at line 382 of file muParserBase.cpp.

References AddCallback(), mu::cmOPRT_INFIX, m_InfixOprtDef, and ValidOprtChars().

Referenced by mu::Test::ParserTester::EqnTest(), mu::Parser::InitOprt(), mu::ParserComplex::InitOprt(), and mu::ParserInt::InitOprt().

◆ DefineInfixOprtChars()

void mu::ParserBase::DefineInfixOprtChars ( const char_type a_szCharset)

Define the set of valid characters to be used in names of infix operators.

Definition at line 311 of file muParserBase.cpp.

References m_sInfixOprtChars.

Referenced by mu::Parser::InitCharSets(), mu::ParserComplex::InitCharSets(), and mu::ParserInt::InitCharSets().

◆ DefineNameChars()

void mu::ParserBase::DefineNameChars ( const char_type a_szCharset)

Define the set of valid characters to be used in names of functions, variables, constants.

Definition at line 293 of file muParserBase.cpp.

References m_sNameChars.

Referenced by mu::Parser::InitCharSets(), mu::ParserComplex::InitCharSets(), and mu::ParserInt::InitCharSets().

◆ DefineOprt()

void mu::ParserBase::DefineOprt ( const string_type a_sName,
fun_type2  a_pFun,
unsigned  a_iPrec = 0,
bool  a_bAllowOpt = false 
)

Define a binary operator.

Parameters
[in]a_pFunPointer to the callback function.
[in]a_iPrecPrecedence of the operator.
[in]a_bAllowOptIf this is true the operator may be optimized away.

Definition at line 400 of file muParserBase.cpp.

References AddCallback(), c_DefaultOprt, mu::cmARG_SEP, mu::cmOPRT_BIN, mu::ecBUILTIN_OVERLOAD, Error(), i, m_bBuiltInOp, m_OprtDef, and ValidOprtChars().

Referenced by mu::ParserComplex::InitOprt(), and mu::ParserInt::InitOprt().

◆ DefineOprtChars()

void mu::ParserBase::DefineOprtChars ( const char_type a_szCharset)

Define the set of valid characters to be used in names of binary operators and postfix operators.

Definition at line 302 of file muParserBase.cpp.

References m_sOprtChars.

Referenced by mu::Parser::InitCharSets(), mu::ParserComplex::InitCharSets(), and mu::ParserInt::InitCharSets().

◆ DefinePostfixOprt()

void mu::ParserBase::DefinePostfixOprt ( const string_type a_sName,
fun_type1  a_pFun,
bool  a_bAllowOpt = true 
)

Add a user defined operator.

Postcondition
Will reset the Parser to string parsing mode.

Definition at line 350 of file muParserBase.cpp.

References AddCallback(), mu::cmOPRT_POSTFIX, m_PostOprtDef, mu::prPOSTFIX, and ValidOprtChars().

Referenced by mu::Test::ParserTester::EqnTest().

◆ DefineStrConst()

void mu::ParserBase::DefineStrConst ( const string_type a_strName,
const string_type a_strVal 
)

Define a new string constant.

Parameters
[in]a_strNameThe name of the constant.
[in]a_strValthe value of the constant.

Definition at line 421 of file muParserBase.cpp.

References CheckName(), mu::ecNAME_CONFLICT, Error(), m_StrVarDef, m_vStringBuf, m_vStringVarBuf, ReInit(), and ValidNameChars().

◆ DefineVar()

void mu::ParserBase::DefineVar ( const string_type a_sName,
value_type a_pVar 
)

Add a user defined variable.

Parameters
[in]a_sNamethe variable name
[in]a_pVarA pointer to the variable vaule.
Postcondition
Will reset the Parser to string parsing mode.
Precondition
[assert] a_fVar!=0
Exceptions
ParserExceptionin case the name contains invalid signs.

Definition at line 443 of file muParserBase.cpp.

References CheckName(), mu::ecINVALID_VAR_PTR, mu::ecNAME_CONFLICT, Error(), m_ConstDef, m_FunDef, m_VarDef, ReInit(), and ValidNameChars().

Referenced by mu::Test::ParserTester::EqnTest(), mu::Test::ParserTester::EqnTestInt(), mu::Test::ParserTester::TestInterface(), mu::Test::ParserTester::TestVarConst(), and mu::Test::ParserTester::ThrowTest().

◆ EnableBuiltInOprt()

void mu::ParserBase::EnableBuiltInOprt ( bool  a_bIsOn = true)

Enable or disable the built in binary operators.

Exceptions
nothrow
See also
m_bBuiltInOp, ReInit()

If you disable the built in binary operators there will be no binary operators defined. Thus you must add them manually one by one. It is not possible to disable built in operators selectively. This function will Reinitialize the parser by calling ReInit().

Definition at line 1393 of file muParserBase.cpp.

References m_bBuiltInOp, and ReInit().

Referenced by mu::ParserComplex::InitOprt(), mu::ParserInt::InitOprt(), and mu::Test::ParserTester::TestNames().

◆ EnableByteCode()

void mu::ParserBase::EnableByteCode ( bool  a_bIsOn = true)

Enable or disable parsing from Bytecode.

Attention
There is no reason to disable bytecode. It will drastically decrease parsing speed.

Definition at line 1376 of file muParserBase.cpp.

References m_bUseByteCode, and ReInit().

◆ EnableOptimizer()

void mu::ParserBase::EnableOptimizer ( bool  a_bIsOn = true)

Enable or disable the formula optimization feature.

Postcondition
Resets the parser to string parser mode.
Exceptions
nothrow

Definition at line 1364 of file muParserBase.cpp.

References m_bOptimize, and ReInit().

Referenced by mu::Test::ParserTester::EqnTest().

◆ Error()

void mu::ParserBase::Error ( EErrorCodes  a_iErrc,
int  a_iPos = (int)mu::string_type::npos,
const string_type a_sTok = string_type() 
) const

Create an error containing the parse error position.

This function will create an Parser Exception object containing the error text and its position.

Parameters
a_iErrc[in] The error code of type EErrorCodes.
a_iPos[in] The position where the error was detected.
a_strTok[in] The token string representation associated with the error.
Exceptions
ParserExceptionalways throws thats the only purpose of this function.

Definition at line 1253 of file muParserBase.cpp.

References m_pTokenReader.

Referenced by AddCallback(), ApplyBinOprt(), ApplyFunc(), ApplyNumFunc(), ApplyStrFunc(), CheckName(), DefineOprt(), DefineStrConst(), DefineVar(), mu::ParserTokenReader::Error(), GetOprtPri(), ParseCmdCode(), ParseString(), and SetExpr().

◆ Eval()

value_type mu::ParserBase::Eval ( ) const
inline

Calculate the result.

A note on const correctness: I consider it important that Calc is a const function. Due to caching operations Calc changes only the state of internal variables with one exception m_UsedVar this is reset during string parsing and accessible from the outside. Instead of making Calc non const GetUsedVar is non const because it explicitely calls Eval() forcing this update.

Precondition
A formula must be set.
Variables must have been set (if needed)
See also
m_pParseFormula
Returns
The evaluation result
Exceptions
ParseExceptionif no Formula is set or in case of any other error related to the formula.

Definition at line 116 of file muParserBase.h.

References m_pParseFormula.

Referenced by mu::Parser::Diff(), mu::Test::ParserTester::EqnTest(), mu::Test::ParserTester::EqnTestInt(), mu::ParserComplex::Eval(), mu::Test::ParserTester::TestInterface(), mu::Test::ParserTester::TestVolatile(), and mu::Test::ParserTester::ThrowTest().

◆ GetArgSep()

char_type mu::ParserBase::GetArgSep ( ) const

Get the argument separator character.

Definition at line 1412 of file muParserBase.cpp.

References m_pTokenReader.

◆ GetConst()

const valmap_type & mu::ParserBase::GetConst ( ) const

Return a map containing all parser constants.

Definition at line 545 of file muParserBase.cpp.

References m_ConstDef.

◆ GetExpr()

const string_type & mu::ParserBase::GetExpr ( ) const

Retrieve the formula.

Definition at line 568 of file muParserBase.cpp.

References m_pTokenReader.

◆ GetFunDef()

const funmap_type & mu::ParserBase::GetFunDef ( ) const

Return prototypes of all parser functions.

Returns
m_FunDef
See also
FunProt
Exceptions
nothrowThe return type is a map of the public type funmap_type containing the prototype definitions for all numerical parser functions. String functions are not part of this map. The Prototype definition is encapsulated in objects of the class FunProt one per parser function each associated with function names via a map construct.

Definition at line 561 of file muParserBase.cpp.

References m_FunDef.

◆ GetOprtDef()

const char_type ** mu::ParserBase::GetOprtDef ( ) const

Get the default symbols used for the built in operators.

See also
c_DefaultOprt

Definition at line 284 of file muParserBase.cpp.

References c_DefaultOprt.

Referenced by mu::ParserTokenReader::IsBuiltIn().

◆ GetOprtPri()

int mu::ParserBase::GetOprtPri ( const token_type a_Tok) const
private

◆ GetUsedVar()

const varmap_type & mu::ParserBase::GetUsedVar ( ) const

Return a map containing the used variables only.

Definition at line 514 of file muParserBase.cpp.

References m_pParseFormula, m_pTokenReader, and ParseString().

Referenced by mu::Test::ParserTester::TestVarConst().

◆ GetVar()

const varmap_type & mu::ParserBase::GetVar ( ) const

Return a map containing the used variables only.

Definition at line 538 of file muParserBase.cpp.

References m_VarDef.

◆ HasBuiltInOprt()

bool mu::ParserBase::HasBuiltInOprt ( ) const

Query status of built in variables.

Returns
m_bBuiltInOp; true if built in operators are enabled.
Exceptions
nothrow

Definition at line 1404 of file muParserBase.cpp.

References m_bBuiltInOp.

Referenced by mu::ParserTokenReader::IsBuiltIn().

◆ Init()

void mu::ParserBase::Init ( void  )
protected

Initialize user defined functions.

Calls the virtual functions InitFun(), InitConst() and InitOprt().

Definition at line 365 of file muParserBase.cpp.

References InitCharSets(), InitConst(), InitFun(), and InitOprt().

◆ InitCharSets()

virtual void mu::ParserBase::InitCharSets ( )
protectedpure virtual

Implemented in mu::ParserInt, mu::ParserComplex, and mu::Parser.

Referenced by Init().

◆ InitConst()

virtual void mu::ParserBase::InitConst ( )
protectedpure virtual

Implemented in mu::ParserInt, mu::ParserComplex, and mu::Parser.

Referenced by Init().

◆ InitFun()

virtual void mu::ParserBase::InitFun ( )
protectedpure virtual

Implemented in mu::ParserInt, mu::ParserComplex, and mu::Parser.

Referenced by Init().

◆ InitOprt()

virtual void mu::ParserBase::InitOprt ( )
protectedpure virtual

Implemented in mu::ParserInt, mu::ParserComplex, and mu::Parser.

Referenced by Init().

◆ InitTokenReader()

void mu::ParserBase::InitTokenReader ( )
private

Initialize the token reader.

Create new token reader object and submit pointers to function, operator, constant and variable definitions.

Postcondition
m_pTokenReader.get()!=0
Exceptions
nothrow

Definition at line 178 of file muParserBase.cpp.

References m_pTokenReader.

Referenced by ParserBase().

◆ operator=()

ParserBase & mu::ParserBase::operator= ( const ParserBase a_Parser)

Assignement operator.

Implemented by calling Assign(a_Parser). Self assignement is suppressed.

Parameters
a_ParserObject to copy to this.
Returns
*this
Exceptions
nothrow

Definition at line 125 of file muParserBase.cpp.

References Assign().

◆ ParseCmdCode()

value_type mu::ParserBase::ParseCmdCode ( ) const
private

Parse the command code.

See also
ParseString(), ParseValue()

Command code contains precalculated stack positions of the values and the associated operators. The Stack is filled beginning from index one the value at index zero is not used at all.

Definition at line 885 of file muParserBase.cpp.

References mu::cmADD, mu::cmAND, mu::cmASSIGN, mu::cmDIV, mu::cmEND, mu::cmEQ, mu::cmFUNC, mu::cmFUNC_STR, mu::cmGE, mu::cmGT, mu::cmLE, mu::cmLT, mu::cmMUL, mu::cmNEQ, mu::cmOPRT_BIN, mu::cmOR, mu::cmPOW, mu::cmSUB, mu::cmVAL, mu::cmVAR, mu::cmXOR, mu::ecGENERIC, mu::ecINTERNAL_ERROR, Error(), mu::ParserByteCode::GetPtrSize(), mu::ParserByteCode::GetValSize(), i, int, m_pCmdCode, m_pTokenReader, m_vByteCode, m_vStringBuf, MUP_ASSERT, and wxT.

Referenced by ParseString().

◆ ParseString()

value_type mu::ParserBase::ParseString ( ) const
private

One of the two main parse functions.

Parse expression from input string. Perform syntax checking and create bytecode. After parsing the string and creating the bytecode the function pointer m_pParseFormula will be changed to the second parse routine the uses bytecode instead of string parsing.

See also
ParseCmdCode(), ParseValue()

Definition at line 1034 of file muParserBase.cpp.

References mu::ParserByteCode::AddVal(), mu::ParserByteCode::AddVar(), ApplyBinOprt(), ApplyFunc(), mu::ParserByteCode::AsciiDump(), assert, mu::cmADD, mu::cmAND, mu::cmARG_SEP, mu::cmASSIGN, mu::cmBC, mu::cmBO, mu::cmDIV, mu::cmEND, mu::cmEQ, mu::cmFUNC, mu::cmFUNC_STR, mu::cmGE, mu::cmGT, mu::cmLE, mu::cmLT, mu::cmMUL, mu::cmNEQ, mu::cmOPRT_BIN, mu::cmOPRT_INFIX, mu::cmOPRT_POSTFIX, mu::cmOR, mu::cmPOW, mu::cmSTRING, mu::cmSUB, mu::cmVAL, mu::cmVAR, mu::cmXOR, mu::ecEMPTY_EXPRESSION, mu::ecINTERNAL_ERROR, mu::ecSTR_RESULT, mu::ecUNEXPECTED_ARG, mu::ecUNEXPECTED_ARG_SEP, mu::ecUNEXPECTED_EOF, mu::ParserStack< TValueType >::empty(), Error(), mu::ParserByteCode::Finalize(), mu::ParserToken< TBase, TString >::GetAsString(), mu::ParserByteCode::GetBufSize(), mu::ParserToken< TBase, TString >::GetCode(), GetOprtPri(), mu::ParserByteCode::GetRawData(), mu::ParserToken< TBase, TString >::GetVal(), mu::ParserByteCode::GetValSize(), mu::ParserToken< TBase, TString >::GetVar(), m_bUseByteCode, m_pCmdCode, m_pParseFormula, m_pTokenReader, m_vByteCode, m_vStringBuf, ParseCmdCode(), ParseValue(), mu::ParserStack< TValueType >::pop(), mu::ParserStack< TValueType >::push(), ReInit(), mu::ParserToken< TBase, TString >::SetIdx(), mu::ParserStack< TValueType >::size(), mu::ParserStack< TValueType >::top(), mu::tpDBL, and val.

Referenced by GetUsedVar(), and ReInit().

◆ ParseValue()

value_type mu::ParserBase::ParseValue ( ) const
private

Return result for constant functions.

Seems pointless, but for parser functions that are made up of only a value, which occur in real world applications, this speeds up things by removing the parser overhead almost completely.

Definition at line 1020 of file muParserBase.cpp.

References m_pCmdCode.

Referenced by ParseString().

◆ ReInit()

void mu::ParserBase::ReInit ( ) const
private

Reset parser to string parsing mode and clear internal buffers.

Clear bytecode, reset the token reader.

Exceptions
nothrow

Definition at line 189 of file muParserBase.cpp.

References mu::ParserByteCode::clear(), m_pParseFormula, m_pTokenReader, m_vByteCode, m_vStringBuf, and ParseString().

Referenced by AddCallback(), Assign(), ClearConst(), ClearFormula(), ClearFun(), ClearInfixOprt(), ClearOprt(), ClearPostfixOprt(), ClearVar(), DefineConst(), DefineStrConst(), DefineVar(), EnableBuiltInOprt(), EnableByteCode(), EnableOptimizer(), ParseString(), RemoveVar(), and SetExpr().

◆ RemoveVar()

void mu::ParserBase::RemoveVar ( const string_type a_strVarName)

Remove a variable from internal storage.

Exceptions
nothrowRemoves a variable if it exists. If the Variable does not exist nothing will be done.

Definition at line 1276 of file muParserBase.cpp.

References m_VarDef, and ReInit().

Referenced by mu::Test::ParserTester::TestInterface().

◆ SetArgSep()

void mu::ParserBase::SetArgSep ( char_type  cArgSep)

Set argument separator.

Parameters
cArgSepthe argument separator character.

Definition at line 1421 of file muParserBase.cpp.

References m_pTokenReader.

◆ SetExpr()

void mu::ParserBase::SetExpr ( const string_type a_sExpr)

Set the formula.

Parameters
a_strFormulaFormula as string_type
Exceptions
ParserExceptionin case of syntax errors.

Triggers first time calculation thus the creation of the bytecode and scanning of used variables.

Definition at line 263 of file muParserBase.cpp.

References mu::ecLOCALE, Error(), locale, m_pTokenReader, MUP_USE_FACET, ReInit(), and wxT.

Referenced by mu::Test::ParserTester::EqnTest(), mu::Test::ParserTester::EqnTestInt(), mu::Test::ParserTester::TestInterface(), mu::Test::ParserTester::TestVarConst(), mu::Test::ParserTester::TestVolatile(), and mu::Test::ParserTester::ThrowTest().

◆ SetVarFactory()

void mu::ParserBase::SetVarFactory ( facfun_type  a_pFactory,
void *  pUserData = NULL 
)

Definition at line 204 of file muParserBase.cpp.

References m_pTokenReader.

◆ ValidInfixOprtChars()

const char_type * mu::ParserBase::ValidInfixOprtChars ( ) const

Virtual function that defines the characters allowed in infix operator definitions.

See also
ValidNameChars, ValidOprtChars

Definition at line 340 of file muParserBase.cpp.

References assert, and m_sInfixOprtChars.

Referenced by mu::ParserTokenReader::IsInfixOpTok().

◆ ValidNameChars()

const char_type * mu::ParserBase::ValidNameChars ( ) const

◆ ValidOprtChars()

const char_type * mu::ParserBase::ValidOprtChars ( ) const

Virtual function that defines the characters allowed in operator definitions.

See also
ValidNameChars, #ValidPrefixOprtChars

Definition at line 330 of file muParserBase.cpp.

References assert, and m_sOprtChars.

Referenced by DefineInfixOprt(), DefineOprt(), DefinePostfixOprt(), mu::ParserTokenReader::IsOprt(), and mu::ParserTokenReader::IsPostOpTok().

Friends And Related Function Documentation

◆ ParserTokenReader

friend class ParserTokenReader
friend

Definition at line 65 of file muParserBase.h.

Member Data Documentation

◆ c_DefaultOprt

const char_type * mu::ParserBase::c_DefaultOprt
staticprotected
Initial value:
=
{
MUP_T( "<=" ), MUP_T( ">=" ), MUP_T( "!=" ),
MUP_T( "==" ), MUP_T( "<" ), MUP_T( ">" ),
MUP_T( "+" ), MUP_T( "-" ), MUP_T( "*" ),
MUP_T( "/" ), MUP_T( "^" ), MUP_T( "and" ),
MUP_T( "or" ), MUP_T( "xor" ), MUP_T( "=" ),
MUP_T( "(" ), MUP_T( ")" ), 0
}
#define MUP_T
Definition: muParserDef.h:62

Identifiers for built in binary operators.

When defining custom binary operators with #AddOprt(...) make sure not to choose names conflicting with these definitions.

Definition at line 197 of file muParserBase.h.

Referenced by DefineOprt(), and GetOprtDef().

◆ m_bBuiltInOp

bool mu::ParserBase::m_bBuiltInOp
private

Flag that can be used for switching built in operators on and off.

Definition at line 259 of file muParserBase.h.

Referenced by Assign(), DefineOprt(), EnableBuiltInOprt(), and HasBuiltInOprt().

◆ m_bOptimize

bool mu::ParserBase::m_bOptimize
private

Flag that indicates if the optimizer is on or off.

Definition at line 257 of file muParserBase.h.

Referenced by ApplyBinOprt(), ApplyNumFunc(), Assign(), and EnableOptimizer().

◆ m_bUseByteCode

bool mu::ParserBase::m_bUseByteCode
private

Flag that indicates if bytecode parsing is on or off.

Definition at line 258 of file muParserBase.h.

Referenced by Assign(), EnableByteCode(), and ParseString().

◆ m_ConstDef

valmap_type mu::ParserBase::m_ConstDef
private

user constants.

Definition at line 253 of file muParserBase.h.

Referenced by Assign(), ClearConst(), DefineConst(), DefineVar(), GetConst(), and mu::ParserTokenReader::SetParent().

◆ m_FunDef

funmap_type mu::ParserBase::m_FunDef
private

Map of function names and pointers.

Definition at line 249 of file muParserBase.h.

Referenced by AddCallback(), Assign(), ClearFun(), DefineVar(), GetFunDef(), and mu::ParserTokenReader::SetParent().

◆ m_InfixOprtDef

funmap_type mu::ParserBase::m_InfixOprtDef
private

unary infix operator.

Definition at line 251 of file muParserBase.h.

Referenced by AddCallback(), Assign(), ClearInfixOprt(), DefineInfixOprt(), and mu::ParserTokenReader::SetParent().

◆ m_OprtDef

funmap_type mu::ParserBase::m_OprtDef
private

Binary operator callbacks.

Definition at line 252 of file muParserBase.h.

Referenced by AddCallback(), ClearOprt(), DefineOprt(), and mu::ParserTokenReader::SetParent().

◆ m_pCmdCode

const ParserByteCode::map_type* mu::ParserBase::m_pCmdCode
mutableprivate

Formula converted to bytecode, points to the data of the bytecode class.

Definition at line 242 of file muParserBase.h.

Referenced by ClearFormula(), ParseCmdCode(), ParseString(), and ParseValue().

◆ m_PostOprtDef

funmap_type mu::ParserBase::m_PostOprtDef
private

Postfix operator callbacks.

Definition at line 250 of file muParserBase.h.

Referenced by AddCallback(), Assign(), ClearPostfixOprt(), DefinePostfixOprt(), and mu::ParserTokenReader::SetParent().

◆ m_pParseFormula

ParseFunction mu::ParserBase::m_pParseFormula
mutableprivate

Pointer to the parser function.

Eval() calls the function whose address is stored there.

Definition at line 241 of file muParserBase.h.

Referenced by Eval(), GetUsedVar(), ParseString(), and ReInit().

◆ m_pTokenReader

std::unique_ptr<token_reader_type> mu::ParserBase::m_pTokenReader
private

◆ m_sInfixOprtChars

string_type mu::ParserBase::m_sInfixOprtChars
private

Charset for infix operator tokens.

Definition at line 263 of file muParserBase.h.

Referenced by Assign(), DefineInfixOprtChars(), and ValidInfixOprtChars().

◆ m_sNameChars

string_type mu::ParserBase::m_sNameChars
private

Charset for names.

Definition at line 261 of file muParserBase.h.

Referenced by Assign(), DefineNameChars(), and ValidNameChars().

◆ m_sOprtChars

string_type mu::ParserBase::m_sOprtChars
private

Charset for postfix/ binary operator tokens.

Definition at line 262 of file muParserBase.h.

Referenced by Assign(), DefineOprtChars(), and ValidOprtChars().

◆ m_StrVarDef

strmap_type mu::ParserBase::m_StrVarDef
private

user defined string constants

Definition at line 254 of file muParserBase.h.

Referenced by Assign(), ClearConst(), DefineStrConst(), and mu::ParserTokenReader::SetParent().

◆ m_VarDef

varmap_type mu::ParserBase::m_VarDef
private

user defind variables.

Definition at line 255 of file muParserBase.h.

Referenced by Assign(), ClearVar(), DefineVar(), GetVar(), RemoveVar(), and mu::ParserTokenReader::SetParent().

◆ m_vByteCode

ParserByteCode mu::ParserBase::m_vByteCode
mutableprivate

The Bytecode class.

Definition at line 243 of file muParserBase.h.

Referenced by ApplyBinOprt(), ApplyNumFunc(), ApplyStrFunc(), ClearFormula(), ParseCmdCode(), ParseString(), and ReInit().

◆ m_vStringBuf

stringbuf_type mu::ParserBase::m_vStringBuf
mutableprivate

String buffer, used for storing string function arguments.

Definition at line 244 of file muParserBase.h.

Referenced by Assign(), DefineStrConst(), mu::ParserTokenReader::IsString(), ParseCmdCode(), ParseString(), and ReInit().

◆ m_vStringVarBuf

stringbuf_type mu::ParserBase::m_vStringVarBuf
private

Definition at line 245 of file muParserBase.h.

Referenced by Assign(), DefineStrConst(), and mu::ParserTokenReader::IsStrVarTok().


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