src/thirdparty/mathexpr/mathexpr_c.h

Go to the documentation of this file.
00001 /*
00002 
00003 mathexpr_c.h version 2.0
00004 
00005 Copyright Yann OLLIVIER 1997-2000
00006   
00007 This software may be freely distributed as is, including this whole notice.
00008 
00009 It may be modified, but any modification should include this whole 
00010 notice as is and a description of the changes made.
00011 
00012 This software may not be sold.
00013 
00014 This software or any modified version of it may be freely used in free
00015 programs. The program should include a copy of this whole notice.
00016 If you want to use it in a program you sell, contact me
00017 
00018 This software comes with absolutely no warranty.
00019 
00020 */
00021 
00022 #ifndef __MATHEXPR_C_H
00023 #define __MATHEXPR_C_H
00024 
00025 #include<string.h>
00026 #include<stdio.h>
00027 #include<stdlib.h>
00028 #include<complex>
00029 #include<float.h>
00030 
00031 #ifndef __STD_COMPLEX_
00032 #define double_complex std::complex<double>
00033 double_complex tan(double_complex);
00034 double_complex acos(double_complex);
00035 double_complex asin(double_complex);
00036 double_complex atan(double_complex);
00037 #endif
00038 
00039 // Compatibility with long double-typed functions
00040 #define atanl atan
00041 #define asinl asin
00042 #define acosl acos
00043 #define expl exp
00044 #define logl log
00045 #define powl pow
00046 #define pow10l(x) pow(10,x)
00047 #define fabsl fabs
00048 #define cosl cos
00049 #define sinl sin
00050 #define tanl tan
00051 #define fmodl fmod
00052 #define sqrtl sqrt
00053 
00054 
00055 // Warning : everything will fail with strings longer than 32767 chars
00056 
00057 const double_complex ErrVal=double_complex(DBL_MAX,0);
00058 
00059 //Class definitions for operations
00060 
00061 class CVar{
00062 public:
00063     char*name;double_complex*pval;
00064     CVar(const CVar&);
00065     CVar(const char*,double_complex*);
00066     ~CVar();
00067     friend int operator==(const CVar&,const CVar&);
00068 };
00069 
00070 typedef CVar* PCVar;
00071 
00072 enum COperator{ErrOp,Juxt,Num,Var,Add,Sub,Opp,Mult,Div,Pow,Sqrt,
00073                NthRoot,Real,Imag,Conj,Abs,Arg,Sin,Cos,Tg,Ln,Exp,Acos,Asin,Atan,E10,Fun};
00074 
00075 typedef void ((*pfoncld)(double_complex*&));
00076 
00077 class COperation;
00078 typedef COperation* PCOperation;
00079 class CFunction;
00080 typedef CFunction* PCFunction;
00081 
00082 class COperation{
00083     pfoncld*pinstr;double_complex**pvals;double_complex*ppile;CFunction**pfuncpile;
00084     mutable signed char containfuncflag;
00085     void BuildCode();
00086     void Destroy();
00087 public:
00088     COperator op;
00089     PCOperation mmb1,mmb2;
00090     double_complex ValC;const CVar* pvar;double_complex*pvarval;
00091     CFunction* pfunc;
00092     COperation();
00093     COperation(const COperation&);
00094     COperation(double);COperation(double_complex);
00095     COperation(const CVar&);
00096     COperation(char*sp,int nvarp=0,PCVar*ppvarp=NULL,int nfuncp=0,PCFunction*ppfuncp=NULL);
00097     ~COperation();
00098     double_complex Val() const;
00099     signed char ContainVar(const CVar&) const;
00100     signed char ContainFunc(const CFunction&) const;
00101     signed char ContainFuncNoRec(const CFunction&) const; // No recursive test on subfunctions
00102     COperation NthMember(int) const;int NMembers() const;
00103     signed char HasError(const COperation* =NULL) const;
00104     COperation& operator=(const COperation&);
00105     friend int operator==(const COperation&,const double);
00106     friend int operator==(const COperation&,const double_complex);
00107     friend int operator==(const COperation&,const COperation&);
00108     friend int operator!=(const COperation&,const COperation&);
00109     COperation operator+() const;COperation operator-() const;
00110     friend COperation operator,(const COperation&,const COperation&);
00111     friend COperation operator+(const COperation&,const COperation&);
00112     friend COperation operator-(const COperation&,const COperation&);
00113     friend COperation operator*(const COperation&,const COperation&);
00114     friend COperation operator/(const COperation&,const COperation&);
00115     friend COperation operator^(const COperation&,const COperation&);  // Caution: wrong associativity and precedence
00116     friend COperation real(const COperation&);
00117     friend COperation imag(const COperation&);
00118     friend COperation conj(const COperation&);
00119     friend COperation arg(const COperation&);
00120     friend COperation sqrt(const COperation&);
00121     friend COperation abs(const COperation&);
00122     friend COperation sin(const COperation&);
00123     friend COperation cos(const COperation&);
00124     friend COperation tan(const COperation&);
00125     friend COperation log(const COperation&);
00126     friend COperation exp(const COperation&);
00127     friend COperation acos(const COperation&);
00128     friend COperation asin(const COperation&);
00129     friend COperation atan(const COperation&);
00130     friend COperation ApplyOperator(int,COperation**,COperation (*)(const COperation&,const COperation&));
00131     COperation Diff(const CVar&) const; //  Differentiate w.r.t a variable
00132     COperation DiffConj(const CVar&) const; // This one is d / d conj(z)
00133     char* Expr() const;
00134     COperation Substitute(const CVar&,const COperation&) const;
00135 };
00136 
00137 class CFunction{
00138     double_complex*buf;
00139 public:
00140     signed char type;
00141     double_complex ((*pfuncval)(double_complex));
00142     COperation op;int nvars;CVar** ppvar;
00143     char*name;
00144     CFunction();
00145     CFunction(double_complex ((*pfuncvalp)(double_complex)));
00146     CFunction(const COperation& opp, CVar* pvarp);
00147     CFunction(const COperation& opp, int nvarsp, CVar**ppvarp);
00148     CFunction(const CFunction&);
00149     ~CFunction();
00150     CFunction& operator=(const CFunction&);
00151     void SetName(const char*s);
00152     double_complex Val(double_complex) const;
00153     double_complex Val(double_complex*) const;
00154     friend int operator==(const CFunction&,const CFunction&);
00155     COperation operator()(const COperation&);
00156 };
00157 
00158 char* PrettyPrint(double_complex);
00159 
00160 char* MidStr(const char*s,int i1,int i2);
00161 char* CopyStr(const char*s);
00162 char* InsStr(const char*s,int n,const char c);
00163 signed char EqStr(const char*s,const char*s2);
00164 signed char CompStr(const char*s,int n,const char*s2);
00165 char* DelStr(const char*s,int n);
00166 
00167 #endif

Generated on Sat Mar 15 22:55:58 2008 for Armagetron Advanced by  doxygen 1.5.4