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 939 by tim, Tue Jan 13 22:12:32 2004 UTC vs.
Revision 1007 by tim, Tue Feb 3 17:10:44 2004 UTC

# Line 1 | Line 1
1 < #ifndef _FUNCTOR_H
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
52   */
53  
54 < class ObjFunctor{
54 > class ObjFunctor1{
55  
56    public:
57      virtual double operator()(vector<double>&, vector<double>&)=0;  
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>&)
64 < class PtrFunctor : ObjFunctor{
64 > class PtrFunctor1 : ObjFunctor1{
65  
66    public:
67  
68 <    PtrFunctor(double (*thePtrFunc)(vector<double>&, vector<double>&)){
68 >    PtrFunctor1(double (*thePtrFunc)(vector<double>&, vector<double>&)){
69        ptrFunc = thePtrFunc;
70      }
71      
# Line 37 | Line 80 | class ClassMemObjFunctor : public ObjFunctor{
80   //ClassMemObjFunctor class wraps a pointer pointing to a member function of a class
81   //
82   template<typename TClass>
83 < class ClassMemObjFunctor : public ObjFunctor{
83 > class ClassMemObjFunctor1 : public ObjFunctor1{
84    public:
85 <    ClassMemObjFunctor(TClass* thePtrClass, double (TClass::*thePtrFunc)(vector<double>&, vector<double>&)){
85 >    ClassMemObjFunctor1(TClass* thePtrClass, double (TClass::*thePtrFunc)(vector<double>&, vector<double>&)){
86        ptrClass = thePtrClass;
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