1 |
tim |
962 |
#ifndef _FUNCTOR_H_
|
2 |
tim |
939 |
#define _FUNCTOR_H_
|
3 |
|
|
|
4 |
|
|
/**
|
5 |
|
|
* Abstract class of object function which have an overloaded method
|
6 |
|
|
* to calculate the gradient
|
7 |
|
|
*/
|
8 |
|
|
|
9 |
tim |
987 |
class ObjFunctor1{
|
10 |
tim |
939 |
|
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 |
tim |
987 |
class PtrFunctor1 : ObjFunctor1{
|
22 |
tim |
939 |
|
23 |
|
|
public:
|
24 |
|
|
|
25 |
tim |
987 |
PtrFunctor1(double (*thePtrFunc)(vector<double>&, vector<double>&)){
|
26 |
tim |
939 |
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 |
tim |
987 |
class ClassMemObjFunctor1 : public ObjFunctor1{
|
41 |
tim |
939 |
public:
|
42 |
tim |
987 |
ClassMemObjFunctor1(TClass* thePtrClass, double (TClass::*thePtrFunc)(vector<double>&, vector<double>&)){
|
43 |
tim |
939 |
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
|