Back to home page

EIC code displayed by LXR

 
 

    


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

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