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 00026 #ifndef MU_PARSER_COMPLEX_H 00027 #define MU_PARSER_COMPLEX_H 00028 00029 #include "muParserBase.h" 00030 #include <vector> 00031 #include <complex> 00032 00038 namespace mu 00039 { 00045 class ParserComplex : private ParserBase 00046 { 00047 public: 00048 00049 typedef std::complex<float> complex_type; 00050 00051 ParserComplex(); 00052 00053 using ParserBase::SetExpr; 00054 00055 complex_type Eval(); 00056 00057 private: 00058 00059 // !! The unary Minus is a MUST, otherwise you cant use negative signs !! 00060 static value_type UnaryMinus(value_type); 00061 // binary operator callbacks 00062 static value_type Add(value_type v1, value_type v2); 00063 static value_type Sub(value_type v1, value_type v2); 00064 static value_type Mul(value_type v1, value_type v2); 00065 static value_type Div(value_type v1, value_type v2); 00066 00067 static value_type Sin(value_type); 00068 static value_type Cos(value_type); 00069 static value_type Tan(value_type); 00070 static value_type Sqrt(value_type); 00071 00072 static int IsVal(const char_type* a_szExpr, int *a_iPos, value_type *a_iVal); 00073 00074 static complex_type UnpackToComplex(double val); 00075 static double PackToDouble(const complex_type &val); 00076 00077 virtual void InitOprt(); 00078 virtual void InitCharSets(); 00079 virtual void InitFun(); 00080 virtual void InitConst(); 00081 }; 00082 } // namespace mu 00083 00084 #endif