OpcUaCanOpen
CANopen OPC-UA server
|
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... | |
![]() | |
ParserBase () | |
Constructor. More... | |
ParserBase (const ParserBase &a_Parser) | |
Copy constructor. More... | |
ParserBase & | operator= (const ParserBase &a_Parser) |
Assignment operator. More... | |
virtual | ~ParserBase () |
value_type | Eval () const |
Calculate the result. More... | |
value_type * | Eval (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_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... | |
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_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... | |
Additional Inherited Members | |
![]() | |
typedef ParserError | exception_type |
Type of the error class. More... | |
![]() | |
static void | EnableDebugDump (bool bDumpCmd, bool bDumpStack) |
Enable the dumping of bytecode and stack content on the console. More... | |
![]() | |
void | Init () |
Initialize user defined functions. More... | |
![]() | |
static const char_type * | c_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 |
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.
mu::Parser::Parser | ( | ) |
Constructor.
Call ParserBase class constructor and trigger Function, Operator and Constant initialization.
Definition at line 238 of file muParser.cpp.
|
staticprotected |
Definition at line 108 of file muParser.cpp.
|
staticprotected |
Definition at line 59 of file muParser.cpp.
|
staticprotected |
Definition at line 66 of file muParser.cpp.
|
staticprotected |
Definition at line 58 of file muParser.cpp.
|
staticprotected |
Definition at line 65 of file muParser.cpp.
|
staticprotected |
Definition at line 60 of file muParser.cpp.
|
staticprotected |
Definition at line 61 of file muParser.cpp.
|
staticprotected |
Definition at line 67 of file muParser.cpp.
|
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 161 of file muParser.cpp.
|
staticprotected |
Definition at line 56 of file muParser.cpp.
|
staticprotected |
Definition at line 63 of file muParser.cpp.
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.
[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 muparser forum:
http://sourceforge.net/forum/forum.php?thread_id=1994611&forum_id=462843
Definition at line 374 of file muParser.cpp.
|
staticprotected |
Definition at line 107 of file muParser.cpp.
|
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 mu::ParserBase.
Definition at line 256 of file muParser.cpp.
|
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.
|
virtual |
Initialize the default functions.
Implements mu::ParserBase.
Definition at line 265 of file muParser.cpp.
|
virtual |
Initialize operators.
By default only the unary minus operator is added.
Implements mu::ParserBase.
Definition at line 330 of file muParser.cpp.
|
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 214 of file muParser.cpp.
|
staticprotected |
Definition at line 95 of file muParser.cpp.
|
staticprotected |
Definition at line 84 of file muParser.cpp.
|
staticprotected |
Definition at line 73 of file muParser.cpp.
|
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 195 of file muParser.cpp.
|
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 177 of file muParser.cpp.
|
virtual |
Reimplemented from mu::ParserBase.
Definition at line 337 of file muParser.cpp.
|
staticprotected |
Definition at line 118 of file muParser.cpp.
|
staticprotected |
Definition at line 119 of file muParser.cpp.
|
staticprotected |
Definition at line 55 of file muParser.cpp.
|
staticprotected |
Definition at line 62 of file muParser.cpp.
|
staticprotected |
Definition at line 109 of file muParser.cpp.
|
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 146 of file muParser.cpp.
|
staticprotected |
Definition at line 57 of file muParser.cpp.
|
staticprotected |
|
staticprotected |
Definition at line 64 of file muParser.cpp.
|
staticprotected |
Callback for the unary minus operator.
v | The value to negate |
Definition at line 126 of file muParser.cpp.
|
staticprotected |
Callback for the unary minus operator.
v | The value to negate |
Definition at line 136 of file muParser.cpp.