File indexing completed on 2024-04-06 12:01:19
0001 #ifndef CommonTools_Utils_formulaFunctionOneArgEvaluator_h
0002 #define CommonTools_Utils_formulaFunctionOneArgEvaluator_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <memory>
0023 #include <functional>
0024
0025
0026 #include "formulaEvaluatorBase.h"
0027
0028
0029
0030 namespace reco {
0031 namespace formula {
0032 class FunctionOneArgEvaluator : public EvaluatorBase {
0033 public:
0034 template <typename T>
0035 explicit FunctionOneArgEvaluator(std::shared_ptr<EvaluatorBase> iArg, T iFunc)
0036 : m_arg(std::move(iArg)), m_function(iFunc) {}
0037
0038
0039 double evaluate(double const* iVariables, double const* iParameters) const final {
0040 return m_function(m_arg->evaluate(iVariables, iParameters));
0041 }
0042 std::vector<std::string> abstractSyntaxTree() const final {
0043 auto ret = shiftAST(m_arg->abstractSyntaxTree());
0044 ret.emplace(ret.begin(), "func 1 arg");
0045 return ret;
0046 }
0047
0048 FunctionOneArgEvaluator(const FunctionOneArgEvaluator&) = delete;
0049
0050 const FunctionOneArgEvaluator& operator=(const FunctionOneArgEvaluator&) = delete;
0051
0052 private:
0053
0054 std::shared_ptr<EvaluatorBase> m_arg;
0055 std::function<double(double)> m_function;
0056 };
0057 }
0058 }
0059
0060 #endif