MADNESS  version 0.9
muParser.h
Go to the documentation of 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 
40 namespace mu
41 {
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 
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;
105  char_type m_cDecPoint;
106  char_type m_cThousandsSep;
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 !!!
139  static value_type UnaryMinus(value_type);
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;
150  };
151 } // namespace mu
152 
153 #endif
154 
virtual void InitFun()
Initialize the default functions.
Definition: muParser.cpp:239
void SetThousandsSep(char_type cThousandsSep)
Sets the thousands operator.
Definition: muParser.cpp:310
::std::string string
Definition: gtest-port.h:872
const muChar_t muFloat_t a_fVal
Definition: muParserDLL.h:107
virtual void InitCharSets()
Define the character sets.
Definition: muParser.cpp:230
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:340
virtual void InitConst()
Initialize constants.
Definition: muParser.cpp:282
void SetDecSep(char_type cDecSep)
Set the decimal separator.
Definition: muParser.cpp:296
This file contains the class definition of the muparser engine.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:222
const muChar_t * a_szExpr
Definition: muParserDLL.h:78
Namespace for mathematical applications.
Definition: muParser.cpp:47
Parser()
Constructor.
Definition: muParser.cpp:212
string_type::value_type char_type
The character type used by the parser.
Definition: muParserDef.h:240
Mathematical expressions parser.
Definition: muParser.h:52
virtual void InitOprt()
Initialize operators.
Definition: muParser.cpp:321
Mathematical expressions parser (base parser engine).
Definition: muParserBase.h:63