NCBI C++ ToolKit
muParser.h
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /*
2  __________
3  _____ __ __\______ \_____ _______ ______ ____ _______
4  / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \
5  | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/
6  |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__|
7  \/ \/ \/ \/
8  Copyright (C) 2004-2008 Ingo Berg
9 
10  Permission is hereby granted, free of charge, to any person obtaining a copy of this
11  software and associated documentation files (the "Software"), to deal in the Software
12  without restriction, including without limitation the rights to use, copy, modify,
13  merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
14  permit persons to whom the Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in all copies or
17  substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
20  NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25 #ifndef MU_PARSER_H
26 #define MU_PARSER_H
27 
28 //--- Standard includes ------------------------------------------------------------------------
29 #include <vector>
30 #include <locale>
31 
32 //--- Parser includes --------------------------------------------------------------------------
33 #include "muParserBase.h"
34 
35 
36 /** \file
37  \brief Definition of the standard floating point parser.
38 */
39 
40 namespace mu
41 {
42  /** \brief Mathematical expressions parser.
43 
44  Standard implementation of the mathematical expressions parser.
45  Can be used as a reference implementation for subclassing the parser.
46 
47  <small>
48  (C) 2004-2008 Ingo Berg<br>
49  ingo_berg(at)gmx.de
50  </small>
51  */
52  class Parser : public ParserBase
53  {
54  public:
55 
56  Parser();
57 
58  virtual void InitCharSets();
59  virtual void InitFun();
60  virtual void InitConst();
61  virtual void InitOprt();
62 
63  void SetDecSep(char_type cDecSep);
64  void SetThousandsSep(char_type cThousandsSep);
65 
66  value_type Diff(value_type *a_Var,
67  value_type a_fPos,
68  value_type a_fEpsilon = 0.00074) const;
69 
70  private:
71 
72  /** \brief A facet class used to change decimal and thousands separator. */
73  template<class TChar>
74  class change_dec_sep : public std::numpunct<TChar>
75  {
76  public:
77 
78  explicit change_dec_sep(char_type cDecSep, char_type cThousandsSep = 0, int nGroup = 3)
79  :std::numpunct<TChar>()
80  ,m_nGroup(nGroup)
81  ,m_cDecPoint(cDecSep)
82  ,m_cThousandsSep(cThousandsSep)
83  {}
84 
85  protected:
86 
87  virtual char_type do_decimal_point() const
88  {
89  return m_cDecPoint;
90  }
91 
92  virtual char_type do_thousands_sep() const
93  {
94  return m_cThousandsSep;
95  }
96 
97  virtual std::string do_grouping() const
98  {
99  return std::string(1, m_nGroup);
100  }
101 
102  private:
103 
104  int m_nGroup;
107  };
108 
109  // Trigonometric functions
110  static value_type Sin(value_type);
111  static value_type Cos(value_type);
112  static value_type Tan(value_type);
113  // arcus functions
114  static value_type ASin(value_type);
115  static value_type ACos(value_type);
116  static value_type ATan(value_type);
117  // hyperbolic functions
118  static value_type Sinh(value_type);
119  static value_type Cosh(value_type);
120  static value_type Tanh(value_type);
121  // arcus hyperbolic functions
122  static value_type ASinh(value_type);
123  static value_type ACosh(value_type);
124  static value_type ATanh(value_type);
125  // Logarithm functions
126  static value_type Log2(value_type); // Logarithm Base 2
127  static value_type Log10(value_type); // Logarithm Base 10
128  static value_type Ln(value_type); // Logarithm Base e (natural logarithm)
129  // misc
130  static value_type Exp(value_type);
131  static value_type Abs(value_type);
132  static value_type Sqrt(value_type);
133  static value_type Rint(value_type);
134  static value_type Sign(value_type);
136 
137  // Prefix operators
138  // !!! Unary Minus is a MUST if you want to use negative signs !!!
140 
141  // Functions with variable number of arguments
142  static value_type Sum(const value_type*, int); // sum
143  static value_type Avg(const value_type*, int); // mean value
144  static value_type Min(const value_type*, int); // minimum
145  static value_type Max(const value_type*, int); // maximum
146 
147  static int IsVal(const char_type* a_szExpr, int *a_iPos, value_type *a_fVal);
148 
149  static std::locale s_locale; ///< The locale used by the parser
150  };
151 } // namespace mu
152 
153 #endif
154 
Mathematical expressions parser (base parser engine).
Definition: muParserBase.h:64
A facet class used to change decimal and thousands separator.
Definition: muParser.h:75
virtual char_type do_decimal_point() const
Definition: muParser.h:87
virtual char_type do_thousands_sep() const
Definition: muParser.h:92
virtual std::string do_grouping() const
Definition: muParser.h:97
change_dec_sep(char_type cDecSep, char_type cThousandsSep=0, int nGroup=3)
Definition: muParser.h:78
Mathematical expressions parser.
Definition: muParser.h:53
static int IsVal(const char_type *a_szExpr, int *a_iPos, value_type *a_fVal)
Default value recognition callback.
Definition: muParser.cpp:178
static value_type ATanh(value_type)
Definition: muParser.cpp:68
Parser()
Constructor.
Definition: muParser.cpp:216
static value_type Sign(value_type)
Definition: muParser.cpp:82
static value_type Tanh(value_type)
Definition: muParser.cpp:65
void SetThousandsSep(char_type cThousandsSep)
Sets the thousands operator.
Definition: muParser.cpp:314
static value_type Cosh(value_type)
Definition: muParser.cpp:64
static value_type ASin(value_type)
Definition: muParser.cpp:60
static value_type UnaryMinus(value_type)
Callback for the unary minus operator.
Definition: muParser.cpp:101
static value_type Sum(const value_type *, int)
Callback for adding multiple values.
Definition: muParser.cpp:111
value_type Diff(value_type *a_Var, value_type a_fPos, value_type a_fEpsilon=0.00074) const
Numerically differentiate with regard to a variable.
Definition: muParser.cpp:344
static value_type Avg(const value_type *, int)
Callback for averaging multiple values.
Definition: muParser.cpp:126
virtual void InitCharSets()
Define the character sets.
Definition: muParser.cpp:234
static value_type Sqrt(value_type)
Definition: muParser.cpp:80
void SetDecSep(char_type cDecSep)
Set the decimal separator.
Definition: muParser.cpp:300
static std::locale s_locale
The locale used by the parser.
Definition: muParser.h:149
static value_type Min(const value_type *, int)
Callback for determining the minimum value out of a vector.
Definition: muParser.cpp:142
virtual void InitOprt()
Initialize operators.
Definition: muParser.cpp:325
static value_type Sinh(value_type)
Definition: muParser.cpp:63
static value_type ACos(value_type)
Definition: muParser.cpp:61
static value_type Tan(value_type)
Definition: muParser.cpp:59
static value_type Abs(value_type)
Definition: muParser.cpp:79
static value_type Exp(value_type)
Definition: muParser.cpp:78
static value_type Rint(value_type)
Definition: muParser.cpp:81
static value_type ATan(value_type)
Definition: muParser.cpp:62
static value_type Log10(value_type)
Definition: muParser.cpp:73
static value_type Cos(value_type)
Definition: muParser.cpp:58
static value_type ASinh(value_type)
Definition: muParser.cpp:66
virtual void InitFun()
Initialize the default functions.
Definition: muParser.cpp:243
static value_type Ite(value_type, value_type, value_type)
Conditional (if then else).
Definition: muParser.cpp:91
virtual void InitConst()
Initialize constants.
Definition: muParser.cpp:286
static value_type Log2(value_type)
Definition: muParser.cpp:72
static value_type Max(const value_type *, int)
Callback for determining the maximum value out of a vector.
Definition: muParser.cpp:159
static value_type Ln(value_type)
Definition: muParser.cpp:74
static value_type Sin(value_type)
Definition: muParser.cpp:57
static value_type ACosh(value_type)
Definition: muParser.cpp:67
char TChar
Definition: interfaces.hpp:78
string
Definition: cgiapp.hpp:687
This file contains the class definition of the muparser engine.
Namespace for mathematical applications.
Definition: muParser.h:41
string_type::value_type char_type
The character type used by the parser.
Definition: muParserDef.h:246
double value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:228
static char * locale
Definition: pcregrep.c:149
Modified on Wed Dec 06 07:13:57 2023 by modify_doxy.py rev. 669887