#ifndef __JFUNCTIONOBJECT1D__ #define __JFUNCTIONOBJECT1D__ #include "JLang/JSinglePointer.hh" #include "JLang/JClass.hh" #include "JMath/JZero.hh" #include "JIO/JSerialisable.hh" #include "JTools/JFunctional.hh" #include "JTools/JConstantFunction1D.hh" /** * \author mdejong */ namespace JTOOLS {} namespace JPP { using namespace JTOOLS; } namespace JTOOLS { using JIO::JReader; using JIO::JWriter; /** * Template implementation of function object in one dimension using an external function. * * This class implements the JFunction1D interface. */ template class JExternalFunction1D : public JFunction1D { public: typedef JFunction1D function_type; typedef typename function_type::argument_type argument_type; typedef typename function_type::result_type result_type; typedef result_type (*pointerToFunction)(const argument_type); /** * Constructor. * * \param function pointer to function */ JExternalFunction1D(pointerToFunction function) : function_type(), __f(function) {} /** * Function value evaluation. * * \param pX pointer to abscissa values * \return function value */ virtual result_type evaluate(const argument_type* pX) const override { return __f(*pX); } protected: /** * Function compilation. */ virtual void do_compile() override {} pointerToFunction __f; }; /** * Template implementation of function object in one dimension. * * This class implements the JFunction1D interface. */ template class JFunctionObject1D : public JFunction1D { public: typedef JFunction1D function_type; typedef typename function_type::argument_type argument_type; typedef typename function_type::result_type result_type; /** * Default constructor. */ JFunctionObject1D() : function_type(), function() {} /** * Constructor. * * \param y constant value */ JFunctionObject1D(typename JLANG::JClass::argument_type y) : function_type(), function(new JConstantFunction1D(y)) {} /** * Constructor. * * \param f pointer to external function */ JFunctionObject1D(result_type (*f)(const argument_type)) : function_type(), function(new JExternalFunction1D(f)) {} /** * Function value evaluation. * * \param pX pointer to abscissa values * \return function value */ virtual result_type evaluate(const argument_type* pX) const override { return function->evaluate(pX); } protected: /** * Function compilation. */ virtual void do_compile() override { function->compile(); } JLANG::JSinglePointer function; }; } #endif