1 /*-==============================================================-
3 file : ArithmeticEvaluator.h
5 creation date : 19/05/2015
7 author : S. Domas (sdomas@univ-fcomte.fr)
11 supp. infos : saved in UTF-8 [éè]
13 -==============================================================-*/
14 #ifndef __ARITHMETICEVALUATOR_H__
15 #define __ARITHMETICEVALUATOR_H__
26 class ArithmeticEvaluator {
30 ArithmeticEvaluator();
31 ArithmeticEvaluator(const QString& _expression) throw(int);
34 inline QList<QString> getVariableNames() { return varNames; }
37 void setExpression(const QString& _expression) throw(int);
38 void setVariablesValue(const QHash<QString,double>& _varValues);
39 inline void setVariableValue(const QString& var, double value) { varValues.insert(var,value); }
40 inline void setVariableMarkers(const QString& _markers) { varMarkers = _markers; }
43 double evaluate() throw(int);
44 inline QString getError() { return errorMessage; }
47 QStringList expression;
48 QList<QString> varNames; // the names of variables that ARE in the expression
49 QHash<QString,double> varValues;
50 QString varMarkers; // a sequence of symbols that are allowed to start a variable. $ is by default
51 QString opMarkers; // a sequence if symbols used as operators. +-*/ is the hard-coded default
52 QStringList fctMarkers;
54 void convert(const QString& _expression) throw(int);
55 QString convertRecur(const QString& _expression, int* offset) throw(int);
56 QString getNumber(const QString& _expression, int offset, int *size);
57 QString getVariable(const QString& _expression, int offset, int *size);
58 int getFunction(const QString& _expression, int offset, int *size);
59 bool checkAfterOp(const QString& _expression, int offset);
60 bool checkAfterPar(const QString& _expression, int offset);
62 double evalFunction(int indexFunc, double value);
64 void setVariableNames(const QString &_expression);
70 #endif //__ARITHMETICEVALUATOR_H__