CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
formulaBinaryOperatorEvaluator.h
Go to the documentation of this file.
1 #ifndef CommonTools_Utils_formulaBinaryOperatorEvaluator_h
2 #define CommonTools_Utils_formulaBinaryOperatorEvaluator_h
3 // -*- C++ -*-
4 //
5 // Package: CommonTools/Utils
6 // Class : formulaBinaryOperatorEvaluator
7 //
16 //
17 // Original Author: Christopher Jones
18 // Created: Wed, 23 Sep 2015 17:41:33 GMT
19 //
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
25 #include "formulaEvaluatorBase.h"
26 
27 // forward declarations
28 
29 namespace reco {
30  namespace formula {
32  public:
33  BinaryOperatorEvaluatorBase( std::shared_ptr<EvaluatorBase> iLHS,
34  std::shared_ptr<EvaluatorBase> iRHS,
35  Precedence iPrec) :
36  EvaluatorBase(iPrec),
37  m_lhs(iLHS),
38  m_rhs(iRHS) {}
39 
41  EvaluatorBase(iPrec) {}
42 
43  void swapLeftEvaluator(std::shared_ptr<EvaluatorBase>& iNew ) {
44  m_lhs.swap(iNew);
45  }
46 
47  void setLeftEvaluator(std::shared_ptr<EvaluatorBase> iOther) {
48  m_lhs = std::move(iOther);
49  }
50  void setRightEvaluator(std::shared_ptr<EvaluatorBase> iOther) {
51  m_rhs = std::move(iOther);
52  }
53 
54  EvaluatorBase const* lhs() const { return m_lhs.get(); }
55  EvaluatorBase const* rhs() const { return m_rhs.get(); }
56 
57  private:
58  std::shared_ptr<EvaluatorBase> m_lhs;
59  std::shared_ptr<EvaluatorBase> m_rhs;
60  };
61 
62  template<typename Op>
64  {
65 
66  public:
67  BinaryOperatorEvaluator(std::shared_ptr<EvaluatorBase> iLHS,
68  std::shared_ptr<EvaluatorBase> iRHS,
69  Precedence iPrec):
70  BinaryOperatorEvaluatorBase(std::move(iLHS), std::move(iRHS), iPrec) {}
71 
74 
75  // ---------- const member functions ---------------------
76  virtual double evaluate(double const* iVariables, double const* iParameters) const override final {
77  return m_operator(lhs()->evaluate(iVariables,iParameters),rhs()->evaluate(iVariables,iParameters));
78  }
79 
80  private:
82 
84 
85  // ---------- member data --------------------------------
87 
88  };
89  }
90 }
91 
92 
93 #endif
BinaryOperatorEvaluatorBase(std::shared_ptr< EvaluatorBase > iLHS, std::shared_ptr< EvaluatorBase > iRHS, Precedence iPrec)
virtual double evaluate(double const *iVariables, double const *iParameters) const overridefinal
void setRightEvaluator(std::shared_ptr< EvaluatorBase > iOther)
void swapLeftEvaluator(std::shared_ptr< EvaluatorBase > &iNew)
const BinaryOperatorEvaluator & operator=(const BinaryOperatorEvaluator &)=delete
def move
Definition: eostools.py:510
void setLeftEvaluator(std::shared_ptr< EvaluatorBase > iOther)
BinaryOperatorEvaluator(std::shared_ptr< EvaluatorBase > iLHS, std::shared_ptr< EvaluatorBase > iRHS, Precedence iPrec)