CMS 3D CMS Logo

Expression.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_Utilities_Expression_h
2 #define PhysicsTools_Utilities_Expression_h
4 #include <ostream>
5 #include <memory>
6 
7 namespace funct {
8 
9  struct AbsExpression {
10  virtual ~AbsExpression() {}
11  virtual double operator()() const = 0;
12  virtual AbsExpression* clone() const = 0;
13  virtual std::ostream& print(std::ostream& cout) const = 0;
14  };
15 
16  template <typename F>
17  struct ExpressionT : public AbsExpression {
18  inline ExpressionT(const F& f) : _f(f) {}
19  ~ExpressionT() override {}
20  double operator()() const override { return _f(); }
21  AbsExpression* clone() const override { return new ExpressionT<F>(_f); }
22  std::ostream& print(std::ostream& cout) const override { return cout << _f; }
23 
24  private:
25  F _f;
26  };
27 
28  struct Expression {
29  inline Expression() {}
30  template <typename F>
31  inline Expression(const F& f) : _f(new ExpressionT<F>(f)) {}
32  inline Expression(const Expression& e) : _f(e._f->clone()) {}
33  inline Expression& operator=(const Expression& e) {
34  _f.reset(e._f->clone());
35  return *this;
36  }
37  inline double operator()() const { return (*_f)(); }
38  inline std::ostream& print(std::ostream& cout) const { return _f->print(cout); }
39 
40  private:
41  std::unique_ptr<AbsExpression> _f;
42  };
43 
44  inline std::ostream& operator<<(std::ostream& cout, const Expression& e) {
45  e.print(cout);
46  return cout;
47  }
48 
50  virtual ~AbsFunctExpression() {}
51  virtual double operator()(double x) const = 0;
52  virtual AbsFunctExpression* clone() const = 0;
53  };
54 
55  template <typename F>
57  inline FunctExpressionT(const F& f) : _f(f) {}
58  ~FunctExpressionT() override {}
59  double operator()(double x) const override { return _f(x); }
60  AbsFunctExpression* clone() const override { return new FunctExpressionT<F>(_f); }
61 
62  private:
63  F _f;
64  };
65 
66  struct FunctExpression {
67  inline FunctExpression() {}
68  template <typename F>
69  inline FunctExpression(const F& f) : _f(new FunctExpressionT<F>(f)) {}
70  inline FunctExpression(const FunctExpression& e) : _f(e._f->clone()) {}
72  _f.reset(e._f->clone());
73  return *this;
74  }
75  inline double operator()(double x) const { return (*_f)(x); }
76 
77  private:
78  std::unique_ptr<AbsFunctExpression> _f;
79  };
80 
81 } // namespace funct
82 
83 #endif
FunctionsIO.h
funct::FunctExpression::operator()
double operator()(double x) const
Definition: Expression.h:75
funct::AbsFunctExpression::operator()
virtual double operator()(double x) const =0
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
funct::ExpressionT::clone
AbsExpression * clone() const override
Definition: Expression.h:21
funct::ExpressionT
Definition: Expression.h:17
gather_cfg.cout
cout
Definition: gather_cfg.py:144
funct::FunctExpression
Definition: Expression.h:66
funct::AbsFunctExpression::clone
virtual AbsFunctExpression * clone() const =0
funct::AbsExpression::clone
virtual AbsExpression * clone() const =0
funct::Expression::operator=
Expression & operator=(const Expression &e)
Definition: Expression.h:33
funct::operator<<
std::ostream & operator<<(std::ostream &cout, const Expression &e)
Definition: Expression.h:44
funct::Expression::print
std::ostream & print(std::ostream &cout) const
Definition: Expression.h:38
F
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
funct::FunctExpressionT::clone
AbsFunctExpression * clone() const override
Definition: Expression.h:60
funct::ExpressionT::operator()
double operator()() const override
Definition: Expression.h:20
funct::ExpressionT::print
std::ostream & print(std::ostream &cout) const override
Definition: Expression.h:22
funct::FunctExpression::FunctExpression
FunctExpression()
Definition: Expression.h:67
funct::FunctExpressionT
Definition: Expression.h:56
funct::ExpressionT::ExpressionT
ExpressionT(const F &f)
Definition: Expression.h:18
funct::AbsExpression
Definition: Expression.h:9
funct::AbsExpression::~AbsExpression
virtual ~AbsExpression()
Definition: Expression.h:10
funct::Expression::Expression
Expression()
Definition: Expression.h:29
funct::ExpressionT::_f
F _f
Definition: Expression.h:25
funct::Expression::_f
std::unique_ptr< AbsExpression > _f
Definition: Expression.h:41
funct::ExpressionT::~ExpressionT
~ExpressionT() override
Definition: Expression.h:19
funct::FunctExpressionT::_f
F _f
Definition: Expression.h:63
funct::Expression::Expression
Expression(const Expression &e)
Definition: Expression.h:32
funct::AbsExpression::print
virtual std::ostream & print(std::ostream &cout) const =0
funct::FunctExpression::FunctExpression
FunctExpression(const FunctExpression &e)
Definition: Expression.h:70
funct::FunctExpression::FunctExpression
FunctExpression(const F &f)
Definition: Expression.h:69
funct::AbsFunctExpression
Definition: Expression.h:49
funct::FunctExpression::_f
std::unique_ptr< AbsFunctExpression > _f
Definition: Expression.h:78
funct::Expression
Definition: Expression.h:28
funct::Expression::operator()
double operator()() const
Definition: Expression.h:37
funct::AbsFunctExpression::~AbsFunctExpression
virtual ~AbsFunctExpression()
Definition: Expression.h:50
funct::FunctExpressionT::~FunctExpressionT
~FunctExpressionT() override
Definition: Expression.h:58
funct::FunctExpressionT::FunctExpressionT
FunctExpressionT(const F &f)
Definition: Expression.h:57
funct::Expression::Expression
Expression(const F &f)
Definition: Expression.h:31
funct::AbsExpression::operator()
virtual double operator()() const =0
funct
Definition: Abs.h:5
funct::FunctExpression::operator=
FunctExpression & operator=(const FunctExpression &e)
Definition: Expression.h:71
funct::FunctExpressionT::operator()
double operator()(double x) const override
Definition: Expression.h:59
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37