ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Functor.hpp
Revision: 939
Committed: Tue Jan 13 22:12:32 2004 UTC (20 years, 5 months ago) by tim
File size: 1390 byte(s)
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 tim 939 #ifndef _FUNCTOR_H
2     #define _FUNCTOR_H_
3    
4     /**
5     * Abstract class of object function which have an overloaded method
6     * to calculate the gradient
7     */
8    
9     class ObjFunctor{
10    
11     public:
12     virtual double operator()(vector<double>&, vector<double>&)=0;
13    
14     };
15    
16    
17    
18     //PtrFunctor class wraps a pointer which points to an objct function.
19     // PtrFunctor can be invoked by
20     // functor(vector<double>&, vector<double>&)
21     class PtrFunctor : ObjFunctor{
22    
23     public:
24    
25     PtrFunctor(double (*thePtrFunc)(vector<double>&, vector<double>&)){
26     ptrFunc = thePtrFunc;
27     }
28    
29     virtual double operator()(vector<double>& arg, vector<double>& grad){
30     return (*ptrFunc)(arg, grad);
31     };
32    
33     protected:
34     double (*ptrFunc)(vector<double>&, vector<double>&);
35     };
36    
37     //ClassMemObjFunctor class wraps a pointer pointing to a member function of a class
38     //
39     template<typename TClass>
40     class ClassMemObjFunctor : public ObjFunctor{
41     public:
42     ClassMemObjFunctor(TClass* thePtrClass, double (TClass::*thePtrFunc)(vector<double>&, vector<double>&)){
43     ptrClass = thePtrClass;
44     ptrFunc = thePtrFunc;
45     }
46    
47     double operator()(vector<double>&, vector<double>&){
48     return (*ptrClass.*ptrFunc))(arg, grad);
49     }
50     protected:
51    
52     double (TClass::*ptrFunc)(vector<double>&, vector<double>&);
53     TClass* ptrClass;
54     };
55    
56     #endif

Properties

Name Value
svn:executable *