ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Functor.hpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/Functor.hpp (file contents):
Revision 987 by tim, Tue Jan 27 19:15:20 2004 UTC vs.
Revision 1007 by tim, Tue Feb 3 17:10:44 2004 UTC

# Line 1 | Line 1
1   #ifndef _FUNCTOR_H_
2   #define _FUNCTOR_H_
3  
4 + #include <vector>
5 +
6 + using namespace std;
7 +
8 + class ObjFunctor0{
9 +  public:
10 +    virtual double operator()(vector<double>&)=0;  
11 + };
12 +
13 + class PtrFunctor0 : ObjFunctor0{
14 +
15 +  public:
16 +
17 +    PtrFunctor0(double (*thePtrFunc)(vector<double>&)){
18 +      ptrFunc = thePtrFunc;
19 +    }
20 +    
21 +    virtual double operator()(vector<double>& arg){
22 +       return (*ptrFunc)(arg);
23 +    };
24 +    
25 +  protected:
26 +    double (*ptrFunc)(vector<double>&);
27 + };
28 +
29 +
30 + //ClassMemObjFunctor class wraps a pointer pointing to a member function of a class
31 + //
32 + template<typename TClass>
33 + class ClassMemObjFunctor0 : public ObjFunctor0{
34 +  public:
35 +    ClassMemObjFunctor0(TClass* thePtrClass, double (TClass::*thePtrFunc)(vector<double>&)){
36 +      ptrClass = thePtrClass;
37 +      ptrFunc = thePtrFunc;
38 +    }
39 +    
40 +    double operator()(vector<double>& arg){
41 +      return (*ptrClass.*ptrFunc)(arg);
42 +    }
43 +  protected:
44 +    
45 +    double (TClass::*ptrFunc)(vector<double>&);  
46 +    TClass* ptrClass;
47 + };
48 +
49   /**
50   * Abstract class of object function which have an overloaded method
51   * to calculate the gradient
# Line 13 | Line 58 | class ObjFunctor1{
58      
59   };
60  
16
17
61   //PtrFunctor class wraps a pointer which points to an objct function.
62   // PtrFunctor can be invoked by
63   // functor(vector<double>&, vector<double>&)
# Line 44 | Line 87 | class ClassMemObjFunctor1 : public ObjFunctor1{
87        ptrFunc = thePtrFunc;
88      }
89      
90 <    double operator()(vector<double>&, vector<double>&){
91 <      return (*ptrClass.*ptrFunc))(arg, grad);
90 >    double operator()(vector<double>&arg, vector<double>&grad){
91 >      return (*ptrClass.*ptrFunc)(arg, grad);
92      }
93    protected:
94      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines