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);
33 void setExpression(const QString& _expression) throw(int);
34 inline void setVariablesValue(const QHash<QString,double>& _varValues) { varValues = _varValues; }
35 inline void setVariableValue(const QString& var, double value) { varValues.insert(var,value); }
36 inline void setVariableMarkers(const QString& _markers) { varMarkers = _markers; }
39 double evaluate() throw(int);
42 QStringList expression;
43 QHash<QString,double> varValues;
44 QString varMarkers; // a sequence of symbols that are allowed to start a variable. $ is by default
45 QString opMarkers; // a sequence if symbols used as operators. +-*/ is the hard-coded default
46 QStringList fctMarkers;
48 void convert(const QString& _expression) throw(int);
49 QString convertRecur(const QString& _expression, int* offset) throw(int);
50 QString getNumber(const QString& _expression, int offset, int *size);
51 QString getVariable(const QString& _expression, int offset, int *size);
52 int getFunction(const QString& _expression, int offset, int *size);
53 bool checkAfterOp(const QString& _expression, int offset);
54 bool checkAfterPar(const QString& _expression, int offset);
56 double evalFunction(int indexFunc, double value);
60 #endif //__ARITHMETICEVALUATOR_H__