File indexing completed on 2024-04-06 12:01:19
0001 #ifndef CommonTools_Utils_formulaFunctionTwoArgsEvaluator_h
0002 #define CommonTools_Utils_formulaFunctionTwoArgsEvaluator_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 FunctionTwoArgsEvaluator : public EvaluatorBase {
0033 public:
0034 template <typename T>
0035 FunctionTwoArgsEvaluator(std::shared_ptr<EvaluatorBase> iArg1, std::shared_ptr<EvaluatorBase> iArg2, T iFunc)
0036 : m_arg1(std::move(iArg1)), m_arg2(std::move(iArg2)), m_function(iFunc) {}
0037
0038
0039 double evaluate(double const* iVariables, double const* iParameters) const final {
0040 return m_function(m_arg1->evaluate(iVariables, iParameters), m_arg2->evaluate(iVariables, iParameters));
0041 }
0042 std::vector<std::string> abstractSyntaxTree() const final {
0043 auto ret = shiftAST(m_arg1->abstractSyntaxTree());
0044 for (auto& v : shiftAST(m_arg2->abstractSyntaxTree())) {
0045 ret.emplace_back(std::move(v));
0046 }
0047 ret.emplace(ret.begin(), "func 2 args");
0048 return ret;
0049 }
0050
0051 FunctionTwoArgsEvaluator(const FunctionTwoArgsEvaluator&) = delete;
0052
0053 const FunctionTwoArgsEvaluator& operator=(const FunctionTwoArgsEvaluator&) = delete;
0054
0055 private:
0056
0057 std::shared_ptr<EvaluatorBase> m_arg1;
0058 std::shared_ptr<EvaluatorBase> m_arg2;
0059 std::function<double(double, double)> m_function;
0060 };
0061 }
0062 }
0063
0064 #endif