1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#ifndef CommonTools_Utils_formulaEvaluatorBase_h
#define CommonTools_Utils_formulaEvaluatorBase_h
// -*- C++ -*-
//
// Package: CommonTools/Utils
// Class : reco::formula::EvaluatorBase
//
/**\class reco::formula::EvaluatorBase formulaEvaluatorBase.h "formulaEvaluatorBase.h"
Description: Base class for formula evaluators
Usage:
Used as an internal detail on the reco::FormulaEvalutor class.
Base class for all objects used in the abstract evaluation tree where one node
corresponds to one syntax element of the formula.
*/
//
// Original Author: Christopher Jones
// Created: Wed, 23 Sep 2015 16:26:00 GMT
//
// system include files
#include <vector>
#include <string>
// user include files
// forward declarations
namespace reco {
namespace formula {
std::vector<std::string> shiftAST(std::vector<std::string> child);
class EvaluatorBase {
public:
enum class Precedence {
kIdentity = 1,
kComparison = 2,
kPlusMinus = 3,
kMultDiv = 4,
kPower = 5,
kFunction = 6, //default
kParenthesis = 7,
kUnaryMinusOperator = 8
};
EvaluatorBase();
EvaluatorBase(Precedence);
virtual ~EvaluatorBase();
// ---------- const member functions ---------------------
//inputs are considered to be 'arrays' which have already been validated to
// be of the appropriate length
virtual double evaluate(double const* iVariables, double const* iParameters) const = 0;
virtual std::vector<std::string> abstractSyntaxTree() const = 0;
unsigned int precedence() const { return m_precedence; }
void setPrecedenceToParenthesis() { m_precedence = static_cast<unsigned int>(Precedence::kParenthesis); }
EvaluatorBase(const EvaluatorBase&) = delete;
const EvaluatorBase& operator=(const EvaluatorBase&) = delete;
private:
// ---------- member data --------------------------------
unsigned int m_precedence;
};
} // namespace formula
} // namespace reco
#endif
|