Seamly2D
Code documentation
qmuparserbase.h
Go to the documentation of this file.
1 /***************************************************************************************************
2  **
3  ** Copyright (C) 2013 Ingo Berg
4  **
5  ** Permission is hereby granted, free of charge, to any person obtaining a copy of this
6  ** software and associated documentation files (the "Software"), to deal in the Software
7  ** without restriction, including without limitation the rights to use, copy, modify,
8  ** merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
9  ** permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  **
11  ** The above copyright notice and this permission notice shall be included in all copies or
12  ** substantial portions of the Software.
13  **
14  ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15  ** NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16  ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17  ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  **
20  ******************************************************************************************************/
21 
22 #ifndef QMUQPARSERBASE_H
23 #define QMUQPARSERBASE_H
24 
25 #include <limits.h>
26 #include <qcompilerdetection.h>
27 #include <QChar>
28 #include <QMap>
29 #include <QStack>
30 #include <QString>
31 #include <QStringList>
32 #include <QVector>
33 #include <QtGlobal>
34 #include <memory>
35 #include <string>
36 #include <QLocale>
37 
38 #include "qmuparserbytecode.h"
39 #include "qmuparsercallback.h"
40 #include "qmuparserdef.h"
41 #include "qmuparsererror.h"
42 #include "qmuparsertoken.h"
43 #include "qmuparsertokenreader.h"
44 
45 template <class T> class QStack;
46 
47 namespace qmu
48 {
49 /**
50  * @file
51  * @brief This file contains the class definition of the qmuparser engine.
52  */
53 
54 /**
55  * @brief Mathematical expressions parser (base parser engine).
56  * @author (C) 2013 Ingo Berg
57  *
58  * This is the implementation of a bytecode based mathematical expressions parser.
59  * The formula will be parsed from string and converted into a bytecode.
60  * Future calculations will be done with the bytecode instead the formula string
61  * resulting in a significant performance increase.
62  * Complementary to a set of internally implemented functions the parser is able to handle
63  * user defined functions and variables.
64  */
66 {
67  friend class QmuParserTokenReader;
68 public:
69  QmuParserBase();
70  explicit QmuParserBase(const QmuParserBase &a_Parser);
71  QmuParserBase& operator=(const QmuParserBase &a_Parser);
72  virtual ~QmuParserBase();
73 
74  static void EnableDebugDump(bool bDumpCmd, bool bDumpStack);
75  qreal Eval() const;
76  qreal* Eval(int &nStackSize) const;
77  void Eval(qreal *results, int nBulkSize) const;
78  int GetNumResults() const;
79  void SetExpr(const QString &a_sExpr);
80  void SetVarFactory(facfun_type a_pFactory, void *pUserData = nullptr);
81  void ResetLocale();
82  void EnableOptimizer(bool a_bIsOn=true);
83  void EnableBuiltInOprt(bool a_bIsOn=true);
84  bool HasBuiltInOprt() const;
85  void AddValIdent(identfun_type a_pCallback);
86  void DefineOprt(const QString &a_sName, fun_type2 a_pFun, unsigned a_iPrec=0,
87  EOprtAssociativity a_eAssociativity = oaLEFT, bool a_bAllowOpt = false);
88  void DefineConst(const QString &a_sName, qreal a_fVal);
89  void DefineStrConst(const QString &a_strName, const QString &a_strVal);
90  void DefineVar(const QString &a_sName, qreal *a_pVar);
91  void DefinePostfixOprt(const QString &a_sFun, fun_type1 a_pFun, bool a_bAllowOpt=true);
92  void DefineInfixOprt(const QString &a_sName, fun_type1 a_pFun, int a_iPrec=prINFIX,
93  bool a_bAllowOpt=true);
94  // Clear user defined variables, constants or functions
95  void ClearVar();
96  void ClearFun();
97  void ClearConst();
98  void ClearInfixOprt();
99  void ClearPostfixOprt();
100  void ClearOprt();
101  void RemoveVar(const QString &a_strVarName);
102  const varmap_type& GetUsedVar() const;
103  const varmap_type& GetVar() const;
104  const valmap_type& GetConst() const;
105  const QString& GetExpr() const;
106  const funmap_type& GetFunDef() const;
107  static QString GetVersion(EParserVersionInfo eInfo = pviFULL);
108  static const QStringList& GetOprtDef();
111  void DefineNameChars(const QString &a_szCharset);
112  void DefineOprtChars(const QString &a_szCharset);
113  void DefineInfixOprtChars(const QString &a_szCharset);
114  const QString& ValidNameChars() const;
115  const QString& ValidOprtChars() const;
116  const QString& ValidInfixOprtChars() const;
117  void SetArgSep(char_type cArgSep);
118  QChar GetArgSep() const;
119  void Q_NORETURN Error(EErrorCodes a_iErrc, int a_iPos = -1, const QString &a_sTok = QString() ) const;
120 
121  template<typename T>
122  void DefineFun(const QString &a_strName, T a_pFun, bool a_bAllowOpt = true);
123 
124  void setAllowSubexpressions(bool value);
125 
126  QLocale getLocale() const;
127  void setLocale(const QLocale &value);
128 
129  QChar getDecimalPoint() const;
130  void setDecimalPoint(const QChar &c);
131 
132  QChar getThousandsSeparator() const;
133  void setThousandsSeparator(const QChar &c);
134 
135 protected:
136  static const QStringList c_DefaultOprt;
137  QLocale m_locale;///< The locale used by the parser
140  static bool g_DbgDumpCmdCode;
141  static bool g_DbgDumpStack;
142  void Init();
143  virtual void InitCharSets() = 0;
144  virtual void InitFun() = 0;
145  virtual void InitConst() = 0;
146  virtual void InitOprt() = 0;
147  virtual void OnDetectVar(const QString &pExpr, int &nStart, int &nEnd);
148  /**
149  * @brief A facet class used to change decimal and thousands separator.
150  */
151  template<class TChar>
152  class change_dec_sep : public std::numpunct<TChar>
153  {
154  public:
155  explicit change_dec_sep(char_type cDecSep, char_type cThousandsSep = 0, int nGroup = 3)
156  :std::numpunct<TChar>(), m_nGroup(nGroup), m_cDecPoint(cDecSep), m_cThousandsSep(cThousandsSep)
157  {}
158  protected:
159  virtual char_type do_decimal_point() const Q_DECL_OVERRIDE
160  {
161  return m_cDecPoint;
162  }
163 
164  virtual char_type do_thousands_sep() const Q_DECL_OVERRIDE
165  {
166  return m_cThousandsSep;
167  }
168 
169  virtual std::string do_grouping() const Q_DECL_OVERRIDE
170  {
171  // fix for issue 4: https://code.google.com/p/muparser/issues/detail?id=4
172  // courtesy of Jens Bartsch
173  // original code:
174  // return std::string(1, (char)m_nGroup);
175  // new code:
176  return std::string(1, static_cast<char>(m_cThousandsSep > 0 ? m_nGroup : CHAR_MAX));
177  }
178  private:
179  int m_nGroup;
182  };
183 private:
184  /**
185  * @brief Typedef for the parse functions.
186  *
187  * The parse function do the actual work. The parser exchanges
188  * the function pointer to the parser function depending on
189  * which state it is in. (i.e. bytecode parser vs. string parser)
190  */
191  typedef qreal (QmuParserBase::*ParseFunction)() const;
192 
193  /**
194  * @brief Type used for storing an array of values.
195  */
197 
198  /**
199  * @brief Type for a vector of strings.
200  */
202 
203  /**
204  * @brief Typedef for the token reader.
205  */
207 
208  /**
209  * @brief Type used for parser tokens.
210  */
212 
213  /**
214  * @brief Maximum number of threads spawned by OpenMP when using the bulk mode.
215  */
216  static const int s_MaxNumOpenMPThreads = 4;
217 
218  /**
219  * @brief Pointer to the parser function.
220  *
221  * Eval() calls the function whose address is stored there.
222  */
224  mutable QmuParserByteCode m_vRPN; ///< The Bytecode class.
225  mutable stringbuf_type m_vStringBuf; ///< String buffer, used for storing string function arguments
227 
228  std::unique_ptr<token_reader_type> m_pTokenReader; ///< Managed pointer to the token reader object.
229 
230  funmap_type m_FunDef; ///< Map of function names and pointers.
231  funmap_type m_PostOprtDef; ///< Postfix operator callbacks
232  funmap_type m_InfixOprtDef; ///< unary infix operator.
233  funmap_type m_OprtDef; ///< Binary operator callbacks
234  valmap_type m_ConstDef; ///< user constants.
235  strmap_type m_StrVarDef; ///< user defined string constants
236  varmap_type m_VarDef; ///< user defind variables.
237 
238  bool m_bBuiltInOp; ///< Flag that can be used for switching built in operators on and off
239 
240  QString m_sNameChars; ///< Charset for names
241  QString m_sOprtChars; ///< Charset for postfix/ binary operator tokens
242  QString m_sInfixOprtChars; ///< Charset for infix operator tokens
243 
244  mutable int m_nIfElseCounter; ///< Internal counter for keeping track of nested if-then-else clauses
245 
246  // items merely used for caching state information
247  mutable valbuf_type m_vStackBuffer; ///< This is merely a buffer used for the stack in the cmd parsing routine
248  mutable int m_nFinalResultIdx;
249  mutable QMap<int, QString> m_Tokens;///< Keep all tokens that we can translate
250  mutable QMap<int, QString> m_Numbers;///< Keep all numbers what exist in formula
251 
253 
254  void Assign(const QmuParserBase &a_Parser);
255  void InitTokenReader();
256  void ReInit() const;
257  void AddCallback(const QString &a_strName, const QmuParserCallback &a_Callback,
258  funmap_type &a_Storage, const QString &a_szCharSet );
259  void ApplyRemainingOprt(QStack<token_type> &a_stOpt, QStack<token_type> &a_stVal) const;
260  void ApplyBinOprt(QStack<token_type> &a_stOpt, QStack<token_type> &a_stVal) const;
261  void ApplyIfElse(QStack<token_type> &a_stOpt, QStack<token_type> &a_stVal) const;
262  void ApplyFunc(QStack<token_type> &a_stOpt, QStack<token_type> &a_stVal, int iArgCount) const;
263  token_type ApplyStrFunc(const token_type &a_FunTok, const QVector<token_type> &a_vArg) const;
264  int GetOprtPrecedence(const token_type &a_Tok) const;
266  void CreateRPN() const;
267  qreal ParseString() const;
268  qreal ParseCmdCode() const;
269  qreal ParseCmdCodeBulk(int nOffset, int nThreadID) const;
270  // cppcheck-suppress functionStatic
271  void CheckName(const QString &a_sName, const QString &a_szCharSet) const;
272  // cppcheck-suppress functionStatic
273  void CheckOprt(const QString &a_sName, const QmuParserCallback &a_Callback,
274  const QString &a_szCharSet) const;
275  void StackDump(const QStack<token_type > &a_stVal, const QStack<token_type > &a_stOprt) const;
276 };
277 
278 //---------------------------------------------------------------------------------------------------------------------
279 /**
280  * @fn void qmu::QmuParserBase::DefineFun(const string_type &a_strName, fun_type0 a_pFun,
281  * bool a_bAllowOpt = true)
282  * @brief Define a parser function without arguments.
283  * @param a_strName Name of the function
284  * @param a_pFun Pointer to the callback function
285  * @param a_bAllowOpt A flag indicating this function may be optimized
286  */
287 template<typename T>
288 inline void QmuParserBase::DefineFun(const QString &a_strName, T a_pFun, bool a_bAllowOpt)
289 {
290  AddCallback( a_strName, QmuParserCallback(a_pFun, a_bAllowOpt), m_FunDef, ValidNameChars() );
291 }
292 
293 //---------------------------------------------------------------------------------------------------------------------
294 /**
295  * @brief Initialize the token reader.
296  *
297  * Create new token reader object and submit pointers to function, operator, constant and variable definitions.
298  *
299  * @post m_pTokenReader.get()!=0
300  */
302 {
303  m_pTokenReader.reset(new token_reader_type(this));
304 }
305 
306 //---------------------------------------------------------------------------------------------------------------------
307 /**
308  * @brief Add a value parsing function.
309  *
310  * When parsing an expression muParser tries to detect values in the expression string using different valident
311  * callbacks. Thuis it's possible to parse for hex values, binary values and floating point values.
312  */
314 {
315  m_pTokenReader->AddValIdent(a_pCallback);
316 }
317 
318 //---------------------------------------------------------------------------------------------------------------------
319 /**
320  * @brief Get the default symbols used for the built in operators.
321  * @sa c_DefaultOprt
322  */
323 inline const QStringList &QmuParserBase::GetOprtDef()
324 {
325  return c_DefaultOprt;
326 }
327 
328 //---------------------------------------------------------------------------------------------------------------------
330 {
331  return m_Tokens;
332 }
333 
334 //---------------------------------------------------------------------------------------------------------------------
336 {
337  return m_Numbers;
338 }
339 
340 //---------------------------------------------------------------------------------------------------------------------
341 /**
342  * @brief Define the set of valid characters to be used in names of functions, variables, constants.
343  */
344 inline void QmuParserBase::DefineNameChars(const QString &a_szCharset)
345 {
346  m_sNameChars = a_szCharset;
347 }
348 
349 //---------------------------------------------------------------------------------------------------------------------
350 /**
351  * @brief Define the set of valid characters to be used in names of binary operators and postfix operators.
352  */
353 inline void QmuParserBase::DefineOprtChars(const QString &a_szCharset)
354 {
355  m_sOprtChars = a_szCharset;
356 }
357 
358 //---------------------------------------------------------------------------------------------------------------------
359 /**
360  * @brief Define the set of valid characters to be used in names of infix operators.
361  */
362 inline void QmuParserBase::DefineInfixOprtChars(const QString &a_szCharset)
363 {
364  m_sInfixOprtChars = a_szCharset;
365 }
366 
367 //---------------------------------------------------------------------------------------------------------------------
368 /**
369  * @brief Return a map containing the used variables only.
370  */
371 inline const varmap_type &QmuParserBase::GetVar() const
372 {
373  return m_VarDef;
374 }
375 
376 //---------------------------------------------------------------------------------------------------------------------
377 /**
378  * @brief Return a map containing all parser constants.
379  */
381 {
382  return m_ConstDef;
383 }
384 
385 //---------------------------------------------------------------------------------------------------------------------
386 /**
387  * @brief Return prototypes of all parser functions.
388  * @return #m_FunDef
389  * @sa FunProt
390  * @throw nothrow
391  *
392  * The return type is a map of the public type #funmap_type containing the prototype definitions for all numerical
393  * parser functions. String functions are not part of this map. The Prototype definition is encapsulated in objects
394  * of the class FunProt one per parser function each associated with function names via a map construct.
395  */
397 {
398  return m_FunDef;
399 }
400 
401 //---------------------------------------------------------------------------------------------------------------------
402 /**
403  * @brief Retrieve the formula.
404  */
405 inline const QString& QmuParserBase::GetExpr() const
406 {
407  return m_pTokenReader->GetExpr();
408 }
409 
410 //---------------------------------------------------------------------------------------------------------------------
411 /**
412  * @brief Query status of built in variables.
413  * @return #m_bBuiltInOp; true if built in operators are enabled.
414  * @throw nothrow
415  */
416 inline bool QmuParserBase::HasBuiltInOprt() const
417 {
418  return m_bBuiltInOp;
419 }
420 
421 //---------------------------------------------------------------------------------------------------------------------
422 /**
423  * @brief Return the number of results on the calculation stack.
424  *
425  * If the expression contains comma seperated subexpressions (i.e. "sin(y), x+y"). There mey be more than one return
426  * value. This function returns the number of available results.
427  */
428 // cppcheck-suppress unusedFunction
430 {
431  return m_nFinalResultIdx;
432 }
433 
434 //---------------------------------------------------------------------------------------------------------------------
435 /**
436  * @brief Calculate the result.
437  *
438  * A note on const correctness:
439  * I consider it important that Calc is a const function.
440  * Due to caching operations Calc changes only the state of internal variables with one exception
441  * m_UsedVar this is reset during string parsing and accessible from the outside. Instead of making
442  * Calc non const GetUsedVar is non const because it explicitely calls Eval() forcing this update.
443  *
444  * @pre A formula must be set.
445  * @pre Variables must have been set (if needed)
446  *
447  * @sa #m_pParseFormula
448  * @return The evaluation result
449  * @throw ParseException if no Formula is set or in case of any other error related to the formula.
450  */
451 inline qreal QmuParserBase::Eval() const
452 {
453  return (this->*m_pParseFormula)();
454 }
455 
456 } // namespace qmu
457 
458 #endif
A facet class used to change decimal and thousands separator.
virtual std::string do_grouping() const Q_DECL_OVERRIDE
virtual char_type do_thousands_sep() const Q_DECL_OVERRIDE
virtual char_type do_decimal_point() const Q_DECL_OVERRIDE
change_dec_sep(char_type cDecSep, char_type cThousandsSep=0, int nGroup=3)
Mathematical expressions parser (base parser engine).
Definition: qmuparserbase.h:66
void setDecimalPoint(const QChar &c)
void CheckOprt(const QString &a_sName, const QmuParserCallback &a_Callback, const QString &a_szCharSet) const
Check if a name contains invalid characters.
void Assign(const QmuParserBase &a_Parser)
Copy state of a parser object to this.
void AddCallback(const QString &a_strName, const QmuParserCallback &a_Callback, funmap_type &a_Storage, const QString &a_szCharSet)
Add a function or operator callback to the parser.
void CheckName(const QString &a_sName, const QString &a_szCharSet) const
Check if a name contains invalid characters.
QLocale getLocale() const
void InitTokenReader()
Initialize the token reader.
funmap_type m_OprtDef
Binary operator callbacks.
void SetArgSep(char_type cArgSep)
Set argument separator.
valbuf_type m_vStackBuffer
This is merely a buffer used for the stack in the cmd parsing routine.
void RemoveVar(const QString &a_strVarName)
Remove a variable from internal storage.
QmuParserByteCode m_vRPN
The Bytecode class.
static QString GetVersion(EParserVersionInfo eInfo=pviFULL)
Returns the version of muparser.
stringbuf_type m_vStringVarBuf
void DefineStrConst(const QString &a_strName, const QString &a_strVal)
Define a new string constant.
void DefineOprt(const QString &a_sName, fun_type2 a_pFun, unsigned a_iPrec=0, EOprtAssociativity a_eAssociativity=oaLEFT, bool a_bAllowOpt=false)
Define a binary operator.
void EnableOptimizer(bool a_bIsOn=true)
Enable or disable the formula optimization feature.
void setAllowSubexpressions(bool value)
EOprtAssociativity GetOprtAssociativity(const token_type &a_Tok) const
Get operator priority.
const valmap_type & GetConst() const
Return a map containing all parser constants.
void DefineOprtChars(const QString &a_szCharset)
Define the set of valid characters to be used in names of binary operators and postfix operators.
static const QStringList c_DefaultOprt
Identifiers for built in binary operators.
valmap_type m_ConstDef
user constants.
const QString & GetExpr() const
Retrieve the formula.
const funmap_type & GetFunDef() const
Return prototypes of all parser functions.
int GetOprtPrecedence(const token_type &a_Tok) const
Get operator priority.
QmuParserTokenReader token_reader_type
Typedef for the token reader.
QMap< int, QString > GetTokens() const
strmap_type m_StrVarDef
user defined string constants
funmap_type m_FunDef
Map of function names and pointers.
void Q_NORETURN Error(EErrorCodes a_iErrc, int a_iPos=-1, const QString &a_sTok=QString()) const
Create an error containing the parse error position.
funmap_type m_PostOprtDef
Postfix operator callbacks.
QVector< QString > stringbuf_type
Type for a vector of strings.
void ReInit() const
Reset parser to string parsing mode and clear internal buffers.
void DefineFun(const QString &a_strName, T a_pFun, bool a_bAllowOpt=true)
Define a parser function without arguments.
void DefineVar(const QString &a_sName, qreal *a_pVar)
Add a user defined variable.
void ApplyRemainingOprt(QStack< token_type > &a_stOpt, QStack< token_type > &a_stVal) const
Apply a binary operator.
virtual void InitConst()=0
const QString & ValidNameChars() const
Virtual function that defines the characters allowed in name identifiers.
QString m_sInfixOprtChars
Charset for infix operator tokens.
void StackDump(const QStack< token_type > &a_stVal, const QStack< token_type > &a_stOprt) const
Dump stack content.
static void EnableDebugDump(bool bDumpCmd, bool bDumpStack)
Enable the dumping of bytecode amd stack content on the console.
QChar GetArgSep() const
Get the argument separator character.
static const int s_MaxNumOpenMPThreads
Maximum number of threads spawned by OpenMP when using the bulk mode.
QChar getDecimalPoint() const
void EnableBuiltInOprt(bool a_bIsOn=true)
Enable or disable the built in binary operators.
void ClearFun()
Clear all functions.
QmuParserToken< qreal, QString > token_type
Type used for parser tokens.
int m_nIfElseCounter
Internal counter for keeping track of nested if-then-else clauses.
void DefineInfixOprtChars(const QString &a_szCharset)
Define the set of valid characters to be used in names of infix operators.
qreal ParseCmdCodeBulk(int nOffset, int nThreadID) const
Evaluate the RPN.
void ClearVar()
Clear all user defined variables.
QLocale m_locale
The locale used by the parser.
QMap< int, QString > m_Numbers
Keep all numbers what exist in formula.
void Init()
Initialize user defined functions.
QChar getThousandsSeparator() const
void ApplyFunc(QStack< token_type > &a_stOpt, QStack< token_type > &a_stVal, int iArgCount) const
Apply a function token.
void ClearConst()
Clear all user defined constants.
bool HasBuiltInOprt() const
Query status of built in variables.
funmap_type m_InfixOprtDef
unary infix operator.
static const QStringList & GetOprtDef()
Get the default symbols used for the built in operators.
bool m_bBuiltInOp
Flag that can be used for switching built in operators on and off.
void CreateRPN() const
static bool g_DbgDumpStack
const varmap_type & GetVar() const
Return a map containing the used variables only.
void ApplyBinOprt(QStack< token_type > &a_stOpt, QStack< token_type > &a_stVal) const
Performs the necessary steps to write code for the execution of binary operators into the bytecode.
void setThousandsSeparator(const QChar &c)
void DefinePostfixOprt(const QString &a_sFun, fun_type1 a_pFun, bool a_bAllowOpt=true)
Add a user defined operator.
const varmap_type & GetUsedVar() const
Return a map containing the used variables only.
virtual void InitFun()=0
stringbuf_type m_vStringBuf
String buffer, used for storing string function arguments.
token_type ApplyStrFunc(const token_type &a_FunTok, const QVector< token_type > &a_vArg) const
Execute a function that takes a single string argument.
void SetExpr(const QString &a_sExpr)
Set the formula.
QMap< int, QString > m_Tokens
Keep all tokens that we can translate.
void setLocale(const QLocale &value)
void SetVarFactory(facfun_type a_pFactory, void *pUserData=nullptr)
Set a function that can create variable pointer for unknown expression variables.
void ClearPostfixOprt()
Clear all user defined postfix operators.
qreal ParseCmdCode() const
Parse the command code.
void ResetLocale()
Resets the locale.
virtual void OnDetectVar(const QString &pExpr, int &nStart, int &nEnd)
const QString & ValidInfixOprtChars() const
Virtual function that defines the characters allowed in infix operator definitions.
virtual void InitCharSets()=0
const QString & ValidOprtChars() const
Virtual function that defines the characters allowed in operator definitions.
QString m_sOprtChars
Charset for postfix/ binary operator tokens.
QmuParserBase()
Constructor.
qreal Eval() const
Calculate the result.
std::unique_ptr< token_reader_type > m_pTokenReader
Managed pointer to the token reader object.
void AddValIdent(identfun_type a_pCallback)
Add a value parsing function.
ParseFunction m_pParseFormula
Pointer to the parser function.
QMap< int, QString > GetNumbers() const
varmap_type m_VarDef
user defind variables.
qreal ParseString() const
One of the two main parse functions.
QVector< qreal > valbuf_type
Type used for storing an array of values.
void ClearOprt()
Clear all user defined binary operators.
static bool g_DbgDumpCmdCode
void ApplyIfElse(QStack< token_type > &a_stOpt, QStack< token_type > &a_stVal) const
void ClearInfixOprt()
Clear the user defined Prefix operators.
void DefineConst(const QString &a_sName, qreal a_fVal)
Add a user defined constant.
QmuParserBase & operator=(const QmuParserBase &a_Parser)
Assignement operator.
virtual void InitOprt()=0
void DefineInfixOprt(const QString &a_sName, fun_type1 a_pFun, int a_iPrec=prINFIX, bool a_bAllowOpt=true)
Add a user defined operator.
int GetNumResults() const
Return the number of results on the calculation stack.
QString m_sNameChars
Charset for names.
qreal(QmuParserBase::* ParseFunction)() const
Typedef for the parse functions.
void DefineNameChars(const QString &a_szCharset)
Define the set of valid characters to be used in names of functions, variables, constants.
Bytecode implementation of the Math Parser.
Encapsulation of prototypes for a numerical parser function.
Token reader for the ParserBase class.
Namespace for mathematical applications.
std::map< QString, QmuParserCallback > funmap_type
Container for Callback objects.
std::map< QString, int > strmap_type
Type for assigning a string name to an index in the internal string table.
Definition: qmuparserdef.h:216
string_type::value_type char_type
The character type used by the parser.
Definition: qmuparserdef.h:202
EErrorCodes
Error codes.
qreal *(* facfun_type)(const QString &, void *)
Callback used for variable creation factory functions.
Definition: qmuparserdef.h:306
int(* identfun_type)(const QString &sExpr, int *nPos, qreal *fVal, const QLocale &locale, const QChar &decimal, const QChar &thousand)
Callback used for functions that identify values in a string.
Definition: qmuparserdef.h:302
std::map< QString, qreal > valmap_type
Type used for storing constants.
Definition: qmuparserdef.h:213
qreal(* fun_type2)(qreal, qreal)
Callback type used for functions with two arguments.
Definition: qmuparserdef.h:230
EParserVersionInfo
Definition: qmuparserdef.h:157
@ pviFULL
Definition: qmuparserdef.h:159
EOprtAssociativity
Parser operator precedence values.
Definition: qmuparserdef.h:165
@ oaLEFT
Definition: qmuparserdef.h:166
qreal(* fun_type1)(qreal)
Callback type used for functions with a single arguments.
Definition: qmuparserdef.h:227
@ prINFIX
Signs have a higher priority than ADD_SUB, but lower than power operator.
Definition: qmuparserdef.h:185
std::map< QString, qreal * > varmap_type
Type used for storing variables.
Definition: qmuparserdef.h:210
Definition of the parser bytecode class.
Definition of the parser callback class.
This file contains standard definitions used by the parser.
This file defines the error class used by the parser.
This file contains the parser token definition.
This file contains the parser token reader definition.