File indexing completed on 2024-04-06 12:01:19
0001 #ifndef CommonTools_Utils_formulaEvaluatorBase_h
0002 #define CommonTools_Utils_formulaEvaluatorBase_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include <vector>
0025 #include <string>
0026
0027
0028
0029
0030
0031 namespace reco {
0032 namespace formula {
0033 std::vector<std::string> shiftAST(std::vector<std::string> child);
0034 class EvaluatorBase {
0035 public:
0036 enum class Precedence {
0037 kIdentity = 1,
0038 kComparison = 2,
0039 kPlusMinus = 3,
0040 kMultDiv = 4,
0041 kPower = 5,
0042 kFunction = 6,
0043 kParenthesis = 7,
0044 kUnaryMinusOperator = 8
0045 };
0046
0047 EvaluatorBase();
0048 EvaluatorBase(Precedence);
0049 virtual ~EvaluatorBase();
0050
0051
0052
0053
0054 virtual double evaluate(double const* iVariables, double const* iParameters) const = 0;
0055 virtual std::vector<std::string> abstractSyntaxTree() const = 0;
0056
0057 unsigned int precedence() const { return m_precedence; }
0058 void setPrecedenceToParenthesis() { m_precedence = static_cast<unsigned int>(Precedence::kParenthesis); }
0059
0060 EvaluatorBase(const EvaluatorBase&) = delete;
0061
0062 const EvaluatorBase& operator=(const EvaluatorBase&) = delete;
0063
0064 private:
0065
0066 unsigned int m_precedence;
0067 };
0068 }
0069 }
0070
0071 #endif