OpcUaCanOpen
CANopen OPC-UA server
mu::Parser Class Reference

Mathematical expressions parser. More...

#include <muParser.h>

Inherits mu::ParserBase.

Public Member Functions

 Parser ()
 Constructor. More...
 
virtual void InitCharSets ()
 Define the character sets. More...
 
virtual void InitFun ()
 Initialize the default functions. More...
 
virtual void InitConst ()
 Initialize constants. More...
 
virtual void InitOprt ()
 Initialize operators. More...
 
virtual void OnDetectVar (string_type *pExpr, int &nStart, int &nEnd)
 
value_type Diff (value_type *a_Var, value_type a_fPos, value_type a_fEpsilon=0) const
 Numerically differentiate with regard to a variable. More...
 
- Public Member Functions inherited from mu::ParserBase
 ParserBase ()
 Constructor. More...
 
 ParserBase (const ParserBase &a_Parser)
 Copy constructor. More...
 
ParserBaseoperator= (const ParserBase &a_Parser)
 Assignment operator. More...
 
virtual ~ParserBase ()
 
value_type Eval () const
 Calculate the result. More...
 
value_typeEval (int &nStackSize) const
 Evaluate an expression containing comma separated subexpressions. More...
 
void Eval (value_type *results, int nBulkSize)
 
int GetNumResults () const
 Return the number of results on the calculation stack. More...
 
void SetExpr (const string_type &a_sExpr)
 Set the formula. More...
 
void SetVarFactory (facfun_type a_pFactory, void *pUserData=NULL)
 Set a function that can create variable pointer for unknown expression variables. More...
 
void SetDecSep (char_type cDecSep)
 Set the decimal separator. More...
 
void SetThousandsSep (char_type cThousandsSep=0)
 Sets the thousands operator. 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...
 
template<typename T >
void DefineFun (const string_type &a_strName, T a_pFun, bool a_bAllowOpt=true)
 Define a parser function without arguments. More...
 
void DefineOprt (const string_type &a_strName, fun_type2 a_pFun, unsigned a_iPri=0, EOprtAssociativity a_eAssociativity=oaLEFT, 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...
 
string_type GetVersion (EParserVersionInfo eInfo=pviFULL) const
 Returns the version of muparser. 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...
 

Static Protected Member Functions

static value_type Sin (value_type)
 
static value_type Cos (value_type)
 
static value_type Tan (value_type)
 
static value_type Tan2 (value_type, value_type)
 
static value_type ASin (value_type)
 
static value_type ACos (value_type)
 
static value_type ATan (value_type)
 
static value_type ATan2 (value_type, value_type)
 
static value_type Sinh (value_type)
 
static value_type Cosh (value_type)
 
static value_type Tanh (value_type)
 
static value_type ASinh (value_type)
 
static value_type ACosh (value_type)
 
static value_type ATanh (value_type)
 
static value_type Log2 (value_type)
 
static value_type Log10 (value_type)
 
static value_type Ln (value_type)
 
static value_type Exp (value_type)
 
static value_type Abs (value_type)
 
static value_type Sqrt (value_type)
 
static value_type Rint (value_type)
 
static value_type Sign (value_type)
 
static value_type UnaryMinus (value_type)
 Callback for the unary minus operator. More...
 
static value_type UnaryPlus (value_type)
 Callback for the unary minus operator. More...
 
static value_type Sum (const value_type *, int)
 Callback for adding multiple values. More...
 
static value_type Avg (const value_type *, int)
 Callback for averaging multiple values. More...
 
static value_type Min (const value_type *, int)
 Callback for determining the minimum value out of a vector. More...
 
static value_type Max (const value_type *, int)
 Callback for determining the maximum value out of a vector. More...
 
static int IsVal (const char_type *a_szExpr, int *a_iPos, value_type *a_fVal)
 Default value recognition callback. More...
 

Additional Inherited Members

- Public Types inherited from mu::ParserBase
typedef ParserError exception_type
 Type of the error class. More...
 
- Static Public Member Functions inherited from mu::ParserBase
static void EnableDebugDump (bool bDumpCmd, bool bDumpStack)
 Enable the dumping of bytecode and stack content on the console. More...
 
- Protected Member Functions inherited from mu::ParserBase
void Init ()
 Initialize user defined functions. More...
 
- Static Protected Attributes inherited from mu::ParserBase
static const char_typec_DefaultOprt []
 Identifiers for built in binary operators. More...
 
static std::locale s_locale = std::locale(std::locale::classic(), new change_dec_sep<char_type>('.'))
 The locale used by the parser. 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)beltoforion.de

Definition at line 51 of file muParser.h.

Constructor & Destructor Documentation

◆ Parser()

mu::Parser::Parser ( )

Constructor.

Call ParserBase class constructor and trigger Function, Operator and Constant initialization.

Definition at line 238 of file muParser.cpp.

Member Function Documentation

◆ Abs()

value_type mu::Parser::Abs ( value_type  v)
staticprotected

Definition at line 108 of file muParser.cpp.

◆ ACos()

value_type mu::Parser::ACos ( value_type  v)
staticprotected

Definition at line 59 of file muParser.cpp.

◆ ACosh()

value_type mu::Parser::ACosh ( value_type  v)
staticprotected

Definition at line 66 of file muParser.cpp.

◆ ASin()

value_type mu::Parser::ASin ( value_type  v)
staticprotected

Definition at line 58 of file muParser.cpp.

◆ ASinh()

value_type mu::Parser::ASinh ( value_type  v)
staticprotected

Definition at line 65 of file muParser.cpp.

◆ ATan()

value_type mu::Parser::ATan ( value_type  v)
staticprotected

Definition at line 60 of file muParser.cpp.

◆ ATan2()

value_type mu::Parser::ATan2 ( value_type  v1,
value_type  v2 
)
staticprotected

Definition at line 61 of file muParser.cpp.

◆ ATanh()

value_type mu::Parser::ATanh ( value_type  v)
staticprotected

Definition at line 67 of file muParser.cpp.

◆ Avg()

value_type mu::Parser::Avg ( const value_type 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 161 of file muParser.cpp.

◆ Cos()

value_type mu::Parser::Cos ( value_type  v)
staticprotected

Definition at line 56 of file muParser.cpp.

◆ Cosh()

value_type mu::Parser::Cosh ( value_type  v)
staticprotected

Definition at line 63 of file muParser.cpp.

◆ Diff()

value_type mu::Parser::Diff ( value_type a_Var,
value_type  a_fPos,
value_type  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 muparser forum:

http://sourceforge.net/forum/forum.php?thread_id=1994611&forum_id=462843

Definition at line 374 of file muParser.cpp.

◆ Exp()

value_type mu::Parser::Exp ( value_type  v)
staticprotected

Definition at line 107 of file muParser.cpp.

◆ InitCharSets()

void mu::Parser::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 mu::ParserBase.

Definition at line 256 of file muParser.cpp.

◆ InitConst()

void mu::Parser::InitConst ( )
virtual

Initialize constants.

By default the parser recognizes two constants. Pi ("pi") and the Eulerian number ("_e").

Implements mu::ParserBase.

Definition at line 319 of file muParser.cpp.

◆ InitFun()

void mu::Parser::InitFun ( )
virtual

Initialize the default functions.

Implements mu::ParserBase.

Definition at line 265 of file muParser.cpp.

◆ InitOprt()

void mu::Parser::InitOprt ( )
virtual

Initialize operators.

By default only the unary minus operator is added.

Implements mu::ParserBase.

Definition at line 330 of file muParser.cpp.

◆ IsVal()

int mu::Parser::IsVal ( const char_type a_szExpr,
int *  a_iPos,
value_type a_fVal 
)
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 214 of file muParser.cpp.

◆ Ln()

value_type mu::Parser::Ln ( value_type  v)
staticprotected

Definition at line 95 of file muParser.cpp.

◆ Log10()

value_type mu::Parser::Log10 ( value_type  v)
staticprotected

Definition at line 84 of file muParser.cpp.

◆ Log2()

value_type mu::Parser::Log2 ( value_type  v)
staticprotected

Definition at line 73 of file muParser.cpp.

◆ Max()

value_type mu::Parser::Max ( const value_type 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 195 of file muParser.cpp.

◆ Min()

value_type mu::Parser::Min ( const value_type 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 177 of file muParser.cpp.

◆ OnDetectVar()

void mu::Parser::OnDetectVar ( string_type pExpr,
int &  nStart,
int &  nEnd 
)
virtual

Reimplemented from mu::ParserBase.

Definition at line 337 of file muParser.cpp.

◆ Rint()

value_type mu::Parser::Rint ( value_type  v)
staticprotected

Definition at line 118 of file muParser.cpp.

◆ Sign()

value_type mu::Parser::Sign ( value_type  v)
staticprotected

Definition at line 119 of file muParser.cpp.

◆ Sin()

value_type mu::Parser::Sin ( value_type  v)
staticprotected

Definition at line 55 of file muParser.cpp.

◆ Sinh()

value_type mu::Parser::Sinh ( value_type  v)
staticprotected

Definition at line 62 of file muParser.cpp.

◆ Sqrt()

value_type mu::Parser::Sqrt ( value_type  v)
staticprotected

Definition at line 109 of file muParser.cpp.

◆ Sum()

value_type mu::Parser::Sum ( const value_type 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 146 of file muParser.cpp.

◆ Tan()

value_type mu::Parser::Tan ( value_type  v)
staticprotected

Definition at line 57 of file muParser.cpp.

◆ Tan2()

static value_type mu::Parser::Tan2 ( value_type  ,
value_type   
)
staticprotected

◆ Tanh()

value_type mu::Parser::Tanh ( value_type  v)
staticprotected

Definition at line 64 of file muParser.cpp.

◆ UnaryMinus()

value_type mu::Parser::UnaryMinus ( value_type  v)
staticprotected

Callback for the unary minus operator.

Parameters
vThe value to negate
Returns
-v

Definition at line 126 of file muParser.cpp.

◆ UnaryPlus()

value_type mu::Parser::UnaryPlus ( value_type  v)
staticprotected

Callback for the unary minus operator.

Parameters
vThe value to negate
Returns
-v

Definition at line 136 of file muParser.cpp.


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