Seamly2D
Code documentation
qmu::QmuParser Class Reference

Mathematical expressions parser. More...

#include <qmuparser.h>

Inheritance diagram for qmu::QmuParser:
Collaboration diagram for qmu::QmuParser:

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...
 
QmuParserBaseoperator= (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_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 QString & GetExpr () const
 Retrieve the formula. More...
 
const funmap_typeGetFunDef () 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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ QmuParser()

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().

Member Function Documentation

◆ Abs()

qreal qmu::QmuParser::Abs ( qreal  v)
staticprotected

Definition at line 162 of file qmuparser.cpp.

Referenced by InitFun().

◆ ACosD()

qreal qmu::QmuParser::ACosD ( qreal  v)
staticprotected

Definition at line 114 of file qmuparser.cpp.

Referenced by InitFun().

◆ ACosh()

qreal qmu::QmuParser::ACosh ( qreal  v)
staticprotected

Definition at line 78 of file qmuparser.cpp.

Referenced by InitFun().

◆ ASinD()

qreal qmu::QmuParser::ASinD ( qreal  v)
staticprotected

Definition at line 102 of file qmuparser.cpp.

Referenced by InitFun().

◆ ASinh()

qreal qmu::QmuParser::ASinh ( qreal  v)
staticprotected

Definition at line 66 of file qmuparser.cpp.

Referenced by InitFun().

◆ ATanD()

qreal qmu::QmuParser::ATanD ( qreal  v)
staticprotected

Definition at line 126 of file qmuparser.cpp.

Referenced by InitFun().

◆ ATanh()

qreal qmu::QmuParser::ATanh ( qreal  v)
staticprotected

Definition at line 90 of file qmuparser.cpp.

Referenced by InitFun().

◆ Avg()

qreal qmu::QmuParser::Avg ( const qreal *  a_afArg,
int  a_iArgc 
)
staticprotected

Callback for averaging multiple values.

Parameters
[in]a_afArgVector with the function arguments
[in]a_iArgcThe size of a_afArg

Definition at line 212 of file qmuparser.cpp.

References translate.

Referenced by InitFun().

◆ CosD()

qreal qmu::QmuParser::CosD ( qreal  v)
staticprotected

Definition at line 108 of file qmuparser.cpp.

Referenced by InitFun().

◆ Cosh()

qreal qmu::QmuParser::Cosh ( qreal  v)
staticprotected

Definition at line 72 of file qmuparser.cpp.

Referenced by InitFun().

◆ DegreeToRadian()

qreal qmu::QmuParser::DegreeToRadian ( qreal  deg)
staticprotected

Definition at line 48 of file qmuparser.cpp.

Referenced by InitFun().

◆ Diff()

qreal qmu::QmuParser::Diff ( qreal *  a_Var,
qreal  a_fPos,
qreal  a_fEpsilon = 0 
) const

Numerically differentiate with regard to a variable.

Parameters
[in]a_VarPointer to the differentiation variable.
[in]a_fPosPosition at which the differentiation should take place.
[in]a_fEpsilonEpsilon 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().

◆ FMod()

qreal qmu::QmuParser::FMod ( qreal  number,
qreal  denom 
)
staticprotected

Definition at line 180 of file qmuparser.cpp.

Referenced by InitFun().

◆ InitCharSets()

void qmu::QmuParser::InitCharSets ( )
virtual

Define the character sets.

See also
DefineNameChars, DefineOprtChars, DefineInfixOprtChars

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().

◆ InitConst()

void qmu::QmuParser::InitConst ( )
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().

◆ InitFun()

void qmu::QmuParser::InitFun ( )
virtual

◆ InitOprt()

void qmu::QmuParser::InitOprt ( )
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().

◆ IsVal()

int qmu::QmuParser::IsVal ( const QString &  a_szExpr,
int *  a_iPos,
qreal *  a_fVal,
const QLocale &  locale,
const QChar &  decimal,
const QChar &  thousand 
)
staticprotected

Default value recognition callback.

Parameters
[in]a_szExprPointer to the expression
[in,out]a_iPosPointer to an index storing the current position within the expression
[out]a_fValPointer where the value should be stored in case one is found.
Returns
1 if a value was found 0 otherwise.

Definition at line 277 of file qmuparser.cpp.

References ReadVal().

Referenced by QmuParser().

◆ Log10()

qreal qmu::QmuParser::Log10 ( qreal  v)
staticprotected

Definition at line 149 of file qmuparser.cpp.

References qmu::ecDOMAIN_ERROR.

Referenced by InitFun().

◆ Log2()

qreal qmu::QmuParser::Log2 ( qreal  v)
staticprotected

Definition at line 136 of file qmuparser.cpp.

References qmu::ecDOMAIN_ERROR.

Referenced by InitFun().

◆ Max()

qreal qmu::QmuParser::Max ( const qreal *  a_afArg,
int  a_iArgc 
)
staticprotected

Callback for determining the maximum value out of a vector.

Parameters
[in]a_afArgVector with the function arguments
[in]a_iArgcThe size of a_afArg

Definition at line 254 of file qmuparser.cpp.

References translate.

Referenced by InitFun().

◆ Min()

qreal qmu::QmuParser::Min ( const qreal *  a_afArg,
int  a_iArgc 
)
staticprotected

Callback for determining the minimum value out of a vector.

Parameters
[in]a_afArgVector with the function arguments
[in]a_iArgcThe size of a_afArg

Definition at line 233 of file qmuparser.cpp.

References translate.

Referenced by InitFun().

◆ OnDetectVar()

void qmu::QmuParser::OnDetectVar ( const QString &  pExpr,
int &  nStart,
int &  nEnd 
)
virtual

Reimplemented from qmu::QmuParserBase.

Definition at line 402 of file qmuparser.cpp.

◆ RadianToDegree()

qreal qmu::QmuParser::RadianToDegree ( qreal  rad)
staticprotected

Definition at line 54 of file qmuparser.cpp.

Referenced by InitFun().

◆ Rint()

qreal qmu::QmuParser::Rint ( qreal  v)
staticprotected

Definition at line 168 of file qmuparser.cpp.

Referenced by InitFun().

◆ Sign()

qreal qmu::QmuParser::Sign ( qreal  v)
staticprotected

Definition at line 174 of file qmuparser.cpp.

Referenced by InitFun().

◆ SinD()

qreal qmu::QmuParser::SinD ( qreal  v)
staticprotected

Definition at line 96 of file qmuparser.cpp.

Referenced by InitFun().

◆ Sinh()

qreal qmu::QmuParser::Sinh ( qreal  v)
staticprotected

Definition at line 60 of file qmuparser.cpp.

Referenced by InitFun().

◆ Sum()

qreal qmu::QmuParser::Sum ( const qreal *  a_afArg,
int  a_iArgc 
)
staticprotected

Callback for adding multiple values.

Parameters
[in]a_afArgVector with the function arguments
[in]a_iArgcThe size of a_afArg

Definition at line 191 of file qmuparser.cpp.

References translate.

Referenced by InitFun().

◆ TanD()

qreal qmu::QmuParser::TanD ( qreal  v)
staticprotected

Definition at line 120 of file qmuparser.cpp.

Referenced by InitFun().

◆ Tanh()

qreal qmu::QmuParser::Tanh ( qreal  v)
staticprotected

Definition at line 84 of file qmuparser.cpp.

Referenced by InitFun().

◆ UnaryMinus()

qreal qmu::QmuParser::UnaryMinus ( qreal  v)
inlinestaticprotected

Callback for the unary minus operator.

Parameters
vThe value to negate
Returns
-v

Definition at line 104 of file qmuparser.h.

Referenced by InitOprt().


The documentation for this class was generated from the following files: