Evaluator.h

00001 #ifndef gridripper_math_expr_Evaluator_h
00002 #define gridripper_math_expr_Evaluator_h
00003 
00004 #include <gridripper/config.h>
00005 #include <gridripper/tvector.h>
00006 #include <gridripper/lang/IllegalArgumentException.h>
00007 #include "StkOp.h"
00008 #include "Expr.h"
00009 #include <string>
00010 #include <map>
00011 
00012 namespace gridripper { namespace math { namespace expr {
00013 
00014 using namespace std;
00015 
00022 class Evaluator {
00023 
00024 public:
00028     class Function {
00029     public:
00035         virtual GReal_t eval(GReal_t x) const =0;
00036 
00041         virtual const string& getName() const =0;
00042 
00047         virtual bool isConstant() const =0;
00048 
00050         virtual bool dependsOnVariables() const =0;
00051 
00053         virtual const string& getExprStr() const =0;
00054 
00055         virtual ~Function() { }
00056     };
00057 
00058 public:
00066     static Function* createFunction(const string& expr, const string& varname,
00067                 const tvector<StkOp*>& stkops
00068                     = *(const tvector<StkOp*>*)0,
00069                 const tvector<Function*>& depvars
00070                     = *(const tvector<Function*>*)0)
00071             throw(IllegalArgumentException&);
00072 
00079     static StkConst* addConst(const string& def, tvector<StkOp*> stkops)
00080             throw(IllegalArgumentException&);
00081 
00088     static void addConsts(const string& defs, tvector<StkOp*>& stkops)
00089             throw(IllegalArgumentException&);
00090 
00097     static int findStkOp(const tvector<StkOp*>& stkops,
00098                          const string& name);
00099 
00108     static Function* addVar(const string& def, const string& varname,
00109                             const tvector<StkOp*>& stkops,
00110                             tvector<Function*>& depvars)
00111             throw(IllegalArgumentException&);
00112 
00121     static void addVars(const string& defs, const string& varname,
00122                         tvector<StkOp*>& stkops,
00123                         tvector<Function*>& depvars)
00124             throw(IllegalArgumentException&);
00125 
00134     static void addConstsAndVars(const string& defs, const string& varname,
00135                                  tvector<StkOp*>& stkops,
00136                                  tvector<Function*>& depvars)
00137             throw(IllegalArgumentException&);
00138 
00145     static int findFunction(const tvector<Function*>& funcs,
00146                             const string& name);
00147 
00153     static GReal_t eval(const string& expr,
00154                         const tvector<StkOp*>& stkops
00155                             = *(const tvector<StkOp*>*)0)
00156         throw(IllegalArgumentException&);
00157 
00158 private:
00168     static void addConstsAndVars(const string& defs, const string& varname,
00169                                  tvector<StkOp*>& stkops,
00170                                  tvector<Function*>& depvars,
00171                                  bool varsonly)
00172             throw(IllegalArgumentException&);
00173 
00181     static void addConstOrVar(const string& def, const string& varname,
00182                               tvector<StkOp*>& stkops,
00183                               tvector<Function*>& depvars)
00184             throw(IllegalArgumentException&);
00185 
00186     static bool isDeclaration(const string& def);
00187 
00188     static void declareVars(const string& def, tvector<StkOp*>& stkops);
00189 };
00190 
00191 } } } /* namespace gridripper::math::expr */
00192 
00193 #endif /* gridripper_math_expr_Evaluator_h */

Generated on Wed Jun 17 18:46:47 2009 for GridRipper by  doxygen 1.5.6