muParser: muParser.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Examples

# muParser.h

Go to the documentation of this file.

    00001 /*
    00002                  __________
    00003     _____   __ __\______   \_____  _______  ______  ____ _______
    00004    /     \ |  |  \|     ___/\__  \ \_  __ \/  ___/_/ __ \\_  __ \
    00005   |  Y Y  \|  |  /|    |     / __ \_|  | \/\___ \ \  ___/ |  | \/
    00006   |__|_|  /|____/ |____|    (____  /|__|  /____  > \___  >|__|
    00007         \/                       \/            \/      \/
    00008   Copyright (C) 2004-2008 Ingo Berg
    00009
    00010   Permission is hereby granted, free of charge, to any person obtaining a copy of this
    00011   software and associated documentation files (the "Software"), to deal in the Software
    00012   without restriction, including without limitation the rights to use, copy, modify,
    00013   merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
    00014   permit persons to whom the Software is furnished to do so, subject to the following conditions:
    00015
    00016   The above copyright notice and this permission notice shall be included in all copies or
    00017   substantial portions of the Software.
    00018
    00019   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
    00020   NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    00021   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
    00022   DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00023   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    00024 */
    00025 #ifndef MU_PARSER_H
    00026 #define MU_PARSER_H
    00027
    00028 //--- Standard includes ------------------------------------------------------------------------
    00029 #include <vector>
    00030 #include <locale>
    00031
    00032 //--- Parser includes --------------------------------------------------------------------------
    00033 #include "muParserBase.h"
    00034
    00035
    00040 namespace mu
    00041 {
    00052   class Parser : public ParserBase
    00053   {
    00054   public:
    00055
    00056     Parser();
    00057
    00058     virtual void InitCharSets();
    00059     virtual void InitFun();
    00060     virtual void InitConst();
    00061     virtual void InitOprt();
    00062
    00063     void SetDecSep(char_type cDecSep);
    00064     void SetThousandsSep(char_type cThousandsSep);
    00065
    00066     value_type Diff(value_type *a_Var,
    00067                     value_type a_fPos,
    00068                     value_type a_fEpsilon = 0.00074) const;
    00069
    00070   private:
    00071
    00073     template<class TChar>
    00074     class change_dec_sep : public std::numpunct<TChar>
    00075     {
    00076     public:
    00077
    00078       explicit change_dec_sep(char_type cDecSep, char_type cThousandsSep = 0, int nGroup = 3)
    00079         :std::numpunct<TChar>()
    00080         ,m_cDecPoint(cDecSep)
    00081         ,m_cThousandsSep(cThousandsSep)
    00082         ,m_nGroup(nGroup)
    00083       {}
    00084
    00085     protected:
    00086
    00087       virtual char_type do_decimal_point() const
    00088       {
    00089         return m_cDecPoint;
    00090       }
    00091
    00092       virtual char_type do_thousands_sep() const
    00093       {
    00094         return m_cThousandsSep;
    00095       }
    00096
    00097       virtual std::string do_grouping() const
    00098       {
    00099         return std::string(1, m_nGroup);
    00100       }
    00101
    00102     private:
    00103
    00104       int m_nGroup;
    00105       char_type m_cDecPoint;
    00106       char_type m_cThousandsSep;
    00107     };
    00108
    00109     // Trigonometric functions
    00110     static value_type  Sin(value_type);
    00111     static value_type  Cos(value_type);
    00112     static value_type  Tan(value_type);
    00113     // arcus functions
    00114     static value_type  ASin(value_type);
    00115     static value_type  ACos(value_type);
    00116     static value_type  ATan(value_type);
    00117     // hyperbolic functions
    00118     static value_type  Sinh(value_type);
    00119     static value_type  Cosh(value_type);
    00120     static value_type  Tanh(value_type);
    00121     // arcus hyperbolic functions
    00122     static value_type  ASinh(value_type);
    00123     static value_type  ACosh(value_type);
    00124     static value_type  ATanh(value_type);
    00125     // Logarithm functions
    00126     static value_type  Log2(value_type);  // Logarithm Base 2
    00127     static value_type  Log10(value_type); // Logarithm Base 10
    00128     static value_type  Ln(value_type);    // Logarithm Base e (natural logarithm)
    00129     // misc
    00130     static value_type  Exp(value_type);
    00131     static value_type  Abs(value_type);
    00132     static value_type  Sqrt(value_type);
    00133     static value_type  Rint(value_type);
    00134     static value_type  Sign(value_type);
    00135     static value_type  Ite(value_type, value_type, value_type);
    00136
    00137     // Prefix operators
    00138     // !!! Unary Minus is a MUST if you want to use negative signs !!!
    00139     static value_type  UnaryMinus(value_type);
    00140
    00141     // Functions with variable number of arguments
    00142     static value_type Sum(const value_type*, int);  // sum
    00143     static value_type Avg(const value_type*, int);  // mean value
    00144     static value_type Min(const value_type*, int);  // minimum
    00145     static value_type Max(const value_type*, int);  // maximum
    00146
    00147     static int IsVal(const char_type* a_szExpr, int *a_iPos, value_type *a_fVal);
    00148
    00149     static std::locale s_locale;
    00150   };
    00151 } // namespace mu
    00152
    00153 #endif
    00154