bpp-core3  3.0.0
FunctionOperator.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_NUMERIC_FUNCTION_OPERATORS_FUNCTIONOPERATOR_H
6 #define BPP_NUMERIC_FUNCTION_OPERATORS_FUNCTIONOPERATOR_H
7 
8 #include <memory>
9 
10 #include "../Functions.h"
11 
12 namespace bpp
13 {
20 template<class F>
22  public Operator
23 {
24 private:
25  F& func_;
26 
27  std::string name_;
28 
29  double getValue_(std::true_type) const
30  {
31  return func_.getValue();
32  }
33 
34  double getValue_(std::false_type) const
35  {
36  return 0;
37  }
38 
39  double getFirstOrderDerivative_(const std::string& variable, std::true_type) const
40  {
41  return func_.getFirstOrderDerivative(variable);
42  }
43 
44  double getFirstOrderDerivative_(const std::string& variable, std::false_type) const
45  {
46  return 0;
47  }
48 
49  double getSecondOrderDerivative_(const std::string& variable, std::true_type) const
50  {
51  return func_.getSecondOrderDerivative(variable);
52  }
53 
54  double getSecondOrderDerivative_(const std::string& variable, std::false_type) const
55  {
56  return 0;
57  }
58 
59 public:
60  FunctionOperator(F& func, std::string name) :
61  func_(func), name_(name)
62  {}
63 
65  {
66  return new FunctionOperator(*this);
67  }
68 
69  double getValue() const
70  {
71  return getValue_(std::integral_constant<bool, std::is_base_of<FunctionInterface, F>::value>{});
72  }
73 
74  double getFirstOrderDerivative(const std::string& variable) const
75  {
76  return getFirstOrderDerivative_(variable, std::integral_constant<bool, std::is_base_of<FirstOrderDerivable, F>::value>{});
77  }
78 
79  double getSecondOrderDerivative(const std::string& variable) const
80  {
81  return getSecondOrderDerivative_(variable, std::integral_constant<bool, std::is_base_of<SecondOrderDerivable, F>::value>{});
82  }
83 
84  std::string getName() const
85  {
86  return name_;
87  }
88 
89  std::string output() const
90  {
91  return name_;
92  }
93 };
94 } // end of namespace bpp.
95 #endif // BPP_NUMERIC_FUNCTION_OPERATORS_FUNCTIONOPERATOR_H
double getFirstOrderDerivative_(const std::string &variable, std::true_type) const
double getSecondOrderDerivative_(const std::string &variable, std::false_type) const
Implements a double operator (ie leaf in the computation tree) where value comes from a function...
double getFirstOrderDerivative(const std::string &variable) const
double getSecondOrderDerivative_(const std::string &variable, std::true_type) const
double getSecondOrderDerivative(const std::string &variable) const
std::string output() const
double getValue_(std::true_type) const
FunctionOperator(F &func, std::string name)
double getValue_(std::false_type) const
FunctionOperator * clone() const
Create a copy of this object and send a pointer to it.
std::string getName() const
double getValue() const
double getFirstOrderDerivative_(const std::string &variable, std::false_type) const
Interface of operator for numerical computation.
Definition: Operator.h:19