NCBI C++ ToolKit
|
Search Toolkit Book for mu::ParserBase
Mathematical expressions parser (base parser engine). More...
#include <gui/utils/muparser/muParserBase.h>
Public Types | |
typedef ParserError | exception_type |
Type of the error class. More... | |
Public Member Functions | |
ParserBase () | |
Constructor. More... | |
ParserBase (const ParserBase &a_Parser) | |
ParserBase & | operator= (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_type & | GetUsedVar () const |
Return a map containing the used variables only. More... | |
const varmap_type & | GetVar () const |
Return a map containing the used variables only. More... | |
const valmap_type & | GetConst () const |
Return a map containing all parser constants. More... | |
const string_type & | GetExpr () const |
Retrieve the formula. More... | |
const funmap_type & | GetFunDef () 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_type * | ValidNameChars () const |
Virtual function that defines the characters allowed in name identifiers. More... | |
const char_type * | ValidOprtChars () const |
Virtual function that defines the characters allowed in operator definitions. More... | |
const char_type * | ValidInfixOprtChars () 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_type * | c_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_type > | stringbuf_type |
Type for a vector of strings. More... | |
typedef ParserTokenReader | token_reader_type |
Typedef for the token reader. More... | |
typedef ParserToken< value_type, string_type > | token_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_type * | m_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_type > | m_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 |
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.
Definition at line 63 of file muParserBase.h.
Type of the error class.
Included for backwards compatibility.
Definition at line 92 of file muParserBase.h.
|
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.
|
private |
Type for a vector of strings.
Definition at line 78 of file muParserBase.h.
|
private |
Typedef for the token reader.
Definition at line 81 of file muParserBase.h.
|
private |
Type used for parser tokens.
Definition at line 84 of file muParserBase.h.
mu::ParserBase::ParserBase | ( | ) |
Constructor.
a_szFormula | the formula to interpret. |
ParserException | if a_szFormula is null. |
Definition at line 68 of file muParserBase.cpp.
References InitTokenReader().
mu::ParserBase::ParserBase | ( | const ParserBase & | a_Parser | ) |
Definition at line 92 of file muParserBase.cpp.
References Assign(), and m_pTokenReader.
|
virtual |
Definition at line 114 of file muParserBase.cpp.
|
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().
void mu::ParserBase::AddValIdent | ( | identfun_type | a_pCallback | ) |
Definition at line 198 of file muParserBase.cpp.
References m_pTokenReader.
Referenced by mu::Parser::Parser(), mu::ParserComplex::ParserComplex(), and mu::ParserInt::ParserInt().
|
private |
Definition at line 786 of file muParserBase.cpp.
References mu::ParserByteCode::AddAssignOp(), mu::ParserByteCode::AddOp(), mu::ParserByteCode::AddVal(), ApplyFunc(), assert, mu::cmADD, mu::cmAND, mu::cmASSIGN, mu::cmDIV, mu::cmEQ, mu::cmGE, mu::cmGT, mu::cmLE, mu::cmLT, mu::cmMUL, mu::cmNEQ, mu::cmOPRT_BIN, mu::cmOR, mu::cmPOW, mu::cmSUB, mu::cmVAR, mu::cmXOR, mu::ecINTERNAL_ERROR, mu::ecOPRT_TYPE_CONFLICT, mu::ecUNEXPECTED_OPERATOR, Error(), mu::ParserToken< value_type, string_type >::flVOLATILE, mu::ParserToken< TBase, TString >::GetType(), mu::ParserToken< TBase, TString >::GetVal(), mu::ParserToken< TBase, TString >::IsFlagSet(), m_bOptimize, m_pTokenReader, m_vByteCode, MUP_ASSERT, mu::ParserStack< TValueType >::pop(), mu::ParserStack< TValueType >::push(), mu::ParserByteCode::RemoveValEntries(), mu::ParserStack< TValueType >::size(), mu::ParserStack< TValueType >::top(), mu::tpSTR, and wxT.
Referenced by ParseString().
|
private |
Apply a function token.
iArgCount | Number of Arguments actually gathered used only for multiarg functions. |
exception_type | if 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().
|
private |
Definition at line 574 of file muParserBase.cpp.
References mu::ParserToken< TBase, TString >::AddFlags(), mu::ParserByteCode::AddFun(), mu::ParserByteCode::AddVal(), assert, mu::ecINTERNAL_ERROR, mu::ecTOO_FEW_PARAMS, Error(), mu::ParserToken< value_type, string_type >::flVOLATILE, mu::ParserToken< TBase, TString >::GetArgCount(), mu::ParserToken< TBase, TString >::GetAsString(), mu::ParserToken< TBase, TString >::GetFuncAddr(), mu::ParserToken< TBase, TString >::GetVal(), i, mu::ParserToken< TBase, TString >::IsFlagSet(), m_bOptimize, m_pTokenReader, m_vByteCode, mu::ParserByteCode::RemoveValEntries(), and mu::ParserToken< TBase, TString >::SetVal().
Referenced by ApplyFunc().
|
private |
Execute a function that takes a single string argument.
a_FunTok | Function token. |
exception_type | If the function token is not a string function |
Definition at line 662 of file muParserBase.cpp.
References mu::ParserToken< TBase, TString >::AddFlags(), mu::ParserByteCode::AddStrFun(), assert, mu::cmSTRING, mu::ecINTERNAL_ERROR, mu::ecSTRING_EXPECTED, mu::ecVAL_EXPECTED, Error(), mu::ParserToken< value_type, string_type >::flVOLATILE, mu::ParserToken< TBase, TString >::GetArgCount(), mu::ParserToken< TBase, TString >::GetAsString(), mu::ParserToken< TBase, TString >::GetFuncAddr(), i, mu::ParserToken< TBase, TString >::IsFlagSet(), m_pTokenReader, m_vByteCode, and mu::ParserToken< TBase, TString >::SetVal().
Referenced by ApplyFunc().
|
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.
a_Parser | the 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().
|
private |
Check if a name contains invalid characters.
ParserException | if 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().
void mu::ParserBase::ClearConst | ( | ) |
Clear all user defined constants.
Both numeric and string constants will be removed from the internal storage.
nothrow |
Definition at line 1319 of file muParserBase.cpp.
References m_ConstDef, m_StrVarDef, and ReInit().
Referenced by mu::Test::ParserTester::TestNames().
|
private |
Clear the formula.
nothrow | Clear 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.
void mu::ParserBase::ClearFun | ( | ) |
Clear all functions.
nothrow |
Definition at line 1306 of file muParserBase.cpp.
void mu::ParserBase::ClearInfixOprt | ( | ) |
Clear the user defined Prefix operators.
nothrow |
Definition at line 1353 of file muParserBase.cpp.
References m_InfixOprtDef, and ReInit().
void mu::ParserBase::ClearOprt | ( | ) |
Clear all user defined binary operators.
nothrow |
Definition at line 1342 of file muParserBase.cpp.
void mu::ParserBase::ClearPostfixOprt | ( | ) |
Clear all user defined postfix operators.
nothrow |
Definition at line 1331 of file muParserBase.cpp.
References m_PostOprtDef, and ReInit().
void mu::ParserBase::ClearVar | ( | ) |
Clear all user defined variables.
nothrow | Resets the parser to string parsing mode by calling ReInit. |
Definition at line 1264 of file muParserBase.cpp.
void mu::ParserBase::DefineConst | ( | const string_type & | a_sName, |
value_type | a_fVal | ||
) |
Add a user defined constant.
[in] | a_sName | The name of the constant. |
[in] | a_fVal | the value of the constant. |
ParserException | in 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().
|
inline |
Definition at line 138 of file muParserBase.h.
Referenced by mu::Test::ParserTester::EqnTest(), mu::Parser::InitFun(), mu::ParserComplex::InitFun(), mu::ParserInt::InitFun(), mu::Test::ParserTester::TestVolatile(), and mu::Test::ParserTester::ThrowTest().
|
inline |
Definition at line 139 of file muParserBase.h.
|
inline |
Definition at line 140 of file muParserBase.h.
|
inline |
Definition at line 141 of file muParserBase.h.
|
inline |
Definition at line 142 of file muParserBase.h.
|
inline |
Definition at line 143 of file muParserBase.h.
|
inline |
Definition at line 144 of file muParserBase.h.
|
inline |
Definition at line 145 of file muParserBase.h.
|
inline |
Definition at line 146 of file muParserBase.h.
|
inline |
Definition at line 147 of file muParserBase.h.
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.
[in] | a_sName | operator Identifier |
[in] | a_pFun | Operator callback function |
[in] | a_iPrec | Operator Precedence (default=prSIGN) |
[in] | a_bAllowOpt | True if operator is volatile (default=false) |
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().
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().
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().
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.
[in] | a_pFun | Pointer to the callback function. |
[in] | a_iPrec | Precedence of the operator. |
[in] | a_bAllowOpt | If 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().
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().
void mu::ParserBase::DefinePostfixOprt | ( | const string_type & | a_sName, |
fun_type1 | a_pFun, | ||
bool | a_bAllowOpt = true |
||
) |
Add a user defined operator.
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().
void mu::ParserBase::DefineStrConst | ( | const string_type & | a_strName, |
const string_type & | a_strVal | ||
) |
Define a new string constant.
[in] | a_strName | The name of the constant. |
[in] | a_strVal | the 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().
void mu::ParserBase::DefineVar | ( | const string_type & | a_sName, |
value_type * | a_pVar | ||
) |
Add a user defined variable.
[in] | a_sName | the variable name |
[in] | a_pVar | A pointer to the variable vaule. |
ParserException | in 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().
Enable or disable the built in binary operators.
nothrow |
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().
Enable or disable parsing from Bytecode.
Definition at line 1376 of file muParserBase.cpp.
References m_bUseByteCode, and ReInit().
Enable or disable the formula optimization feature.
nothrow |
Definition at line 1364 of file muParserBase.cpp.
References m_bOptimize, and ReInit().
Referenced by mu::Test::ParserTester::EqnTest().
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.
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. |
ParserException | always 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().
|
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.
ParseException | if 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().
char_type mu::ParserBase::GetArgSep | ( | ) | const |
Get the argument separator character.
Definition at line 1412 of file muParserBase.cpp.
References m_pTokenReader.
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.
const string_type & mu::ParserBase::GetExpr | ( | ) | const |
const funmap_type & mu::ParserBase::GetFunDef | ( | ) | const |
Return prototypes of all parser functions.
nothrow | The 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.
Get the default symbols used for the built in operators.
Definition at line 284 of file muParserBase.cpp.
References c_DefaultOprt.
Referenced by mu::ParserTokenReader::IsBuiltIn().
|
private |
Get operator priority.
ParserException | if a_Oprt is no operator code |
Definition at line 479 of file muParserBase.cpp.
References mu::cmADD, mu::cmAND, mu::cmARG_SEP, mu::cmASSIGN, mu::cmBC, mu::cmBO, mu::cmDIV, mu::cmEND, mu::cmEQ, mu::cmGE, mu::cmGT, mu::cmLE, mu::cmLT, mu::cmMUL, mu::cmNEQ, mu::cmOPRT_BIN, mu::cmOPRT_INFIX, mu::cmOR, mu::cmPOW, mu::cmSUB, mu::cmXOR, mu::ecINTERNAL_ERROR, Error(), mu::ParserToken< TBase, TString >::GetCode(), mu::ParserToken< TBase, TString >::GetPri(), mu::prADD_SUB, mu::prCMP, mu::prLOGIC, mu::prMUL_DIV, and mu::prPOW.
Referenced by ParseString().
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().
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.
bool mu::ParserBase::HasBuiltInOprt | ( | ) | const |
Query status of built in variables.
nothrow |
Definition at line 1404 of file muParserBase.cpp.
References m_bBuiltInOp.
Referenced by mu::ParserTokenReader::IsBuiltIn().
|
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().
|
protectedpure virtual |
Implemented in mu::ParserInt, mu::ParserComplex, and mu::Parser.
Referenced by Init().
|
protectedpure virtual |
Implemented in mu::ParserInt, mu::ParserComplex, and mu::Parser.
Referenced by Init().
|
protectedpure virtual |
Implemented in mu::ParserInt, mu::ParserComplex, and mu::Parser.
Referenced by Init().
|
protectedpure virtual |
Implemented in mu::ParserInt, mu::ParserComplex, and mu::Parser.
Referenced by Init().
|
private |
Initialize the token reader.
Create new token reader object and submit pointers to function, operator, constant and variable definitions.
nothrow |
Definition at line 178 of file muParserBase.cpp.
References m_pTokenReader.
Referenced by ParserBase().
ParserBase & mu::ParserBase::operator= | ( | const ParserBase & | a_Parser | ) |
Assignement operator.
Implemented by calling Assign(a_Parser). Self assignement is suppressed.
a_Parser | Object to copy to this. |
nothrow |
Definition at line 125 of file muParserBase.cpp.
References Assign().
|
private |
Parse the command code.
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().
|
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.
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().
|
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().
|
private |
Reset parser to string parsing mode and clear internal buffers.
Clear bytecode, reset the token reader.
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().
void mu::ParserBase::RemoveVar | ( | const string_type & | a_strVarName | ) |
Remove a variable from internal storage.
nothrow | Removes 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().
void mu::ParserBase::SetArgSep | ( | char_type | cArgSep | ) |
Set argument separator.
cArgSep | the argument separator character. |
Definition at line 1421 of file muParserBase.cpp.
References m_pTokenReader.
void mu::ParserBase::SetExpr | ( | const string_type & | a_sExpr | ) |
Set the formula.
a_strFormula | Formula as string_type |
ParserException | in 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().
void mu::ParserBase::SetVarFactory | ( | facfun_type | a_pFactory, |
void * | pUserData = NULL |
||
) |
Definition at line 204 of file muParserBase.cpp.
References m_pTokenReader.
Virtual function that defines the characters allowed in infix operator definitions.
Definition at line 340 of file muParserBase.cpp.
References assert, and m_sInfixOprtChars.
Referenced by mu::ParserTokenReader::IsInfixOpTok().
Virtual function that defines the characters allowed in name identifiers.
Definition at line 320 of file muParserBase.cpp.
References assert, and m_sNameChars.
Referenced by DefineConst(), DefineStrConst(), DefineVar(), mu::ParserTokenReader::IsFunTok(), mu::ParserTokenReader::IsStrVarTok(), mu::ParserTokenReader::IsUndefVarTok(), mu::ParserTokenReader::IsValTok(), mu::ParserTokenReader::IsVarTok(), and mu::ParserTokenReader::ReadNextToken().
Virtual function that defines the characters allowed in operator definitions.
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().
|
friend |
Definition at line 65 of file muParserBase.h.
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().
|
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().
|
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().
|
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().
|
private |
user constants.
Definition at line 253 of file muParserBase.h.
Referenced by Assign(), ClearConst(), DefineConst(), DefineVar(), GetConst(), and mu::ParserTokenReader::SetParent().
|
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().
|
private |
unary infix operator.
Definition at line 251 of file muParserBase.h.
Referenced by AddCallback(), Assign(), ClearInfixOprt(), DefineInfixOprt(), and mu::ParserTokenReader::SetParent().
|
private |
Binary operator callbacks.
Definition at line 252 of file muParserBase.h.
Referenced by AddCallback(), ClearOprt(), DefineOprt(), and mu::ParserTokenReader::SetParent().
|
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().
|
private |
Postfix operator callbacks.
Definition at line 250 of file muParserBase.h.
Referenced by AddCallback(), Assign(), ClearPostfixOprt(), DefinePostfixOprt(), and mu::ParserTokenReader::SetParent().
|
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().
|
private |
Managed pointer to the token reader object.
Definition at line 247 of file muParserBase.h.
Referenced by AddValIdent(), ApplyBinOprt(), ApplyFunc(), ApplyNumFunc(), ApplyStrFunc(), Assign(), ClearFormula(), Error(), GetArgSep(), GetExpr(), GetUsedVar(), InitTokenReader(), ParseCmdCode(), ParserBase(), ParseString(), ReInit(), SetArgSep(), SetExpr(), and SetVarFactory().
|
private |
Charset for infix operator tokens.
Definition at line 263 of file muParserBase.h.
Referenced by Assign(), DefineInfixOprtChars(), and ValidInfixOprtChars().
|
private |
Charset for names.
Definition at line 261 of file muParserBase.h.
Referenced by Assign(), DefineNameChars(), and ValidNameChars().
|
private |
Charset for postfix/ binary operator tokens.
Definition at line 262 of file muParserBase.h.
Referenced by Assign(), DefineOprtChars(), and ValidOprtChars().
|
private |
user defined string constants
Definition at line 254 of file muParserBase.h.
Referenced by Assign(), ClearConst(), DefineStrConst(), and mu::ParserTokenReader::SetParent().
|
private |
user defind variables.
Definition at line 255 of file muParserBase.h.
Referenced by Assign(), ClearVar(), DefineVar(), GetVar(), RemoveVar(), and mu::ParserTokenReader::SetParent().
|
mutableprivate |
The Bytecode class.
Definition at line 243 of file muParserBase.h.
Referenced by ApplyBinOprt(), ApplyNumFunc(), ApplyStrFunc(), ClearFormula(), ParseCmdCode(), ParseString(), and ReInit().
|
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().
|
private |
Definition at line 245 of file muParserBase.h.
Referenced by Assign(), DefineStrConst(), and mu::ParserTokenReader::IsStrVarTok().