7 |
|
|
8 |
|
class ObjFunctor0{ |
9 |
|
public: |
10 |
+ |
|
11 |
+ |
virtual ~ObjFunctor0() {} |
12 |
|
virtual double operator()(vector<double>&)=0; |
13 |
+ |
|
14 |
|
}; |
15 |
|
|
16 |
< |
class PtrFunctor0 : ObjFunctor0{ |
16 |
> |
class PtrFunctor0 : public ObjFunctor0{ |
17 |
|
|
18 |
|
public: |
19 |
|
|
57 |
|
class ObjFunctor1{ |
58 |
|
|
59 |
|
public: |
60 |
+ |
virtual ~ObjFunctor1() {} |
61 |
|
virtual double operator()(vector<double>&, vector<double>&)=0; |
62 |
|
|
63 |
|
}; |
65 |
|
//PtrFunctor class wraps a pointer which points to an objct function. |
66 |
|
// PtrFunctor can be invoked by |
67 |
|
// functor(vector<double>&, vector<double>&) |
68 |
< |
class PtrFunctor1 : ObjFunctor1{ |
68 |
> |
class PtrFunctor1 : public ObjFunctor1{ |
69 |
|
|
70 |
|
public: |
71 |
|
|
72 |
|
PtrFunctor1(double (*thePtrFunc)(vector<double>&, vector<double>&)){ |
73 |
|
ptrFunc = thePtrFunc; |
74 |
|
} |
75 |
< |
|
75 |
> |
|
76 |
|
virtual double operator()(vector<double>& arg, vector<double>& grad){ |
77 |
|
return (*ptrFunc)(arg, grad); |
78 |
|
}; |
100 |
|
TClass* ptrClass; |
101 |
|
}; |
102 |
|
|
103 |
+ |
|
104 |
+ |
class OutputFunctor{ |
105 |
+ |
public: |
106 |
+ |
|
107 |
+ |
virtual ~OutputFunctor() {} |
108 |
+ |
virtual void operator()(vector<double>&, int)=0; |
109 |
+ |
|
110 |
+ |
}; |
111 |
+ |
|
112 |
+ |
class PtrOutputFunctor : public OutputFunctor{ |
113 |
+ |
|
114 |
+ |
public: |
115 |
+ |
|
116 |
+ |
PtrOutputFunctor(void (*thePtrFunc)(vector<double>&, int)){ |
117 |
+ |
ptrFunc = thePtrFunc; |
118 |
+ |
} |
119 |
+ |
|
120 |
+ |
virtual void operator()(vector<double>& arg1, int arg2){ |
121 |
+ |
return (*ptrFunc)(arg1, arg2); |
122 |
+ |
}; |
123 |
+ |
|
124 |
+ |
protected: |
125 |
+ |
void (*ptrFunc)(vector<double>&, int); |
126 |
+ |
}; |
127 |
+ |
|
128 |
+ |
|
129 |
+ |
//ClassMemObjFunctor class wraps a pointer pointing to a member function of a class |
130 |
+ |
// |
131 |
+ |
template<typename TClass> |
132 |
+ |
class ClassMemOutputFunctor : public OutputFunctor{ |
133 |
+ |
public: |
134 |
+ |
ClassMemOutputFunctor(TClass* thePtrClass, void (TClass::*thePtrFunc)(vector<double>&, int)){ |
135 |
+ |
ptrClass = thePtrClass; |
136 |
+ |
ptrFunc = thePtrFunc; |
137 |
+ |
} |
138 |
+ |
|
139 |
+ |
void operator()(vector<double>& arg1, int arg2){ |
140 |
+ |
return (*ptrClass.*ptrFunc)(arg1, arg2); |
141 |
+ |
} |
142 |
+ |
protected: |
143 |
+ |
|
144 |
+ |
void (TClass::*ptrFunc)(vector<double>&, int); |
145 |
+ |
TClass* ptrClass; |
146 |
+ |
}; |
147 |
|
#endif |