Seamly2D
Code documentation
qmuparser.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 QMUPARSER_H
23 #define QMUPARSER_H
24 
25 #include <qcompilerdetection.h>
26 #include <QString>
27 #include <QtGlobal>
28 #include <locale>
29 
30 #include "qmuparserbase.h"
31 
32 /**
33  * @file
34  * @brief Definition of the standard floating point parser.
35  */
36 
37 namespace qmu
38 {
39  /** @brief Mathematical expressions parser.
40  *
41  * Standard implementation of the mathematical expressions parser.
42  * Can be used as a reference implementation for subclassing the parser.
43  *
44  * <small>
45  * (C) 2011 Ingo Berg<br>
46  * muparser(at)gmx.de
47  * </small>
48  */
49  /* final */ class QmuParser : public QmuParserBase
50  {
51  public:
52  QmuParser();
53  virtual void InitCharSets() Q_DECL_OVERRIDE;
54  virtual void InitFun() Q_DECL_OVERRIDE;
55  virtual void InitConst() Q_DECL_OVERRIDE;
56  virtual void InitOprt() Q_DECL_OVERRIDE;
57  virtual void OnDetectVar(const QString &pExpr, int &nStart, int &nEnd) Q_DECL_OVERRIDE;
58  qreal Diff(qreal *a_Var, qreal a_fPos, qreal a_fEpsilon = 0) const;
59  protected:
60  static int IsVal(const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale,
61  const QChar &decimal, const QChar &thousand);
62  // hyperbolic functions
63  static qreal Sinh(qreal);
64  static qreal Cosh(qreal);
65  static qreal Tanh(qreal);
66  // inverse hyperbolic functions
67  static qreal ASinh(qreal);
68  static qreal ACosh(qreal);
69  static qreal ATanh(qreal);
70  // functions working with degrees
71  static qreal DegreeToRadian(qreal);
72  static qreal RadianToDegree(qreal);
73  static qreal SinD(qreal);
74  static qreal CosD(qreal);
75  static qreal TanD(qreal);
76  static qreal ASinD(qreal);
77  static qreal ACosD(qreal);
78  static qreal ATanD(qreal);
79 
80  // Logarithm functions
81  static qreal Log2(qreal); // Logarithm Base 2
82  static qreal Log10(qreal); // Logarithm Base 10
83  // misc
84  static qreal Abs(qreal);
85  static qreal Rint(qreal);
86  static qreal Sign(qreal);
87  static qreal FMod(qreal, qreal);
88  // Prefix operators
89  // !!! Unary Minus is a MUST if you want to use negative signs !!!
90  static qreal UnaryMinus(qreal v);
91  // Functions with variable number of arguments
92  static qreal Sum(const qreal*, int); // sum
93  static qreal Avg(const qreal*, int); // mean value
94  static qreal Min(const qreal*, int); // minimum
95  static qreal Max(const qreal*, int); // maximum
96  };
97 
98 //---------------------------------------------------------------------------------------------------------------------
99 /**
100  * @brief Callback for the unary minus operator.
101  * @param v The value to negate
102  * @return -v
103  */
104 inline qreal QmuParser::UnaryMinus(qreal v)
105 {
106  return -v;
107 }
108 
109 } // namespace qmu
110 
111 #endif // QMUPARSER_H
Mathematical expressions parser (base parser engine).
Definition: qmuparserbase.h:66
Mathematical expressions parser.
Definition: qmuparser.h:50
virtual void InitOprt() Q_DECL_OVERRIDE
Initialize operators.
Definition: qmuparser.cpp:396
static qreal Min(const qreal *, int)
Callback for determining the minimum value out of a vector.
Definition: qmuparser.cpp:233
static qreal Rint(qreal)
Definition: qmuparser.cpp:168
virtual void InitFun() Q_DECL_OVERRIDE
Initialize the default functions.
Definition: qmuparser.cpp:329
static qreal RadianToDegree(qreal)
Definition: qmuparser.cpp:54
static qreal Sum(const qreal *, int)
Callback for adding multiple values.
Definition: qmuparser.cpp:191
static qreal ACosD(qreal)
Definition: qmuparser.cpp:114
static qreal UnaryMinus(qreal v)
Callback for the unary minus operator.
Definition: qmuparser.h:104
static qreal Sign(qreal)
Definition: qmuparser.cpp:174
static qreal Tanh(qreal)
Definition: qmuparser.cpp:84
virtual void InitConst() Q_DECL_OVERRIDE
Initialize constants.
Definition: qmuparser.cpp:384
static qreal ACosh(qreal)
Definition: qmuparser.cpp:78
static qreal ATanh(qreal)
Definition: qmuparser.cpp:90
static qreal Sinh(qreal)
Definition: qmuparser.cpp:60
static qreal DegreeToRadian(qreal)
Definition: qmuparser.cpp:48
QmuParser()
Constructor.
Definition: qmuparser.cpp:300
static qreal ATanD(qreal)
Definition: qmuparser.cpp:126
static qreal Abs(qreal)
Definition: qmuparser.cpp:162
static qreal FMod(qreal, qreal)
Definition: qmuparser.cpp:180
static int IsVal(const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale, const QChar &decimal, const QChar &thousand)
Default value recognition callback.
Definition: qmuparser.cpp:277
static qreal SinD(qreal)
Definition: qmuparser.cpp:96
static qreal ASinh(qreal)
Definition: qmuparser.cpp:66
static qreal Avg(const qreal *, int)
Callback for averaging multiple values.
Definition: qmuparser.cpp:212
virtual void OnDetectVar(const QString &pExpr, int &nStart, int &nEnd) Q_DECL_OVERRIDE
Definition: qmuparser.cpp:402
static qreal CosD(qreal)
Definition: qmuparser.cpp:108
static qreal TanD(qreal)
Definition: qmuparser.cpp:120
qreal Diff(qreal *a_Var, qreal a_fPos, qreal a_fEpsilon=0) const
Numerically differentiate with regard to a variable.
Definition: qmuparser.cpp:444
static qreal Log2(qreal)
Definition: qmuparser.cpp:136
static qreal ASinD(qreal)
Definition: qmuparser.cpp:102
virtual void InitCharSets() Q_DECL_OVERRIDE
Define the character sets.
Definition: qmuparser.cpp:318
static qreal Max(const qreal *, int)
Callback for determining the maximum value out of a vector.
Definition: qmuparser.cpp:254
static qreal Cosh(qreal)
Definition: qmuparser.cpp:72
static qreal Log10(qreal)
Definition: qmuparser.cpp:149
Namespace for mathematical applications.
This file contains the class definition of the qmuparser engine.