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  : _f( f )
63  {}
64  virtual T operator()() { return ( *_f )(); }
65 
66 private:
67  F _f;
68 };
69 
70 //----------------------------------------------------------------------------
71 //----------------------------------------------------------------------------
72 template<class O, class T>
74 {
75 public:
76  typedef T ( O::*F )();
77  GlsMemberFunctor_T( O& o, F f )
78  : _o( o )
79  , _f( f )
80  {}
81  virtual T operator()() { return ( _o.*_f )(); }
82 
83 private:
84  O& _o;
85  F _f;
86 };
87 
88 //----------------------------------------------------------------------------
89 //----------------------------------------------------------------------------
90 template<class O, class T>
92 {
93 public:
94  typedef T ( O::*F )() const;
95  GlsConstMemberFunctor_T( const O& o, F f )
96  : _o( o )
97  , _f( f )
98  {}
99 
100  virtual T operator()( T arg ) { return ( _o.*_f )( arg ); }
101 
102 private:
103  const O& _o;
104  F _f;
105 };
106 
107 //----------------------------------------------------------------------------
108 //----------------------------------------------------------------------------
109 template<class T>
111 {
112  return new GlsStaticMemberFunctor_T<T>( f );
113 }
114 
115 //----------------------------------------------------------------------------
116 //----------------------------------------------------------------------------
117 template<class O, class T>
118 GlsMemberFunctor_T<O, T>* GlsFunctor( O& o, T ( O::*f )() )
119 {
120  return new GlsMemberFunctor_T<O, T>( o, f );
121 }
122 
123 //----------------------------------------------------------------------------
124 //----------------------------------------------------------------------------
125 template<class O, class T>
126 GlsConstMemberFunctor_T<O, T>* GlsFunctor( const O& o, T ( O::*f )() const )
127 {
128  return new GlsConstMemberFunctor_T<O, T>( o, f );
129 }
130 
131 //----------------------------------------------------------------------------
132 // 1 ARGUMENT FUNCTORS
133 //----------------------------------------------------------------------------
134 template<class T>
136 {
137 public:
138  virtual void operator()( T arg ) = 0;
139 };
140 
141 //----------------------------------------------------------------------------
142 //----------------------------------------------------------------------------
143 template<class T>
145 {
146 public:
147  typedef void ( *F )( T );
149  : _f( f )
150  {}
151  virtual void operator()( T arg ) { ( *_f )( arg ); }
152 
153 private:
154  F _f;
155 };
156 
157 //----------------------------------------------------------------------------
158 //----------------------------------------------------------------------------
159 template<class O, class T>
161 {
162 public:
163  typedef void ( O::*F )( T );
165  : _o( o )
166  , _f( f )
167  {}
168  virtual void operator()( T arg ) { ( _o.*_f )( arg ); }
169 
170 private:
171  O& _o;
172  F _f;
173 };
174 
175 //----------------------------------------------------------------------------
176 //----------------------------------------------------------------------------
177 template<class O, class T>
179 {
180 public:
181  typedef void ( O::*F )( T ) const;
182  GlsConstMemberFunctor1_T( const O& o, F f )
183  : _o( o )
184  , _f( f )
185  {}
186  virtual void operator()( T arg ) { ( _o.*_f )( arg ); }
187 
188 private:
189  const O& _o;
190  F _f;
191 };
192 
193 //----------------------------------------------------------------------------
194 //----------------------------------------------------------------------------
195 template<class T>
197 {
198  return new GlsStaticMemberFunctor1_T<T>( f );
199 }
200 
201 //----------------------------------------------------------------------------
202 //----------------------------------------------------------------------------
203 template<class O, class T>
204 GlsMemberFunctor1_T<O, T>* GlsFunctor( O& o, void ( O::*f )( T ) )
205 {
206  return new GlsMemberFunctor1_T<O, T>( o, f );
207 }
208 
209 //----------------------------------------------------------------------------
210 //----------------------------------------------------------------------------
211 template<class O, class T>
212 GlsConstMemberFunctor1_T<O, T>* GlsFunctor( const O& o, void ( O::*f )( T ) const )
213 {
214  return new GlsConstMemberFunctor1_T<O, T>( o, f );
215 }
216 
217 //----------------------------------------------------------------------------
218 // 2 ARGUMENT FUNCTORS
219 //----------------------------------------------------------------------------
220 template<class T1, class T2>
222 {
223 public:
224  virtual void operator()( T1 arg1, T2 arg2 ) = 0;
225 };
226 
227 //----------------------------------------------------------------------------
228 //----------------------------------------------------------------------------
229 template<class O, class T1, class T2>
231 {
232 public:
233  typedef void ( O::*F )( T1, T2 );
235  : _f( f )
236  {}
237  virtual void operator()( T1 arg1, T2 arg2 ) { ( *_f )( arg1, arg2 ); }
238 
239 private:
240  F _f;
241 };
242 
243 //----------------------------------------------------------------------------
244 //----------------------------------------------------------------------------
245 template<class O, class T1, class T2>
246 class GlsMemberFunctor2_T : public GlsFunctor2_T<T1, T2>
247 {
248 public:
249  typedef void ( O::*F )( T1, T2 );
251  : _o( o )
252  , _f( f )
253  {}
254  virtual void operator()( T1 arg1, T2 arg2 ) { ( _o.*_f )( arg1, arg2 ); }
255 
256 private:
257  O& _o;
258  F _f;
259 };
260 
261 //----------------------------------------------------------------------------
262 //----------------------------------------------------------------------------
263 template<class O, class T1, class T2>
265 {
266 public:
267  typedef void ( O::*F )( T1, T2 ) const;
268  GlsConstMemberFunctor2_T( const O& o, F f )
269  : _o( o )
270  , _f( f )
271  {}
272  virtual void operator()( T1 arg1, T2 arg2 ) { ( _o.*_f )( arg1, arg2 ); }
273 
274 private:
275  const O& _o;
276  F _f;
277 };
278 
279 //----------------------------------------------------------------------------
280 //----------------------------------------------------------------------------
281 template<class O, class T1, class T2>
283 {
284  return new GlsStaticMemberFunctor2_T<O, T1, T2>( f );
285 }
286 
287 //----------------------------------------------------------------------------
288 //----------------------------------------------------------------------------
289 template<class O, class T1, class T2>
290 GlsMemberFunctor2_T<O, T1, T2>* GlsFunctor( O& o, void ( O::*f )( T1, T2 ) )
291 {
292  return new GlsMemberFunctor2_T<O, T1, T2>( o, f );
293 }
294 
295 //----------------------------------------------------------------------------
296 //----------------------------------------------------------------------------
297 template<class O, class T1, class T2>
298 GlsConstMemberFunctor2_T<O, T1, T2>* GlsFunctor( const O& o, void ( O::*f )( T1, T2 ) const )
299 {
300  return new GlsConstMemberFunctor2_T<O, T1, T2>( o, f );
301 }
302 
303 //----------------------------------------------------------------------------
304 // 3 ARGUMENT FUNCTORS
305 //----------------------------------------------------------------------------
306 template<class T1, class T2, class T3>
308 {
309 public:
310  virtual void operator()( T1 arg1, T2 arg2, T3 arg3 ) = 0;
311 };
312 
313 //----------------------------------------------------------------------------
314 //----------------------------------------------------------------------------
315 template<class O, class T1, class T2, class T3>
316 class GlsStaticMemberFunctor3_T : public GlsFunctor3_T<T1, T2, T3>
317 {
318 public:
319  typedef void ( O::*F )( T1, T2, T3 );
321  : _f( f )
322  {}
323  virtual void operator()( T1 arg1, T2 arg2, T3 arg3 ) { ( *_f )( arg1, arg2, arg3 ); }
324 
325 private:
326  F _f;
327 };
328 
329 //----------------------------------------------------------------------------
330 //----------------------------------------------------------------------------
331 template<class O, class T1, class T2, class T3>
332 class GlsMemberFunctor3_T : public GlsFunctor3_T<T1, T2, T3>
333 {
334 public:
335  typedef void ( O::*F )( T1, T2, T3 );
337  : _o( o )
338  , _f( f )
339  {}
340  virtual void operator()( T1 arg1, T2 arg2, T3 arg3 ) { ( _o.*_f )( arg1, arg2, arg3 ); }
341 
342 private:
343  O& _o;
344  F _f;
345 };
346 
347 //----------------------------------------------------------------------------
348 //----------------------------------------------------------------------------
349 template<class O, class T1, class T2, class T3>
350 class GlsConstMemberFunctor3_T : public GlsFunctor3_T<T1, T2, T3>
351 {
352 public:
353  typedef void ( O::*F )( T1, T2, T3 ) const;
354  GlsConstMemberFunctor3_T( const O& o, F f )
355  : _o( o )
356  , _f( f )
357  {}
358  virtual void operator()( T1 arg1, T2 arg2, T3 arg3 ) { ( _o.*_f )( arg1, arg2, arg3 ); }
359 
360 private:
361  const O& _o;
362  F _f;
363 };
364 
365 //----------------------------------------------------------------------------
366 //----------------------------------------------------------------------------
367 template<class O, class T1, class T2, class T3>
368 GlsStaticMemberFunctor3_T<O, T1, T2, T3>* GlsFunctor( void ( O::*f )( T1, T2, T3 ) )
369 {
371 }
372 
373 //----------------------------------------------------------------------------
374 //----------------------------------------------------------------------------
375 template<class O, class T1, class T2, class T3>
376 GlsMemberFunctor3_T<O, T1, T2, T3>* GlsFunctor( O& o, void ( O::*f )( T1, T2, T3 ) )
377 {
378  return new GlsMemberFunctor3_T<O, T1, T2, T3>( o, f );
379 }
380 
381 //----------------------------------------------------------------------------
382 //----------------------------------------------------------------------------
383 template<class O, class T1, class T2, class T3>
384 GlsConstMemberFunctor3_T<O, T1, T2, T3>* GlsFunctor( const O& o, void ( O::*f )( T1, T2, T3 ) const )
385 {
386  return new GlsConstMemberFunctor3_T<O, T1, T2, T3>( o, f );
387 }
388 
389 #endif // GLS_FUNCTOR_H
void(O::* F)(T) const
Definition: gls_functor.h:181
GlsConstMemberFunctor1_T(const O &o, F f)
Definition: gls_functor.h:182
virtual void operator()(T arg)
Definition: gls_functor.h:168
virtual void operator()(T arg)
Definition: gls_functor.h:186
virtual void operator()(T1 arg1, T2 arg2, T3 arg3)
Definition: gls_functor.h:340
virtual void operator()(T1 arg1, T2 arg2, T3 arg3)=0
virtual T operator()()
Definition: gls_functor.h:81
void(O::* F)(T1, T2)
Definition: gls_functor.h:233
GlsMemberFunctor1_T(O &o, F f)
Definition: gls_functor.h:164
void(O::* F)(T1, T2)
Definition: gls_functor.h:249
void(O::* F)(T1, T2, T3)
Definition: gls_functor.h:335
virtual void operator()(T1 arg1, T2 arg2)=0
GlsMemberFunctor2_T(O &o, F f)
Definition: gls_functor.h:250
GlsConstMemberFunctor2_T(const O &o, F f)
Definition: gls_functor.h:268
virtual void operator()(T arg)
Definition: gls_functor.h:151
virtual void operator()(T1 arg1, T2 arg2)
Definition: gls_functor.h:237
virtual void operator()(T1 arg1, T2 arg2, T3 arg3)
Definition: gls_functor.h:358
virtual void operator()(T1 arg1, T2 arg2, T3 arg3)
Definition: gls_functor.h:323
GlsMemberFunctor3_T(O &o, F f)
Definition: gls_functor.h:336
void(O::* F)(T1, T2, T3) const
Definition: gls_functor.h:353
GlsMemberFunctor_T(O &o, F f)
Definition: gls_functor.h:77
virtual T operator()()=0
GlsConstMemberFunctor3_T(const O &o, F f)
Definition: gls_functor.h:354
void(O::* F)(T1, T2) const
Definition: gls_functor.h:267
GlsConstMemberFunctor_T(const O &o, F f)
Definition: gls_functor.h:95
virtual void operator()(T1 arg1, T2 arg2)
Definition: gls_functor.h:254
void(O::* F)(T1, T2, T3)
Definition: gls_functor.h:319
virtual void operator()(T1 arg1, T2 arg2)
Definition: gls_functor.h:272
virtual T operator()(T arg)
Definition: gls_functor.h:100
virtual void operator()(T arg)=0
GlsStaticMemberFunctor_T< T > * GlsFunctor(T(*f)())
Definition: gls_functor.h:110
void(O::* F)(T)
Definition: gls_functor.h:163
T(O::* F)() const
Definition: gls_functor.h:94