muParser API -  1.35
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Attributes | Friends | List of all members
mu::ParserBase Class Referenceabstract

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

#include <muParserBase.h>

Inheritance diagram for mu::ParserBase:
Inheritance graph
[legend]

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...
 
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.
 
const varmap_typeGetVar () const
 Return a map containing the used variables only.
 
const valmap_typeGetConst () const
 Return a map containing all parser constants.
 
const string_typeGetExpr () const
 Retrieve the formula.
 
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.
 
void DefineOprtChars (const char_type *a_szCharset)
 Define the set of valid characters to be used in names of binary operators and postfix operators.
 
void DefineInfixOprtChars (const char_type *a_szCharset)
 Define the set of valid characters to be used in names of infix operators.
 
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.
 
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.
 
static bool g_DbgDumpCmdCode = false
 
static bool g_DbgDumpStack = false
 

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

Type of the error class.

Included for backwards compatibility.

Definition at line 97 of file muParserBase.h.

Constructor & Destructor Documentation

mu::ParserBase::ParserBase ( )

Constructor.

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

Definition at line 77 of file muParserBase.cpp.

78  :m_pParseFormula(&ParserBase::ParseString)
79  ,m_vRPN()
80  ,m_vStringBuf()
81  ,m_pTokenReader()
82  ,m_FunDef()
83  ,m_PostOprtDef()
84  ,m_InfixOprtDef()
85  ,m_OprtDef()
86  ,m_ConstDef()
87  ,m_StrVarDef()
88  ,m_VarDef()
89  ,m_bBuiltInOp(true)
90  ,m_sNameChars()
91  ,m_sOprtChars()
92  ,m_sInfixOprtChars()
93  ,m_nIfElseCounter(0)
94  ,m_vStackBuffer()
95  ,m_nFinalResultIdx(0)
96  {
97  InitTokenReader();
98  }
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 106 of file muParserBase.cpp.

107  :m_pParseFormula(&ParserBase::ParseString)
108  ,m_vRPN()
109  ,m_vStringBuf()
110  ,m_pTokenReader()
111  ,m_FunDef()
112  ,m_PostOprtDef()
113  ,m_InfixOprtDef()
114  ,m_OprtDef()
115  ,m_ConstDef()
116  ,m_StrVarDef()
117  ,m_VarDef()
118  ,m_bBuiltInOp(true)
119  ,m_sNameChars()
120  ,m_sOprtChars()
121  ,m_sInfixOprtChars()
122  ,m_nIfElseCounter(0)
123  {
124  m_pTokenReader.reset(new token_reader_type(this));
125  Assign(a_Parser);
126  }

Member Function Documentation

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

Referenced by mu::Parser::Parser(), and mu::ParserInt::ParserInt().

320  {
321  m_pTokenReader->AddValIdent(a_pCallback);
322  }
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 1491 of file muParserBase.cpp.

1492  {
1493  m_ConstDef.clear();
1494  m_StrVarDef.clear();
1495  ReInit();
1496  }
void mu::ParserBase::ClearFun ( )

Clear all functions.

Postcondition
Resets the parser to string parsing mode.
Exceptions
nothrow

Definition at line 1478 of file muParserBase.cpp.

1479  {
1480  m_FunDef.clear();
1481  ReInit();
1482  }
void mu::ParserBase::ClearInfixOprt ( )

Clear the user defined Prefix operators.

Postcondition
Resets the parser to string parser mode.
Exceptions
nothrow

Definition at line 1525 of file muParserBase.cpp.

1526  {
1527  m_InfixOprtDef.clear();
1528  ReInit();
1529  }
void mu::ParserBase::ClearOprt ( )

Clear all user defined binary operators.

Postcondition
Resets the parser to string parsing mode.
Exceptions
nothrow

Definition at line 1514 of file muParserBase.cpp.

1515  {
1516  m_OprtDef.clear();
1517  ReInit();
1518  }
void mu::ParserBase::ClearPostfixOprt ( )

Clear all user defined postfix operators.

Postcondition
Resets the parser to string parsing mode.
Exceptions
nothrow

Definition at line 1503 of file muParserBase.cpp.

1504  {
1505  m_PostOprtDef.clear();
1506  ReInit();
1507  }
void mu::ParserBase::ClearVar ( )

Clear all user defined variables.

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

Definition at line 1451 of file muParserBase.cpp.

1452  {
1453  m_VarDef.clear();
1454  ReInit();
1455  }
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 615 of file muParserBase.cpp.

Referenced by mu::Parser::InitConst().

616  {
617  CheckName(a_sName, ValidNameChars());
618  m_ConstDef[a_sName] = a_fVal;
619  ReInit();
620  }
const char_type * ValidNameChars() const
Virtual function that defines the characters allowed in name identifiers.
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.

Referenced by mu::Parser::InitFun(), and mu::ParserInt::InitFun().

134  {
135  AddCallback( a_strName, ParserCallback(a_pFun, a_bAllowOpt), m_FunDef, ValidNameChars() );
136  }
const char_type * ValidNameChars() const
Virtual function that defines the characters allowed in name identifiers.
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 529 of file muParserBase.cpp.

Referenced by mu::Parser::InitOprt(), and mu::ParserInt::InitOprt().

533  {
534  AddCallback(a_sName,
535  ParserCallback(a_pFun, a_bAllowOpt, a_iPrec, cmOPRT_INFIX),
536  m_InfixOprtDef,
538  }
code for infix operators
Definition: muParserDef.h:191
const char_type * ValidInfixOprtChars() const
Virtual function that defines the characters allowed in infix operator definitions.
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 551 of file muParserBase.cpp.

Referenced by mu::ParserInt::InitOprt().

556  {
557  // Check for conflicts with built in operator names
558  for (int i=0; m_bBuiltInOp && i<cmENDIF; ++i)
559  if (a_sName == string_type(c_DefaultOprt[i]))
560  Error(ecBUILTIN_OVERLOAD, -1, a_sName);
561 
562  AddCallback(a_sName,
563  ParserCallback(a_pFun, a_bAllowOpt, a_iPrec, a_eAssociativity),
564  m_OprtDef,
565  ValidOprtChars() );
566  }
Trying to overload builtin operator.
Definition: muParserError.h:74
static const char_type * c_DefaultOprt[]
Identifiers for built in binary operators.
Definition: muParserBase.h:192
const char_type * ValidOprtChars() const
Virtual function that defines the characters allowed in operator definitions.
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.
For use in the ternary if-then-else operator.
Definition: muParserDef.h:172
MUP_STRING_TYPE string_type
The stringtype used by the parser.
Definition: muParserDef.h:253
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 497 of file muParserBase.cpp.

500  {
501  AddCallback(a_sName,
502  ParserCallback(a_pFun, a_bAllowOpt, prPOSTFIX, cmOPRT_POSTFIX),
503  m_PostOprtDef,
504  ValidOprtChars() );
505  }
Postfix operator priority (currently unused)
Definition: muParserDef.h:237
code for postfix operators
Definition: muParserDef.h:190
const char_type * ValidOprtChars() const
Virtual function that defines the characters allowed in operator definitions.
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 573 of file muParserBase.cpp.

574  {
575  // Test if a constant with that names already exists
576  if (m_StrVarDef.find(a_strName)!=m_StrVarDef.end())
578 
579  CheckName(a_strName, ValidNameChars());
580 
581  m_vStringVarBuf.push_back(a_strVal); // Store variable string in internal buffer
582  m_StrVarDef[a_strName] = m_vStringVarBuf.size()-1; // bind buffer index to variable name
583 
584  ReInit();
585  }
Name conflict.
Definition: muParserError.h:78
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.
const char_type * ValidNameChars() const
Virtual function that defines the characters allowed in name identifiers.
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 594 of file muParserBase.cpp.

595  {
596  if (a_pVar==0)
598 
599  // Test if a constant with that names already exists
600  if (m_ConstDef.find(a_sName)!=m_ConstDef.end())
602 
603  CheckName(a_sName, ValidNameChars());
604  m_VarDef[a_sName] = a_pVar;
605  ReInit();
606  }
Name conflict.
Definition: muParserError.h:78
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.
const char_type * ValidNameChars() const
Virtual function that defines the characters allowed in name identifiers.
Invalid variable pointer.
Definition: muParserError.h:76
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 1565 of file muParserBase.cpp.

Referenced by mu::ParserInt::InitOprt().

1566  {
1567  m_bBuiltInOp = a_bIsOn;
1568  ReInit();
1569  }
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 1549 of file muParserBase.cpp.

1550  {
1551  ParserBase::g_DbgDumpCmdCode = bDumpCmd;
1552  ParserBase::g_DbgDumpStack = bDumpStack;
1553  }
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 1536 of file muParserBase.cpp.

1537  {
1538  m_vRPN.EnableOptimizer(a_bIsOn);
1539  ReInit();
1540  }
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 thats the only purpose of this function.

Definition at line 1440 of file muParserBase.cpp.

Referenced by DefineOprt(), DefineStrConst(), DefineVar(), and SetExpr().

1441  {
1442  throw exception_type(a_iErrc, a_sTok, m_pTokenReader->GetExpr(), a_iPos);
1443  }
ParserError exception_type
Type of the error class.
Definition: muParserBase.h:97
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 1708 of file muParserBase.cpp.

Referenced by mu::Parser::Diff().

1709  {
1710  return (this->*m_pParseFormula)();
1711  }
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 1671 of file muParserBase.cpp.

1672  {
1673  (this->*m_pParseFormula)();
1674  nStackSize = m_nFinalResultIdx;
1675 
1676  // (for historic reasons the stack starts at position 1)
1677  return &m_vStackBuffer[1];
1678  }
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 734 of file muParserBase.cpp.

735  {
736  return m_FunDef;
737  }
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 1687 of file muParserBase.cpp.

1688  {
1689  return m_nFinalResultIdx;
1690  }
const char_type ** mu::ParserBase::GetOprtDef ( ) const

Get the default symbols used for the built in operators.

See also
c_DefaultOprt

Definition at line 431 of file muParserBase.cpp.

432  {
433  return (const char_type **)(&c_DefaultOprt[0]);
434  }
static const char_type * c_DefaultOprt[]
Identifiers for built in binary operators.
Definition: muParserBase.h:192
string_type::value_type char_type
The character type used by the parser.
Definition: muParserDef.h:259
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 267 of file muParserBase.cpp.

268  {
270 
271  ss << MUP_VERSION;
272 
273  if (eInfo==pviFULL)
274  {
275  ss << _T(" (") << MUP_VERSION_DATE;
276  ss << std::dec << _T("; ") << sizeof(void*)*8 << _T("BIT");
277 
278 #ifdef _DEBUG
279  ss << _T("; DEBUG");
280 #else
281  ss << _T("; RELEASE");
282 #endif
283 
284 #ifdef _UNICODE
285  ss << _T("; UNICODE");
286 #else
287  #ifdef _MBCS
288  ss << _T("; MBCS");
289  #else
290  ss << _T("; ASCII");
291  #endif
292 #endif
293 
294 #ifdef MUP_USE_OPENMP
295  ss << _T("; OPENMP");
296 //#else
297 // ss << _T("; NO_OPENMP");
298 #endif
299 
300 #if defined(MUP_MATH_EXCEPTIONS)
301  ss << _T("; MATHEXC");
302 //#else
303 // ss << _T("; NO_MATHEXC");
304 #endif
305 
306  ss << _T(")");
307  }
308 
309  return ss.str();
310  }
#define _T(x)
Activate this option in order to compile with OpenMP support.
Definition: muParserDef.h:69
std::basic_stringstream< char_type, std::char_traits< char_type >, std::allocator< char_type > > stringstream_type
Typedef for easily using stringstream that respect the parser stringtype.
Definition: muParserDef.h:264
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 1576 of file muParserBase.cpp.

1577  {
1578  return m_bBuiltInOp;
1579  }
void mu::ParserBase::Init ( )
protected

Initialize user defined functions.

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

Definition at line 512 of file muParserBase.cpp.

513  {
514  InitCharSets();
515  InitFun();
516  InitConst();
517  InitOprt();
518  }
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 140 of file muParserBase.cpp.

141  {
142  Assign(a_Parser);
143  return *this;
144  }
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 1463 of file muParserBase.cpp.

1464  {
1465  varmap_type::iterator item = m_VarDef.find(a_strVarName);
1466  if (item!=m_VarDef.end())
1467  {
1468  m_VarDef.erase(item);
1469  ReInit();
1470  }
1471  }
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 220 of file muParserBase.cpp.

221  {
222  s_locale = std::locale(std::locale("C"), new change_dec_sep<char_type>('.'));
223  SetArgSep(',');
224  }
static std::locale s_locale
The locale used by the parser.
Definition: muParserBase.h:193
void SetArgSep(char_type cArgSep)
Set argument separator.
void mu::ParserBase::SetArgSep ( char_type  cArgSep)

Set argument separator.

Parameters
cArgSepthe argument separator character.

Definition at line 1593 of file muParserBase.cpp.

Referenced by ResetLocale().

1594  {
1595  m_pTokenReader->SetArgSep(cArgSep);
1596  }
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 194 of file muParserBase.cpp.

195  {
196  char_type cThousandsSep = std::use_facet< change_dec_sep<char_type> >(s_locale).thousands_sep();
197  s_locale = std::locale(std::locale("C"), new change_dec_sep<char_type>(cDecSep, cThousandsSep));
198  }
static std::locale s_locale
The locale used by the parser.
Definition: muParserBase.h:193
string_type::value_type char_type
The character type used by the parser.
Definition: muParserDef.h:259
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 410 of file muParserBase.cpp.

411  {
412  // Check locale compatibility
413  std::locale loc;
414  if (m_pTokenReader->GetArgSep()==std::use_facet<numpunct<char_type> >(loc).decimal_point())
415  Error(ecLOCALE);
416 
417  // <ibg> 20060222: Bugfix for Borland-Kylix:
418  // adding a space to the expression will keep Borlands KYLIX from going wild
419  // when calling tellg on a stringstream created from the expression after
420  // reading a value at the end of an expression. (mu::Parser::IsVal function)
421  // (tellg returns -1 otherwise causing the parser to ignore the value)
422  string_type sBuf(a_sExpr + _T(" ") );
423  m_pTokenReader->SetFormula(sBuf);
424  ReInit();
425  }
#define _T(x)
Activate this option in order to compile with OpenMP support.
Definition: muParserDef.h:69
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.
Conflict with current locale.
Definition: muParserError.h:84
MUP_STRING_TYPE string_type
The stringtype used by the parser.
Definition: muParserDef.h:253
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 208 of file muParserBase.cpp.

209  {
210  char_type cDecSep = std::use_facet< change_dec_sep<char_type> >(s_locale).decimal_point();
211  s_locale = std::locale(std::locale("C"), new change_dec_sep<char_type>(cDecSep, cThousandsSep));
212  }
static std::locale s_locale
The locale used by the parser.
Definition: muParserBase.h:193
string_type::value_type char_type
The character type used by the parser.
Definition: muParserDef.h:259
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 329 of file muParserBase.cpp.

330  {
331  m_pTokenReader->SetVarCreator(a_pFactory, pUserData);
332  }
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 487 of file muParserBase.cpp.

Referenced by DefineInfixOprt().

488  {
489  assert(m_sInfixOprtChars.size());
490  return m_sInfixOprtChars.c_str();
491  }
const char_type * mu::ParserBase::ValidNameChars ( ) const

Virtual function that defines the characters allowed in name identifiers.

See also
ValidOprtChars, #ValidPrefixOprtChars

Definition at line 467 of file muParserBase.cpp.

Referenced by DefineConst(), DefineFun(), DefineStrConst(), DefineVar(), and mu::ParserTokenReader::ReadNextToken().

468  {
469  assert(m_sNameChars.size());
470  return m_sNameChars.c_str();
471  }
const char_type * mu::ParserBase::ValidOprtChars ( ) const

Virtual function that defines the characters allowed in operator definitions.

See also
ValidNameChars, #ValidPrefixOprtChars

Definition at line 477 of file muParserBase.cpp.

Referenced by DefineOprt(), and DefinePostfixOprt().

478  {
479  assert(m_sOprtChars.size());
480  return m_sOprtChars.c_str();
481  }

Member Data Documentation

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.

Referenced by DefineOprt(), and GetOprtDef().


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