00001
00002
00003
00004
00005 #ifndef XMLTOOLS_EVALUATOR_H
00006 #define XMLTOOLS_EVALUATOR_H
00007
00008 namespace XmlTools {
00009
00027 class Evaluator {
00028 public:
00029
00040 enum {
00041 OK,
00042 WARNING_EXISTING_VARIABLE,
00043 WARNING_EXISTING_FUNCTION,
00044 WARNING_BLANK_STRING,
00045 ERROR_NOT_A_NAME,
00046 ERROR_SYNTAX_ERROR,
00047 ERROR_UNPAIRED_PARENTHESIS,
00048 ERROR_UNEXPECTED_SYMBOL,
00049 ERROR_UNKNOWN_VARIABLE,
00050 ERROR_UNKNOWN_FUNCTION,
00051 ERROR_EMPTY_PARAMETER,
00052 ERROR_CALCULATION_ERROR
00053 };
00054
00058 Evaluator();
00059
00063 ~Evaluator();
00064
00077 double evaluate(const char * expression);
00078
00082 int status() const;
00083
00087 int error_position() const;
00088
00092 void print_error() const;
00093
00102 void setVariable(const char * name, double value);
00103
00113 void setVariable(const char * name, const char * expression);
00114
00123 void setFunction(const char * name, double (*fun)());
00124
00133 void setFunction(const char * name, double (*fun)(double));
00134
00143 void setFunction(const char * name, double (*fun)(double,double));
00144
00153 void setFunction(const char * name, double (*fun)(double,double,double));
00154
00163 void setFunction(const char * name,
00164 double (*fun)(double,double,double,double));
00165
00174 void setFunction(const char * name,
00175 double (*fun)(double,double,double,double,double));
00176
00183 bool findVariable(const char * name) const;
00184
00192 bool findFunction(const char * name, int npar) const;
00193
00199 void removeVariable(const char * name);
00200
00207 void removeFunction(const char * name, int npar);
00208
00212 void clear();
00213
00217 void setStdMath();
00218
00245 void setSystemOfUnits(double meter = 1.0,
00246 double kilogram = 1.0,
00247 double second = 1.0,
00248 double ampere = 1.0,
00249 double kelvin = 1.0,
00250 double mole = 1.0,
00251 double candela = 1.0);
00252
00253 private:
00254 void * p;
00255 Evaluator(const Evaluator &);
00256 Evaluator & operator=(const Evaluator &);
00257 };
00258
00259 }
00260
00261 #endif