Mathematical expressions parser. More...
#include <qmuparser.h>
| Public Member Functions | |
| QmuParser () | |
| Constructor.  More... | |
| virtual void | InitCharSets () Q_DECL_OVERRIDE | 
| Define the character sets.  More... | |
| virtual void | InitFun () Q_DECL_OVERRIDE | 
| Initialize the default functions.  More... | |
| virtual void | InitConst () Q_DECL_OVERRIDE | 
| Initialize constants.  More... | |
| virtual void | InitOprt () Q_DECL_OVERRIDE | 
| Initialize operators.  More... | |
| virtual void | OnDetectVar (const QString &pExpr, int &nStart, int &nEnd) Q_DECL_OVERRIDE | 
| qreal | Diff (qreal *a_Var, qreal a_fPos, qreal a_fEpsilon=0) const | 
| Numerically differentiate with regard to a variable.  More... | |
|  Public Member Functions inherited from qmu::QmuParserBase | |
| QmuParserBase () | |
| Constructor.  More... | |
| QmuParserBase (const QmuParserBase &a_Parser) | |
| Copy constructor.  More... | |
| QmuParserBase & | operator= (const QmuParserBase &a_Parser) | 
| Assignement operator.  More... | |
| virtual | ~QmuParserBase () | 
| qreal | Eval () const | 
| Calculate the result.  More... | |
| qreal * | Eval (int &nStackSize) const | 
| Evaluate an expression containing comma seperated subexpressions.  More... | |
| void | Eval (qreal *results, int nBulkSize) const | 
| int | GetNumResults () const | 
| Return the number of results on the calculation stack.  More... | |
| void | SetExpr (const QString &a_sExpr) | 
| Set the formula.  More... | |
| void | SetVarFactory (facfun_type a_pFactory, void *pUserData=nullptr) | 
| Set a function that can create variable pointer for unknown expression variables.  More... | |
| void | ResetLocale () | 
| Resets the locale.  More... | |
| void | EnableOptimizer (bool a_bIsOn=true) | 
| Enable or disable the formula optimization feature.  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) | 
| Add a value parsing function.  More... | |
| void | DefineOprt (const QString &a_sName, fun_type2 a_pFun, unsigned a_iPrec=0, EOprtAssociativity a_eAssociativity=oaLEFT, bool a_bAllowOpt=false) | 
| Define a binary operator.  More... | |
| void | DefineConst (const QString &a_sName, qreal a_fVal) | 
| Add a user defined constant.  More... | |
| void | DefineStrConst (const QString &a_strName, const QString &a_strVal) | 
| Define a new string constant.  More... | |
| void | DefineVar (const QString &a_sName, qreal *a_pVar) | 
| Add a user defined variable.  More... | |
| void | DefinePostfixOprt (const QString &a_sFun, fun_type1 a_pFun, bool a_bAllowOpt=true) | 
| Add a user defined operator.  More... | |
| void | DefineInfixOprt (const QString &a_sName, fun_type1 a_pFun, 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 QString &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 QString & | GetExpr () const | 
| Retrieve the formula.  More... | |
| const funmap_type & | GetFunDef () const | 
| Return prototypes of all parser functions.  More... | |
| QMap< int, QString > | GetTokens () const | 
| QMap< int, QString > | GetNumbers () const | 
| void | DefineNameChars (const QString &a_szCharset) | 
| Define the set of valid characters to be used in names of functions, variables, constants.  More... | |
| void | DefineOprtChars (const QString &a_szCharset) | 
| Define the set of valid characters to be used in names of binary operators and postfix operators.  More... | |
| void | DefineInfixOprtChars (const QString &a_szCharset) | 
| Define the set of valid characters to be used in names of infix operators.  More... | |
| const QString & | ValidNameChars () const | 
| Virtual function that defines the characters allowed in name identifiers.  More... | |
| const QString & | ValidOprtChars () const | 
| Virtual function that defines the characters allowed in operator definitions.  More... | |
| const QString & | ValidInfixOprtChars () const | 
| Virtual function that defines the characters allowed in infix operator definitions.  More... | |
| void | SetArgSep (char_type cArgSep) | 
| Set argument separator.  More... | |
| QChar | GetArgSep () const | 
| Get the argument separator character.  More... | |
| void Q_NORETURN | Error (EErrorCodes a_iErrc, int a_iPos=-1, const QString &a_sTok=QString()) const | 
| Create an error containing the parse error position.  More... | |
| template<typename T > | |
| void | DefineFun (const QString &a_strName, T a_pFun, bool a_bAllowOpt=true) | 
| Define a parser function without arguments.  More... | |
| void | setAllowSubexpressions (bool value) | 
| QLocale | getLocale () const | 
| void | setLocale (const QLocale &value) | 
| QChar | getDecimalPoint () const | 
| void | setDecimalPoint (const QChar &c) | 
| QChar | getThousandsSeparator () const | 
| void | setThousandsSeparator (const QChar &c) | 
| Static Protected Member Functions | |
| static int | IsVal (const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale, const QChar &decimal, const QChar &thousand) | 
| Default value recognition callback.  More... | |
| static qreal | Sinh (qreal) | 
| static qreal | Cosh (qreal) | 
| static qreal | Tanh (qreal) | 
| static qreal | ASinh (qreal) | 
| static qreal | ACosh (qreal) | 
| static qreal | ATanh (qreal) | 
| static qreal | DegreeToRadian (qreal) | 
| static qreal | RadianToDegree (qreal) | 
| static qreal | SinD (qreal) | 
| static qreal | CosD (qreal) | 
| static qreal | TanD (qreal) | 
| static qreal | ASinD (qreal) | 
| static qreal | ACosD (qreal) | 
| static qreal | ATanD (qreal) | 
| static qreal | Log2 (qreal) | 
| static qreal | Log10 (qreal) | 
| static qreal | Abs (qreal) | 
| static qreal | Rint (qreal) | 
| static qreal | Sign (qreal) | 
| static qreal | FMod (qreal, qreal) | 
| static qreal | UnaryMinus (qreal v) | 
| Callback for the unary minus operator.  More... | |
| static qreal | Sum (const qreal *, int) | 
| Callback for adding multiple values.  More... | |
| static qreal | Avg (const qreal *, int) | 
| Callback for averaging multiple values.  More... | |
| static qreal | Min (const qreal *, int) | 
| Callback for determining the minimum value out of a vector.  More... | |
| static qreal | Max (const qreal *, int) | 
| Callback for determining the maximum value out of a vector.  More... | |
| Additional Inherited Members | |
|  Static Public Member Functions inherited from qmu::QmuParserBase | |
| static void | EnableDebugDump (bool bDumpCmd, bool bDumpStack) | 
| Enable the dumping of bytecode amd stack content on the console.  More... | |
| static QString | GetVersion (EParserVersionInfo eInfo=pviFULL) | 
| Returns the version of muparser.  More... | |
| static const QStringList & | GetOprtDef () | 
| Get the default symbols used for the built in operators.  More... | |
|  Protected Member Functions inherited from qmu::QmuParserBase | |
| void | Init () | 
| Initialize user defined functions.  More... | |
|  Protected Attributes inherited from qmu::QmuParserBase | |
| QLocale | m_locale | 
| The locale used by the parser.  More... | |
| QChar | m_decimalPoint | 
| QChar | m_thousandsSeparator | 
|  Static Protected Attributes inherited from qmu::QmuParserBase | |
| static const QStringList | c_DefaultOprt | 
| Identifiers for built in binary operators.  More... | |
| static bool | g_DbgDumpCmdCode = false | 
| static bool | g_DbgDumpStack = false | 
Mathematical expressions parser.
Standard implementation of the mathematical expressions parser. Can be used as a reference implementation for subclassing the parser.
 (C) 2011 Ingo Berg
 muparser(at)gmx.de  
Definition at line 49 of file qmuparser.h.
| qmu::QmuParser::QmuParser | ( | ) | 
Constructor.
Call QmuParserBase class constructor and trigger Function, Operator and Constant initialization.
Definition at line 300 of file qmuparser.cpp.
References qmu::QmuParserBase::AddValIdent(), InitCharSets(), InitConst(), InitFun(), InitOprt(), and IsVal().
| 
 | staticprotected | 
Definition at line 162 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | staticprotected | 
Definition at line 114 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | staticprotected | 
Definition at line 78 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | staticprotected | 
Definition at line 102 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | staticprotected | 
Definition at line 66 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | staticprotected | 
Definition at line 126 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | staticprotected | 
Definition at line 90 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | staticprotected | 
Callback for averaging multiple values.
| [in] | a_afArg | Vector with the function arguments | 
| [in] | a_iArgc | The size of a_afArg | 
Definition at line 212 of file qmuparser.cpp.
References translate.
Referenced by InitFun().
| 
 | staticprotected | 
Definition at line 108 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | staticprotected | 
Definition at line 72 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | staticprotected | 
Definition at line 48 of file qmuparser.cpp.
Referenced by InitFun().
| qreal qmu::QmuParser::Diff | ( | qreal * | a_Var, | 
| qreal | a_fPos, | ||
| qreal | a_fEpsilon = 0 | ||
| ) | const | 
Numerically differentiate with regard to a variable.
| [in] | a_Var | Pointer to the differentiation variable. | 
| [in] | a_fPos | Position at which the differentiation should take place. | 
| [in] | a_fEpsilon | Epsilon used for the numerical differentiation. | 
Numerical differentiation uses a 5 point operator yielding a 4th order formula. The default value for epsilon is 0.00074 which is numeric_limits<double>::epsilon() ^ (1/5) as suggested in the muQmuParser forum:
http://sourceforge.net/forum/forum.php?thread_id=1994611&forum_id=462843
Definition at line 444 of file qmuparser.cpp.
References qmu::QmuParserBase::Eval().
| 
 | staticprotected | 
Definition at line 180 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | virtual | 
Define the character sets.
This function is used for initializing the default character sets that define the characters to be useable in function and variable names and operators.
Implements qmu::QmuParserBase.
Reimplemented in qmu::QmuFormulaBase.
Definition at line 318 of file qmuparser.cpp.
References qmu::QmuParserBase::DefineInfixOprtChars(), qmu::QmuParserBase::DefineNameChars(), and qmu::QmuParserBase::DefineOprtChars().
Referenced by QmuParser().
| 
 | virtual | 
Initialize constants.
By default the QmuParser recognizes two constants. Pi ("pi") and the eulerian number ("_e").
Implements qmu::QmuParserBase.
Definition at line 384 of file qmuparser.cpp.
References qmu::QmuParserBase::DefineConst().
Referenced by QmuParser().
| 
 | virtual | 
Initialize the default functions.
Implements qmu::QmuParserBase.
Definition at line 329 of file qmuparser.cpp.
References Abs(), ACosD(), ACosh(), ASinD(), ASinh(), ATanD(), ATanh(), Avg(), CosD(), Cosh(), qmu::QmuParserBase::DefineFun(), DegreeToRadian(), FMod(), Log10(), Log2(), Max(), Min(), RadianToDegree(), Rint(), Sign(), SinD(), Sinh(), Sum(), TanD(), and Tanh().
Referenced by QmuParser().
| 
 | virtual | 
Initialize operators.
By default only the unary minus operator is added.
Implements qmu::QmuParserBase.
Definition at line 396 of file qmuparser.cpp.
References qmu::QmuParserBase::DefineInfixOprt(), qmu::QmuParserBase::m_locale, and UnaryMinus().
Referenced by QmuParser().
| 
 | staticprotected | 
Default value recognition callback.
| [in] | a_szExpr | Pointer to the expression | 
| [in,out] | a_iPos | Pointer to an index storing the current position within the expression | 
| [out] | a_fVal | Pointer where the value should be stored in case one is found. | 
Definition at line 277 of file qmuparser.cpp.
References ReadVal().
Referenced by QmuParser().
| 
 | staticprotected | 
Definition at line 149 of file qmuparser.cpp.
References qmu::ecDOMAIN_ERROR.
Referenced by InitFun().
| 
 | staticprotected | 
Definition at line 136 of file qmuparser.cpp.
References qmu::ecDOMAIN_ERROR.
Referenced by InitFun().
| 
 | staticprotected | 
Callback for determining the maximum value out of a vector.
| [in] | a_afArg | Vector with the function arguments | 
| [in] | a_iArgc | The size of a_afArg | 
Definition at line 254 of file qmuparser.cpp.
References translate.
Referenced by InitFun().
| 
 | staticprotected | 
Callback for determining the minimum value out of a vector.
| [in] | a_afArg | Vector with the function arguments | 
| [in] | a_iArgc | The size of a_afArg | 
Definition at line 233 of file qmuparser.cpp.
References translate.
Referenced by InitFun().
| 
 | virtual | 
Reimplemented from qmu::QmuParserBase.
Definition at line 402 of file qmuparser.cpp.
| 
 | staticprotected | 
Definition at line 54 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | staticprotected | 
Definition at line 168 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | staticprotected | 
Definition at line 174 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | staticprotected | 
Definition at line 96 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | staticprotected | 
Definition at line 60 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | staticprotected | 
Callback for adding multiple values.
| [in] | a_afArg | Vector with the function arguments | 
| [in] | a_iArgc | The size of a_afArg | 
Definition at line 191 of file qmuparser.cpp.
References translate.
Referenced by InitFun().
| 
 | staticprotected | 
Definition at line 120 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | staticprotected | 
Definition at line 84 of file qmuparser.cpp.
Referenced by InitFun().
| 
 | inlinestaticprotected | 
Callback for the unary minus operator.
| v | The value to negate | 
Definition at line 104 of file qmuparser.h.
Referenced by InitOprt().