Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:48:21

0001 #ifndef FUNCTOR_1D
0002 #define FUNCTOR_1D
0003 
0004 /**
0005  * @file Functor1D.h
0006  * @author Bryan BERTHOU (SPhN / CEA Saclay)
0007  * @date 15 February 2016
0008  * @version 1.0
0009  */
0010 
0011 #include <vector>
0012 
0013 #include "FunctionType1D.h"
0014 
0015 namespace NumA {
0016 
0017 /**
0018  * @class Functor1D
0019  *
0020  * @brief Template class for defining one-dimensional functions that can be used as arguments in virtual methods.
0021  * This is needed to circumvent the issue that templates and virtual methods are incompatible.
0022  *
0023  * See FunctionType1D documentation for usage.
0024  */
0025 
0026 template<typename PointerToObj, typename PointerToFunc>
0027 class Functor1D: public FunctionType1D {
0028 public:
0029     /**
0030      * Constructor.
0031      * @param object Pointer to an object instantiating the class where the function is defined.
0032      * @param function Reference to the function.
0033      */
0034     Functor1D(PointerToObj* object, PointerToFunc function) :
0035             m_pObject(object), m_pFunction(function) {
0036     }
0037 
0038     /**
0039      * Default destructor.
0040      */
0041     virtual ~Functor1D() {
0042     }
0043 
0044     inline double operator()(double x, std::vector<double> &parameters) {
0045         return ((*m_pObject).*m_pFunction)(x, parameters);
0046     }
0047     inline double operator()(double x) {
0048         std::vector<double> parameters;
0049         return ((*m_pObject).*m_pFunction)(x, parameters);
0050     }
0051 
0052 private:
0053     PointerToObj* m_pObject; ///< Pointer to an object instantiating the class where the function is defined.
0054     PointerToFunc m_pFunction; ///< Reference to the function.
0055 
0056     Functor1D(const Functor1D&); ///< Not implemented. Disallows copy.
0057     Functor1D& operator=(const Functor1D&); ///< Not implemented. Disallows comparisons.
0058 };
0059 
0060 } // namespace NumA
0061 
0062 #endif /* FUNCTOR_1D */