OpcUaCanOpen
CANopen OPC-UA server
mu::ParserBase Class Referenceabstract

Mathematical expressions parser (base parser engine). More...

#include <muParserBase.h>

Inherited by mu::Parser, and mu::ParserInt.

Classes

class  change_dec_sep
 A facet class used to change decimal and thousands separator. More...
 

Public Types

typedef ParserError exception_type
 Type of the error class. More...
 

Public Member Functions

 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 Public Member Functions

static void EnableDebugDump (bool bDumpCmd, bool bDumpStack)
 Enable the dumping of bytecode and stack content on the console. 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
 
virtual void OnDetectVar (string_type *pExpr, int &nStart, int &nEnd)
 

Static Protected Attributes

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
 

Private Types

typedef value_type(ParserBase::* ParseFunction) () const
 Typedef for the parse functions. More...
 
typedef std::vector< value_typevalbuf_type
 Type used for storing an array of values. More...
 
typedef std::vector< string_typestringbuf_type
 Type for a vector of strings. More...
 
typedef ParserTokenReader token_reader_type
 Typedef for the token reader. More...
 
typedef ParserToken< value_type, string_typetoken_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 ApplyRemainingOprt (ParserStack< token_type > &a_stOpt, ParserStack< token_type > &a_stVal) const
 Apply a binary operator. More...
 
void ApplyBinOprt (ParserStack< token_type > &a_stOpt, ParserStack< token_type > &a_stVal) const
 Performs the necessary steps to write code for the execution of binary operators into the bytecode. More...
 
void ApplyIfElse (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 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 GetOprtPrecedence (const token_type &a_Tok) const
 Get operator priority. More...
 
EOprtAssociativity GetOprtAssociativity (const token_type &a_Tok) const
 Get operator priority. More...
 
void CreateRPN () const
 
value_type ParseString () const
 One of the two main parse functions. More...
 
value_type ParseCmdCode () const
 Parse the command code. More...
 
value_type ParseCmdCodeBulk (int nOffset, int nThreadID) const
 Evaluate the RPN. More...
 
void CheckName (const string_type &a_strName, const string_type &a_CharSet) const
 Check if a name contains invalid characters. More...
 
void CheckOprt (const string_type &a_sName, const ParserCallback &a_Callback, const string_type &a_szCharSet) const
 Check if a name contains invalid characters. More...
 
void StackDump (const ParserStack< token_type > &a_stVal, const ParserStack< token_type > &a_stOprt) const
 Dump stack content. More...
 

Private Attributes

ParseFunction m_pParseFormula
 Pointer to the parser function. More...
 
ParserByteCode m_vRPN
 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_typem_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_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...
 
int m_nIfElseCounter
 Internal counter for keeping track of nested if-then-else clauses. More...
 
valbuf_type m_vStackBuffer
 This is merely a buffer used for the stack in the cmd parsing routine. More...
 
int m_nFinalResultIdx
 

Static Private Attributes

static const int s_MaxNumOpenMPThreads = 16
 Maximum number of threads spawned by OpenMP when using the bulk mode. More...
 

Friends

class ParserTokenReader
 

Detailed Description

Mathematical expressions parser (base parser engine).

Author
(C) 2013 Ingo Berg

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 62 of file muParserBase.h.

Member Typedef Documentation

◆ exception_type

Type of the error class.

Included for backwards compatibility.

Definition at line 97 of file muParserBase.h.

◆ ParseFunction

typedef value_type(ParserBase::* mu::ParserBase::ParseFunction) () const
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 74 of file muParserBase.h.

◆ stringbuf_type

typedef std::vector<string_type> mu::ParserBase::stringbuf_type
private

Type for a vector of strings.

Definition at line 80 of file muParserBase.h.

◆ token_reader_type

Typedef for the token reader.

Definition at line 83 of file muParserBase.h.

◆ token_type

Type used for parser tokens.

Definition at line 86 of file muParserBase.h.

◆ valbuf_type

typedef std::vector<value_type> mu::ParserBase::valbuf_type
private

Type used for storing an array of values.

Definition at line 77 of file muParserBase.h.

Constructor & Destructor Documentation

◆ ParserBase() [1/2]

mu::ParserBase::ParserBase ( )

Constructor.

Parameters
a_szFormulathe formula to interpret.
Exceptions
ParserExceptionif a_szFormula is null.

Definition at line 79 of file muParserBase.cpp.

◆ ParserBase() [2/2]

mu::ParserBase::ParserBase ( const ParserBase a_Parser)

Copy constructor.

The parser can be safely copy constructed but the bytecode is reset during copy construction.

Definition at line 108 of file muParserBase.cpp.

◆ ~ParserBase()

mu::ParserBase::~ParserBase ( )
virtual

Definition at line 131 of file muParserBase.cpp.

Member Function Documentation

◆ AddCallback()

void mu::ParserBase::AddCallback ( const string_type a_strName,
const ParserCallback a_Callback,
funmap_type a_Storage,
const char_type a_szCharSet 
)
private

Add a function or operator callback to the parser.

Definition at line 338 of file muParserBase.cpp.

◆ AddValIdent()

void mu::ParserBase::AddValIdent ( identfun_type  a_pCallback)

Add a value parsing function.

When parsing an expression muParser tries to detect values in the expression string using different valident callbacks. Thus it's possible to parse for hex values, binary values and floating point values.

Definition at line 321 of file muParserBase.cpp.

◆ ApplyBinOprt()

void mu::ParserBase::ApplyBinOprt ( ParserStack< token_type > &  a_stOpt,
ParserStack< token_type > &  a_stVal 
) const
private

Performs the necessary steps to write code for the execution of binary operators into the bytecode.

Definition at line 908 of file muParserBase.cpp.

◆ ApplyFunc()

void mu::ParserBase::ApplyFunc ( ParserStack< token_type > &  a_stOpt,
ParserStack< token_type > &  a_stVal,
int  a_iArgCount 
) const
private

Apply a function token.

Parameters
iArgCountNumber of Arguments actually gathered used only for multiarg functions.
Postcondition
The result is pushed to the value stack
The function token is removed from the stack
Exceptions
exception_typeif Argument count does not match function requirements.

Definition at line 792 of file muParserBase.cpp.

◆ ApplyIfElse()

void mu::ParserBase::ApplyIfElse ( ParserStack< token_type > &  a_stOpt,
ParserStack< token_type > &  a_stVal 
) const
private

Definition at line 874 of file muParserBase.cpp.

◆ ApplyRemainingOprt()

void mu::ParserBase::ApplyRemainingOprt ( ParserStack< token_type > &  stOpt,
ParserStack< token_type > &  stVal 
) const
private

Apply a binary operator.

Parameters
a_stOptThe operator stack
a_stValThe value stack

Definition at line 948 of file muParserBase.cpp.

◆ ApplyStrFunc()

ParserBase::token_type mu::ParserBase::ApplyStrFunc ( const token_type a_FunTok,
const std::vector< token_type > &  a_vArg 
) const
private

Execute a function that takes a single string argument.

Parameters
a_FunTokFunction token.
Exceptions
exception_typeIf the function token is not a string function

Definition at line 752 of file muParserBase.cpp.

◆ Assign()

void mu::ParserBase::Assign ( const ParserBase a_Parser)
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.

Parameters
a_Parserthe source object.

Definition at line 157 of file muParserBase.cpp.

◆ CheckName()

void mu::ParserBase::CheckName ( const string_type a_sName,
const string_type a_szCharSet 
) const
private

Check if a name contains invalid characters.

Exceptions
ParserExceptionif the name contains invalid characters.

Definition at line 393 of file muParserBase.cpp.

◆ CheckOprt()

void mu::ParserBase::CheckOprt ( const string_type a_sName,
const ParserCallback a_Callback,
const string_type a_szCharSet 
) const
private

Check if a name contains invalid characters.

Exceptions
ParserExceptionif the name contains invalid characters.

Definition at line 371 of file muParserBase.cpp.

◆ ClearConst()

void mu::ParserBase::ClearConst ( )

Clear all user defined constants.

Both numeric and string constants will be removed from the internal storage.

Postcondition
Resets the parser to string parsing mode.
Exceptions
nothrow

Definition at line 1496 of file muParserBase.cpp.

◆ ClearFun()

void mu::ParserBase::ClearFun ( )

Clear all functions.

Postcondition
Resets the parser to string parsing mode.
Exceptions
nothrow

Definition at line 1483 of file muParserBase.cpp.

◆ ClearInfixOprt()

void mu::ParserBase::ClearInfixOprt ( )

Clear the user defined Prefix operators.

Postcondition
Resets the parser to string parser mode.
Exceptions
nothrow

Definition at line 1530 of file muParserBase.cpp.

◆ ClearOprt()

void mu::ParserBase::ClearOprt ( )

Clear all user defined binary operators.

Postcondition
Resets the parser to string parsing mode.
Exceptions
nothrow

Definition at line 1519 of file muParserBase.cpp.

◆ ClearPostfixOprt()

void mu::ParserBase::ClearPostfixOprt ( )

Clear all user defined postfix operators.

Postcondition
Resets the parser to string parsing mode.
Exceptions
nothrow

Definition at line 1508 of file muParserBase.cpp.

◆ ClearVar()

void mu::ParserBase::ClearVar ( )

Clear all user defined variables.

Exceptions
nothrowResets the parser to string parsing mode by calling ReInit.

Definition at line 1456 of file muParserBase.cpp.

◆ CreateRPN()

void mu::ParserBase::CreateRPN ( ) const
private

Definition at line 1177 of file muParserBase.cpp.

◆ DefineConst()

void mu::ParserBase::DefineConst ( const string_type a_sName,
value_type  a_fVal 
)

Add a user defined constant.

Parameters
[in]a_sNameThe name of the constant.
[in]a_fValthe value of the constant.
Postcondition
Will reset the Parser to string parsing mode.
Exceptions
ParserExceptionin case the name contains invalid signs.

Definition at line 616 of file muParserBase.cpp.

◆ DefineFun()

template<typename T >
void mu::ParserBase::DefineFun ( const string_type a_strName,
a_pFun,
bool  a_bAllowOpt = true 
)
inline

Define a parser function without arguments.

Parameters
a_strNameName of the function
a_pFunPointer to the callback function
a_bAllowOptA flag indicating this function may be optimized

Definition at line 133 of file muParserBase.h.

◆ DefineInfixOprt()

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.

Postcondition
Will reset the Parser to string parsing mode.
Parameters
[in]a_sNameoperator Identifier
[in]a_pFunOperator callback function
[in]a_iPrecOperator Precedence (default=prSIGN)
[in]a_bAllowOptTrue if operator is volatile (default=false)
See also
EPrec

Definition at line 530 of file muParserBase.cpp.

◆ DefineInfixOprtChars()

void mu::ParserBase::DefineInfixOprtChars ( const char_type a_szCharset)

Define the set of valid characters to be used in names of infix operators.

Definition at line 459 of file muParserBase.cpp.

◆ DefineNameChars()

void mu::ParserBase::DefineNameChars ( const char_type a_szCharset)

Define the set of valid characters to be used in names of functions, variables, constants.

Definition at line 441 of file muParserBase.cpp.

◆ DefineOprt()

void mu::ParserBase::DefineOprt ( const string_type a_sName,
fun_type2  a_pFun,
unsigned  a_iPrec = 0,
EOprtAssociativity  a_eAssociativity = oaLEFT,
bool  a_bAllowOpt = false 
)

Define a binary operator.

Parameters
[in]a_sNameThe identifier of the operator.
[in]a_pFunPointer to the callback function.
[in]a_iPrecPrecedence of the operator.
[in]a_eAssociativityThe associativity of the operator.
[in]a_bAllowOptIf this is true the operator may be optimized away.

Adds a new Binary operator the the parser instance.

Definition at line 552 of file muParserBase.cpp.

◆ DefineOprtChars()

void mu::ParserBase::DefineOprtChars ( const char_type a_szCharset)

Define the set of valid characters to be used in names of binary operators and postfix operators.

Definition at line 450 of file muParserBase.cpp.

◆ DefinePostfixOprt()

void mu::ParserBase::DefinePostfixOprt ( const string_type a_sName,
fun_type1  a_pFun,
bool  a_bAllowOpt = true 
)

Add a user defined operator.

Postcondition
Will reset the Parser to string parsing mode.

Definition at line 498 of file muParserBase.cpp.

◆ DefineStrConst()

void mu::ParserBase::DefineStrConst ( const string_type a_strName,
const string_type a_strVal 
)

Define a new string constant.

Parameters
[in]a_strNameThe name of the constant.
[in]a_strValthe value of the constant.

Definition at line 574 of file muParserBase.cpp.

◆ DefineVar()

void mu::ParserBase::DefineVar ( const string_type a_sName,
value_type a_pVar 
)

Add a user defined variable.

Parameters
[in]a_sNamethe variable name
[in]a_pVarA pointer to the variable value.
Postcondition
Will reset the Parser to string parsing mode.
Exceptions
ParserExceptionin case the name contains invalid signs or a_pVar is NULL.

Definition at line 595 of file muParserBase.cpp.

◆ EnableBuiltInOprt()

void mu::ParserBase::EnableBuiltInOprt ( bool  a_bIsOn = true)

Enable or disable the built in binary operators.

Exceptions
nothrow
See also
m_bBuiltInOp, ReInit()

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 1570 of file muParserBase.cpp.

◆ EnableDebugDump()

void mu::ParserBase::EnableDebugDump ( bool  bDumpCmd,
bool  bDumpStack 
)
static

Enable the dumping of bytecode and stack content on the console.

Parameters
bDumpCmdFlag to enable dumping of the current bytecode to the console.
bDumpStackFlag to enable dumping of the stack content is written to the console.

This function is for debug purposes only!

Definition at line 1554 of file muParserBase.cpp.

◆ EnableOptimizer()

void mu::ParserBase::EnableOptimizer ( bool  a_bIsOn = true)

Enable or disable the formula optimization feature.

Postcondition
Resets the parser to string parser mode.
Exceptions
nothrow

Definition at line 1541 of file muParserBase.cpp.

◆ Error()

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.

Parameters
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.
Exceptions
ParserExceptionalways throws that's the only purpose of this function.

Definition at line 1445 of file muParserBase.cpp.

◆ Eval() [1/3]

value_type mu::ParserBase::Eval ( ) const

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 explicitly calls Eval() forcing this update.

Precondition
A formula must be set.
Variables must have been set (if needed)
See also
m_pParseFormula
Returns
The evaluation result
Exceptions
ParseExceptionif no Formula is set or in case of any other error related to the formula.

Definition at line 1713 of file muParserBase.cpp.

◆ Eval() [2/3]

value_type * mu::ParserBase::Eval ( int &  nStackSize) const

Evaluate an expression containing comma separated subexpressions.

Parameters
[out]nStackSizeThe total number of results available
Returns
Pointer to the array containing all expression results

This member function can be used to retrieve all results of an expression made up of multiple comma separated subexpressions (i.e. "x+y,sin(x),cos(y)")

Definition at line 1676 of file muParserBase.cpp.

◆ Eval() [3/3]

void mu::ParserBase::Eval ( value_type results,
int  nBulkSize 
)

Definition at line 1719 of file muParserBase.cpp.

◆ GetArgSep()

char_type mu::ParserBase::GetArgSep ( ) const

Get the argument separator character.

Definition at line 1589 of file muParserBase.cpp.

◆ GetConst()

const valmap_type & mu::ParserBase::GetConst ( ) const

Return a map containing all parser constants.

Definition at line 719 of file muParserBase.cpp.

◆ GetExpr()

const string_type & mu::ParserBase::GetExpr ( ) const

Retrieve the formula.

Definition at line 742 of file muParserBase.cpp.

◆ GetFunDef()

const funmap_type & mu::ParserBase::GetFunDef ( ) const

Return prototypes of all parser functions.

Returns
m_FunDef
See also
FunProt
Exceptions
nothrowThe 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 735 of file muParserBase.cpp.

◆ GetNumResults()

int mu::ParserBase::GetNumResults ( ) const

Return the number of results on the calculation stack.

If the expression contains comma separated subexpressions (i.e. "sin(y), x+y"). There may be more than one return value. This function returns the number of available results.

Definition at line 1692 of file muParserBase.cpp.

◆ GetOprtAssociativity()

EOprtAssociativity mu::ParserBase::GetOprtAssociativity ( const token_type a_Tok) const
private

Get operator priority.

Exceptions
ParserExceptionif a_Oprt is no operator code

Definition at line 663 of file muParserBase.cpp.

◆ GetOprtDef()

const char_type ** mu::ParserBase::GetOprtDef ( ) const

Get the default symbols used for the built in operators.

See also
c_DefaultOprt

Definition at line 432 of file muParserBase.cpp.

◆ GetOprtPrecedence()

int mu::ParserBase::GetOprtPrecedence ( const token_type a_Tok) const
private

Get operator priority.

Exceptions
ParserExceptionif a_Oprt is no operator code

Definition at line 627 of file muParserBase.cpp.

◆ GetUsedVar()

const varmap_type & mu::ParserBase::GetUsedVar ( ) const

Return a map containing the used variables only.

Definition at line 688 of file muParserBase.cpp.

◆ GetVar()

const varmap_type & mu::ParserBase::GetVar ( ) const

Return a map containing the used variables only.

Definition at line 712 of file muParserBase.cpp.

◆ GetVersion()

string_type mu::ParserBase::GetVersion ( EParserVersionInfo  eInfo = pviFULL) const

Returns the version of muparser.

Parameters
eInfoA flag indicating whether the full version info should be returned or not.

Format is as follows: "MAJOR.MINOR (COMPILER_FLAGS)" The COMPILER_FLAGS are returned only if eInfo==pviFULL.

Definition at line 269 of file muParserBase.cpp.

◆ HasBuiltInOprt()

bool mu::ParserBase::HasBuiltInOprt ( ) const

Query status of built in variables.

Returns
m_bBuiltInOp; true if built in operators are enabled.
Exceptions
nothrow

Definition at line 1581 of file muParserBase.cpp.

◆ Init()

void mu::ParserBase::Init ( )
protected

Initialize user defined functions.

Calls the virtual functions InitFun(), InitConst() and InitOprt().

Definition at line 513 of file muParserBase.cpp.

◆ InitCharSets()

virtual void mu::ParserBase::InitCharSets ( )
protectedpure virtual

Implemented in mu::ParserInt, and mu::Parser.

◆ InitConst()

virtual void mu::ParserBase::InitConst ( )
protectedpure virtual

Implemented in mu::ParserInt, and mu::Parser.

◆ InitFun()

virtual void mu::ParserBase::InitFun ( )
protectedpure virtual

Implemented in mu::ParserInt, and mu::Parser.

◆ InitOprt()

virtual void mu::ParserBase::InitOprt ( )
protectedpure virtual

Implemented in mu::ParserInt, and mu::Parser.

◆ InitTokenReader()

void mu::ParserBase::InitTokenReader ( )
private

Initialize the token reader.

Create new token reader object and submit pointers to function, operator, constant and variable definitions.

Postcondition
m_pTokenReader.get()!=0
Exceptions
nothrow

Definition at line 237 of file muParserBase.cpp.

◆ OnDetectVar()

void mu::ParserBase::OnDetectVar ( string_type pExpr,
int &  nStart,
int &  nEnd 
)
protectedvirtual

Reimplemented in mu::Parser.

Definition at line 258 of file muParserBase.cpp.

◆ operator=()

ParserBase & mu::ParserBase::operator= ( const ParserBase a_Parser)

Assignment operator.

Implemented by calling Assign(a_Parser). Self assignment is suppressed.

Parameters
a_ParserObject to copy to this.
Returns
*this
Exceptions
nothrow

Definition at line 142 of file muParserBase.cpp.

◆ ParseCmdCode()

value_type mu::ParserBase::ParseCmdCode ( ) const
private

Parse the command code.

See also
ParseString(...)

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 998 of file muParserBase.cpp.

◆ ParseCmdCodeBulk()

value_type mu::ParserBase::ParseCmdCodeBulk ( int  nOffset,
int  nThreadID 
) const
private

Evaluate the RPN.

Parameters
nOffsetThe offset added to variable addresses (for bulk mode)
nThreadIDOpenMP Thread id of the calling thread

Definition at line 1008 of file muParserBase.cpp.

◆ ParseString()

value_type mu::ParserBase::ParseString ( ) const
private

One of the two main parse functions.

See also
ParseCmdCode(...)

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 1419 of file muParserBase.cpp.

◆ ReInit()

void mu::ParserBase::ReInit ( ) const
private

Reset parser to string parsing mode and clear internal buffers.

Clear bytecode, reset the token reader.

Exceptions
nothrow

Definition at line 248 of file muParserBase.cpp.

◆ RemoveVar()

void mu::ParserBase::RemoveVar ( const string_type a_strVarName)

Remove a variable from internal storage.

Exceptions
nothrowRemoves a variable if it exists. If the Variable does not exist nothing will be done.

Definition at line 1468 of file muParserBase.cpp.

◆ ResetLocale()

void mu::ParserBase::ResetLocale ( )

Resets the locale.

The default locale used "." as decimal separator, no thousands separator and "," as function argument separator.

Definition at line 222 of file muParserBase.cpp.

◆ SetArgSep()

void mu::ParserBase::SetArgSep ( char_type  cArgSep)

Set argument separator.

Parameters
cArgSepthe argument separator character.

Definition at line 1598 of file muParserBase.cpp.

◆ SetDecSep()

void mu::ParserBase::SetDecSep ( char_type  cDecSep)

Set the decimal separator.

Parameters
cDecSepDecimal separator as a character value.
See also
SetThousandsSep

By default muparser uses the "C" locale. The decimal separator of this locale is overwritten by the one provided here.

Definition at line 196 of file muParserBase.cpp.

◆ SetExpr()

void mu::ParserBase::SetExpr ( const string_type a_sExpr)

Set the formula.

Parameters
a_strFormulaFormula as string_type
Exceptions
ParserExceptionin case of syntax errors.

Triggers first time calculation thus the creation of the bytecode and scanning of used variables.

Definition at line 412 of file muParserBase.cpp.

◆ SetThousandsSep()

void mu::ParserBase::SetThousandsSep ( char_type  cThousandsSep = 0)

Sets the thousands operator.

Parameters
cThousandsSepThe thousands separator as a character
See also
SetDecSep

By default muparser uses the "C" locale. The thousands separator of this locale is overwritten by the one provided here.

Definition at line 210 of file muParserBase.cpp.

◆ SetVarFactory()

void mu::ParserBase::SetVarFactory ( facfun_type  a_pFactory,
void *  pUserData = NULL 
)

Set a function that can create variable pointer for unknown expression variables.

Parameters
a_pFactoryA pointer to the variable factory.
pUserDataA user defined context pointer.

Definition at line 331 of file muParserBase.cpp.

◆ StackDump()

void mu::ParserBase::StackDump ( const ParserStack< token_type > &  a_stVal,
const ParserStack< token_type > &  a_stOprt 
) const
private

Dump stack content.

This function is used for debugging only.

Definition at line 1608 of file muParserBase.cpp.

◆ ValidInfixOprtChars()

const char_type * mu::ParserBase::ValidInfixOprtChars ( ) const

Virtual function that defines the characters allowed in infix operator definitions.

See also
ValidNameChars, ValidOprtChars

Definition at line 488 of file muParserBase.cpp.

◆ ValidNameChars()

const char_type * mu::ParserBase::ValidNameChars ( ) const

Virtual function that defines the characters allowed in name identifiers.

See also
ValidOprtChars, #ValidPrefixOprtChars

Definition at line 468 of file muParserBase.cpp.

◆ ValidOprtChars()

const char_type * mu::ParserBase::ValidOprtChars ( ) const

Virtual function that defines the characters allowed in operator definitions.

See also
ValidNameChars, #ValidPrefixOprtChars

Definition at line 478 of file muParserBase.cpp.

Friends And Related Function Documentation

◆ ParserTokenReader

friend class ParserTokenReader
friend

Definition at line 64 of file muParserBase.h.

Member Data Documentation

◆ c_DefaultOprt

const char_type * mu::ParserBase::c_DefaultOprt
staticprotected
Initial value:
=
{
_T("<="), _T(">="), _T("!="),
_T("=="), _T("<"), _T(">"),
_T("+"), _T("-"), _T("*"),
_T("/"), _T("^"), _T("&&"),
_T("||"), _T("="), _T("("),
_T(")"), _T("?"), _T(":"), 0
}

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 192 of file muParserBase.h.

◆ g_DbgDumpCmdCode

bool mu::ParserBase::g_DbgDumpCmdCode = false
staticprotected

Definition at line 194 of file muParserBase.h.

◆ g_DbgDumpStack

bool mu::ParserBase::g_DbgDumpStack = false
staticprotected

Definition at line 195 of file muParserBase.h.

◆ m_bBuiltInOp

bool mu::ParserBase::m_bBuiltInOp
private

Flag that can be used for switching built in operators on and off.

Definition at line 301 of file muParserBase.h.

◆ m_ConstDef

valmap_type mu::ParserBase::m_ConstDef
private

user constants.

Definition at line 297 of file muParserBase.h.

◆ m_FunDef

funmap_type mu::ParserBase::m_FunDef
private

Map of function names and pointers.

Definition at line 293 of file muParserBase.h.

◆ m_InfixOprtDef

funmap_type mu::ParserBase::m_InfixOprtDef
private

unary infix operator.

Definition at line 295 of file muParserBase.h.

◆ m_nFinalResultIdx

int mu::ParserBase::m_nFinalResultIdx
mutableprivate

Definition at line 311 of file muParserBase.h.

◆ m_nIfElseCounter

int mu::ParserBase::m_nIfElseCounter
mutableprivate

Internal counter for keeping track of nested if-then-else clauses.

Definition at line 307 of file muParserBase.h.

◆ m_OprtDef

funmap_type mu::ParserBase::m_OprtDef
private

Binary operator callbacks.

Definition at line 296 of file muParserBase.h.

◆ m_PostOprtDef

funmap_type mu::ParserBase::m_PostOprtDef
private

Postfix operator callbacks.

Definition at line 294 of file muParserBase.h.

◆ m_pParseFormula

ParseFunction mu::ParserBase::m_pParseFormula
mutableprivate

Pointer to the parser function.

Eval() calls the function whose address is stored there.

Definition at line 286 of file muParserBase.h.

◆ m_pTokenReader

std::unique_ptr<token_reader_type> mu::ParserBase::m_pTokenReader
private

Managed pointer to the token reader object.

Definition at line 291 of file muParserBase.h.

◆ m_sInfixOprtChars

string_type mu::ParserBase::m_sInfixOprtChars
private

Charset for infix operator tokens.

Definition at line 305 of file muParserBase.h.

◆ m_sNameChars

string_type mu::ParserBase::m_sNameChars
private

Charset for names.

Definition at line 303 of file muParserBase.h.

◆ m_sOprtChars

string_type mu::ParserBase::m_sOprtChars
private

Charset for postfix/ binary operator tokens.

Definition at line 304 of file muParserBase.h.

◆ m_StrVarDef

strmap_type mu::ParserBase::m_StrVarDef
private

user defined string constants

Definition at line 298 of file muParserBase.h.

◆ m_VarDef

varmap_type mu::ParserBase::m_VarDef
private

user defind variables.

Definition at line 299 of file muParserBase.h.

◆ m_vRPN

ParserByteCode mu::ParserBase::m_vRPN
mutableprivate

The Bytecode class.

Definition at line 287 of file muParserBase.h.

◆ m_vStackBuffer

valbuf_type mu::ParserBase::m_vStackBuffer
mutableprivate

This is merely a buffer used for the stack in the cmd parsing routine.

Definition at line 310 of file muParserBase.h.

◆ m_vStringBuf

stringbuf_type mu::ParserBase::m_vStringBuf
mutableprivate

String buffer, used for storing string function arguments.

Definition at line 288 of file muParserBase.h.

◆ m_vStringVarBuf

stringbuf_type mu::ParserBase::m_vStringVarBuf
private

Definition at line 289 of file muParserBase.h.

◆ s_locale

std::locale mu::ParserBase::s_locale = std::locale(std::locale::classic(), new change_dec_sep<char_type>('.'))
staticprotected

The locale used by the parser.

Definition at line 193 of file muParserBase.h.

◆ s_MaxNumOpenMPThreads

const int mu::ParserBase::s_MaxNumOpenMPThreads = 16
staticprivate

Maximum number of threads spawned by OpenMP when using the bulk mode.

Definition at line 89 of file muParserBase.h.


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