GlsMenu
gls_functor.h
Go to the documentation of this file.
1 
41 #if !defined(GLS_FUNCTOR_H)
42 #define GLS_FUNCTOR_H
43 
44 //----------------------------------------------------------------------------
45 // 0 ARGUMENT FUNCTORS
46 //----------------------------------------------------------------------------
47 template <class T>
49 {
50 public:
51  virtual T operator()() = 0;
52 };
53 
54 //----------------------------------------------------------------------------
55 //----------------------------------------------------------------------------
56 template <class T>
58 {
59 public:
60  typedef T (*F)();
62  virtual T operator()() { return (*_f)(); }
63 private:
64  F _f;
65 };
66 
67 //----------------------------------------------------------------------------
68 //----------------------------------------------------------------------------
69 template <class O, class T>
71 {
72 public:
73  typedef T (O::*F)();
74  GlsMemberFunctor_T(O& o, F f) : _o(o), _f(f) {}
75  virtual T operator()() { return (_o.*_f)(); }
76 private:
77  O& _o;
78  F _f;
79 };
80 
81 //----------------------------------------------------------------------------
82 //----------------------------------------------------------------------------
83 template <class O, class T>
85 {
86 public:
87  typedef T (O::*F)() const;
88  GlsConstMemberFunctor_T(const O& o, F f) : _o(o), _f(f) {}
89 
90  virtual T operator()(T arg) { return (_o.*_f)(arg); }
91 
92 private:
93  const O& _o;
94  F _f;
95 };
96 
97 //----------------------------------------------------------------------------
98 //----------------------------------------------------------------------------
99 template <class T>
101 {
102  return new GlsStaticMemberFunctor_T<T>(f);
103 }
104 
105 //----------------------------------------------------------------------------
106 //----------------------------------------------------------------------------
107 template <class O, class T>
109 {
110  return new GlsMemberFunctor_T<O,T>(o, f);
111 }
112 
113 //----------------------------------------------------------------------------
114 //----------------------------------------------------------------------------
115 template <class O, class T>
116 GlsConstMemberFunctor_T<O,T>* GlsFunctor(const O& o, T (O::*f)() const)
117 {
118  return new GlsConstMemberFunctor_T<O,T>(o, f);
119 }
120 
121 
122 //----------------------------------------------------------------------------
123 // 1 ARGUMENT FUNCTORS
124 //----------------------------------------------------------------------------
125 template <class T>
127 {
128 public:
129  virtual void operator()(T arg) = 0;
130 };
131 
132 //----------------------------------------------------------------------------
133 //----------------------------------------------------------------------------
134 template <class T>
136 {
137 public:
138  typedef void (*F)(T);
140  virtual void operator()(T arg) { (*_f)(arg); }
141 private:
142  F _f;
143 };
144 
145 //----------------------------------------------------------------------------
146 //----------------------------------------------------------------------------
147 template <class O, class T>
149 {
150 public:
151  typedef void (O::*F)(T);
152  GlsMemberFunctor1_T(O& o, F f) : _o(o), _f(f) {}
153  virtual void operator()(T arg) { (_o.*_f)(arg); }
154 private:
155  O& _o;
156  F _f;
157 };
158 
159 //----------------------------------------------------------------------------
160 //----------------------------------------------------------------------------
161 template <class O, class T>
163 {
164 public:
165  typedef void (O::*F)(T) const;
166  GlsConstMemberFunctor1_T(const O& o, F f) : _o(o), _f(f) {}
167  virtual void operator()(T arg) { (_o.*_f)(arg); }
168 private:
169  const O& _o;
170  F _f;
171 };
172 
173 //----------------------------------------------------------------------------
174 //----------------------------------------------------------------------------
175 template <class T>
177 {
178  return new GlsStaticMemberFunctor1_T<T>(f);
179 }
180 
181 //----------------------------------------------------------------------------
182 //----------------------------------------------------------------------------
183 template <class O, class T>
184 GlsMemberFunctor1_T<O,T>* GlsFunctor(O& o, void (O::*f)(T))
185 {
186  return new GlsMemberFunctor1_T<O,T>(o, f);
187 }
188 
189 //----------------------------------------------------------------------------
190 //----------------------------------------------------------------------------
191 template <class O, class T>
192 GlsConstMemberFunctor1_T<O,T>* GlsFunctor(const O& o, void (O::*f)(T) const)
193 {
194  return new GlsConstMemberFunctor1_T<O,T>(o, f);
195 }
196 
197 //----------------------------------------------------------------------------
198 // 2 ARGUMENT FUNCTORS
199 //----------------------------------------------------------------------------
200 template <class T1, class T2>
202 {
203 public:
204  virtual void operator()(T1 arg1, T2 arg2) = 0;
205 };
206 
207 //----------------------------------------------------------------------------
208 //----------------------------------------------------------------------------
209 template <class O, class T1, class T2>
211 {
212 public:
213  typedef void (O::*F)(T1,T2);
215  virtual void operator()(T1 arg1, T2 arg2) { (*_f)(arg1, arg2); }
216 private:
217  F _f;
218 };
219 
220 //----------------------------------------------------------------------------
221 //----------------------------------------------------------------------------
222 template <class O, class T1, class T2>
223 class GlsMemberFunctor2_T : public GlsFunctor2_T<T1,T2>
224 {
225 public:
226  typedef void (O::*F)(T1,T2);
227  GlsMemberFunctor2_T(O& o, F f) : _o(o), _f(f) {}
228  virtual void operator()(T1 arg1, T2 arg2) { (_o.*_f)(arg1, arg2); }
229 private:
230  O& _o;
231  F _f;
232 };
233 
234 //----------------------------------------------------------------------------
235 //----------------------------------------------------------------------------
236 template <class O, class T1, class T2>
238 {
239 public:
240  typedef void (O::*F)(T1,T2) const;
241  GlsConstMemberFunctor2_T(const O& o, F f) : _o(o), _f(f) {}
242  virtual void operator()(T1 arg1, T2 arg2) { (_o.*_f)(arg1, arg2); }
243 private:
244  const O& _o;
245  F _f;
246 };
247 
248 //----------------------------------------------------------------------------
249 //----------------------------------------------------------------------------
250 template <class O, class T1, class T2>
252 {
254 }
255 
256 //----------------------------------------------------------------------------
257 //----------------------------------------------------------------------------
258 template <class O, class T1, class T2>
259 GlsMemberFunctor2_T<O,T1,T2>* GlsFunctor(O& o, void (O::*f)(T1, T2))
260 {
261  return new GlsMemberFunctor2_T<O,T1,T2>(o, f);
262 }
263 
264 //----------------------------------------------------------------------------
265 //----------------------------------------------------------------------------
266 template <class O, class T1, class T2>
267 GlsConstMemberFunctor2_T<O,T1,T2>* GlsFunctor(const O& o, void (O::*f)(T1, T2) const)
268 {
269  return new GlsConstMemberFunctor2_T<O,T1,T2>(o, f);
270 }
271 
272 
273 //----------------------------------------------------------------------------
274 // 3 ARGUMENT FUNCTORS
275 //----------------------------------------------------------------------------
276 template <class T1, class T2, class T3>
278 {
279 public:
280  virtual void operator()(T1 arg1, T2 arg2, T3 arg3) = 0;
281 };
282 
283 //----------------------------------------------------------------------------
284 //----------------------------------------------------------------------------
285 template <class O, class T1, class T2, class T3>
286 class GlsStaticMemberFunctor3_T : public GlsFunctor3_T<T1, T2, T3>
287 {
288 public:
289  typedef void (O::*F)(T1, T2, T3);
291  virtual void operator()(T1 arg1, T2 arg2, T3 arg3) { (*_f)(arg1, arg2, arg3); }
292 private:
293  F _f;
294 };
295 
296 //----------------------------------------------------------------------------
297 //----------------------------------------------------------------------------
298 template <class O, class T1, class T2, class T3>
299 class GlsMemberFunctor3_T : public GlsFunctor3_T<T1, T2, T3>
300 {
301 public:
302  typedef void (O::*F)(T1, T2, T3);
303  GlsMemberFunctor3_T(O& o, F f) : _o(o), _f(f) {}
304  virtual void operator()(T1 arg1, T2 arg2, T3 arg3) { (_o.*_f)(arg1, arg2, arg3); }
305 private:
306  O& _o;
307  F _f;
308 };
309 
310 //----------------------------------------------------------------------------
311 //----------------------------------------------------------------------------
312 template <class O, class T1, class T2, class T3>
313 class GlsConstMemberFunctor3_T : public GlsFunctor3_T<T1, T2, T3>
314 {
315 public:
316  typedef void (O::*F)(T1, T2, T3) const;
317  GlsConstMemberFunctor3_T(const O& o, F f) : _o(o), _f(f) {}
318  virtual void operator()(T1 arg1, T2 arg2, T3 arg3) { (_o.*_f)(arg1, arg2, arg3); }
319 private:
320  const O& _o;
321  F _f;
322 };
323 
324 //----------------------------------------------------------------------------
325 //----------------------------------------------------------------------------
326 template <class O, class T1, class T2, class T3>
328 {
330 }
331 
332 //----------------------------------------------------------------------------
333 //----------------------------------------------------------------------------
334 template <class O, class T1, class T2, class T3>
335 GlsMemberFunctor3_T<O,T1, T2, T3>* GlsFunctor(O& o, void (O::*f)(T1, T2, T3))
336 {
337  return new GlsMemberFunctor3_T<O,T1, T2, T3>(o, f);
338 }
339 
340 //----------------------------------------------------------------------------
341 //----------------------------------------------------------------------------
342 template <class O, class T1, class T2, class T3>
343 GlsConstMemberFunctor3_T<O,T1, T2, T3>* GlsFunctor(const O& o, void (O::*f)(T1, T2, T3) const)
344 {
346 }
347 
348 
349 #endif // GLS_FUNCTOR_H
350 
GlsConstMemberFunctor1_T(const O &o, F f)
Definition: gls_functor.h:166
virtual void operator()(T arg)
Definition: gls_functor.h:153
virtual void operator()(T arg)
Definition: gls_functor.h:167
virtual void operator()(T1 arg1, T2 arg2, T3 arg3)
Definition: gls_functor.h:304
virtual void operator()(T1 arg1, T2 arg2, T3 arg3)=0
virtual T operator()()
Definition: gls_functor.h:75
GlsMemberFunctor1_T(O &o, F f)
Definition: gls_functor.h:152
virtual void operator()(T1 arg1, T2 arg2)=0
GlsMemberFunctor2_T(O &o, F f)
Definition: gls_functor.h:227
GlsConstMemberFunctor2_T(const O &o, F f)
Definition: gls_functor.h:241
virtual void operator()(T arg)
Definition: gls_functor.h:140
void(O::* F)(T1, T2, T3) const
Definition: gls_functor.h:316
void(O::* F)(T1, T2)
Definition: gls_functor.h:213
virtual void operator()(T1 arg1, T2 arg2)
Definition: gls_functor.h:215
virtual void operator()(T1 arg1, T2 arg2, T3 arg3)
Definition: gls_functor.h:318
virtual void operator()(T1 arg1, T2 arg2, T3 arg3)
Definition: gls_functor.h:291
GlsMemberFunctor3_T(O &o, F f)
Definition: gls_functor.h:303
void(O::* F)(T1, T2, T3)
Definition: gls_functor.h:289
GlsMemberFunctor_T(O &o, F f)
Definition: gls_functor.h:74
virtual T operator()()=0
void(O::* F)(T1, T2, T3)
Definition: gls_functor.h:302
GlsConstMemberFunctor3_T(const O &o, F f)
Definition: gls_functor.h:317
void(O::* F)(T1, T2) const
Definition: gls_functor.h:240
GlsConstMemberFunctor_T(const O &o, F f)
Definition: gls_functor.h:88
void(O::* F)(T1, T2)
Definition: gls_functor.h:226
void(O::* F)(T) const
Definition: gls_functor.h:165
void(O::* F)(T)
Definition: gls_functor.h:151
virtual void operator()(T1 arg1, T2 arg2)
Definition: gls_functor.h:228
virtual void operator()(T1 arg1, T2 arg2)
Definition: gls_functor.h:242
virtual T operator()(T arg)
Definition: gls_functor.h:90
virtual void operator()(T arg)=0
GlsStaticMemberFunctor_T< T > * GlsFunctor(T(*f)())
Definition: gls_functor.h:100
T(O::* F)() const
Definition: gls_functor.h:87