Home
Install
Use
Develop
Support
News
Credits
hosted by
|
11 #ifndef __Swinburne_Functor_h
12 #define __Swinburne_Functor_h
14 #include "Reference.h"
17 struct __functor_empty {};
38 template< typename R, typename A1=__functor_empty, typename A2=__functor_empty>
52 template< typename Function, typename Inherit>
58 { return function == _function; }
61 bool is_valid () const { return function != 0; }
66 return like && like-> matches( function); }
76 template< class Class, typename Method, class Inherit>
81 bool matches ( const Class* _instance, Method _method) const
110 template< typename R, typename A1, typename A2 >
115 typedef R result_type;
125 R operator() () const { return functor->call(); }
128 template< class C, typename M> Functor (C* instance, M method)
129 { functor = new Method<C, M> (instance, method); }
132 template< class C, typename M> Functor ( const C& instance, M method)
133 { functor = new Method<const C, M> (&instance, method); }
137 { functor = new Function<F> ( function); }
140 template< class C, typename M> void set (C* instance, M method)
141 { functor = new Method<C, M> (instance, method); }
144 template< typename F> void set (F function)
145 { functor = new Function<F> ( function); }
155 virtual R call () const = 0;
164 { this-> function = _function; }
168 { return R( (*(this-> function)) () ); }
173 template< class C, typename M> class Method : public FunctorMethod<C,M,Base> {
178 { this->instance = _instance; this->method = _method; }
182 { return R( (this->instance->*(this->method)) () ); }
187 bool operator ! () const { return !functor; }
190 operator bool () const { return functor; }
210 template< typename R, typename A1, typename A2 >
215 typedef A1 argument_type;
216 typedef R result_type;
226 R operator() ( const A1& p1) const { return functor->call(p1); }
229 template< class C, typename M> Functor (C* instance, M method)
230 { functor = new Method<C, M> (instance, method); }
233 template< class C, typename M> Functor ( const C& instance, M method)
234 { functor = new Method<const C, M> (&instance, method); }
238 { functor = new Function<F> ( function); }
241 template< class C, typename M> void set (C* instance, M method)
242 { functor = new Method<C, M> (instance, method); }
245 template< typename F> void set (F function)
246 { functor = new Function<F> ( function); }
256 virtual R call ( const A1& p1) const = 0;
265 { this-> function = _function; }
269 { return static_cast<R >( (*(this-> function))(p1) ); }
274 template< class C, typename M> class Method : public FunctorMethod<C,M,Base> {
279 { this->instance = _instance; this->method = _method; }
282 R call ( const A1& p1) const try
283 { return R( (this->instance->*(this->method)) (p1) ); }
284 catch ( Error& error) { throw error += "Functor<R(T)>::Method::call"; }
289 bool operator ! () const { return !functor; }
292 operator bool () const { return functor; }
313 template< typename R, typename A1, typename A2 >
318 typedef A1 first_argument_type;
319 typedef A2 second_argument_type;
320 typedef R result_type;
330 R operator() ( const A1& p1, const A2& p2) const
331 { return functor->call(p1,p2); }
334 template< class C, typename M> Functor (C* instance, M method)
335 { functor = new Method<C, M> (instance, method); }
338 template< class C, typename M> Functor ( const C& instance, M method)
339 { functor = new Method<const C, M> (&instance, method); }
343 { functor = new Function<F> ( function); }
346 template< class C, typename M> void set (C* instance, M method)
347 { functor = new Method<C, M> (instance, method); }
350 template< typename F> void set (F function)
351 { functor = new Function<F> ( function); }
361 virtual R call ( const A1& p1, const A2& p2) const = 0;
370 { this-> function = _function; }
373 R call ( const A1& p1, const A2& p2) const
374 { return R( (*(this-> function)) (p1, p2) ); }
379 template< class C, typename M> class Method : public FunctorMethod<C,M,Base> {
384 { this->instance = _instance; this->method = _method; }
387 R call ( const A1& p1, const A2& p2) const
388 { return R( (this->instance->*(this->method)) (p1, p2) ); }
393 bool operator ! () const { return !functor; }
396 operator bool () const { return functor; }
408 template< typename R, typename A1, typename A2>
417 if (f1.get_functor() == f2.get_functor())
420 return f1.get_functor()->matches( f2.get_functor() );
void set(F function) Set equal to a generator function. Definition: Functor.h:144
Function(F _function) Construct from a pointer to a function. Definition: Functor.h:369
Functor(F function) Construct from a binary function. Definition: Functor.h:342
virtual bool matches(const FunctorBase *that) const Return true if this matches that. Definition: Functor.h:64
R call(const A1 &p1, const A2 &p2) const Call the function. Definition: Functor.h:373
Functor(const C &instance, M method) Construct from a class instance and binary method. Definition: Functor.h:338
void set(C *instance, M method) Set equal to a class instance and unary method. Definition: Functor.h:241
bool matches(Function _function) const Return true if the function matches. Definition: Functor.h:57
Functor(F function) Construct from a generator function. Definition: Functor.h:136
Method(C *_instance, M _method) Construct from a pointer to a class instance and method. Definition: Functor.h:177
const FunctorBase * get_functor() const Get the pointer to the functor implementation. Definition: Functor.h:399
A convenient exception handling class. Definition: Error.h:54
void set(C *instance, M method) Set equal to a class instance and generator method. Definition: Functor.h:140
Function(F _function) Construct from a pointer to a function. Definition: Functor.h:163
void set(C *instance, M method) Set equal to a class instance and binary method. Definition: Functor.h:346
Functor() Default constructor. Definition: Functor.h:122
Pure virtual base class of functor implementations. Definition: Functor.h:42
void set(F function) Set equal to a binary function. Definition: Functor.h:350
R call() const Call the function. Definition: Functor.h:167
virtual bool matches(const FunctorBase *that) const =0 Return true if this matches that.
Functor() Default constructor. Definition: Functor.h:223
R call(const A1 &p1) const Call the function. Definition: Functor.h:268
Reference::To< Base > functor The implementation. Definition: Functor.h:404
bool is_valid() const Return true if valid (able to be called) Definition: Functor.h:61
void set(F function) Set equal to a unary function. Definition: Functor.h:245
const FunctorBase * get_functor() const Get the pointer to the functor implementation. Definition: Functor.h:193
Method method The method to be called. Definition: Functor.h:98
R call() const Call the method through the class instance. Definition: Functor.h:181
Method(C *_instance, M _method) Construct from a pointer to a class instance and method. Definition: Functor.h:278
R call(const A1 &p1) const Call the method through the class instance. Definition: Functor.h:282
Method(C *_instance, M _method) Construct from a pointer to a class instance and method. Definition: Functor.h:383
virtual bool matches(const FunctorBase *that) const Return true if this matches that. Definition: Functor.h:88
const FunctorBase * get_functor() const Get the pointer to the functor implementation. Definition: Functor.h:295
Functor(C *instance, M method) Construct from a class instance and binary method. Definition: Functor.h:334
Reference::To< Base > functor The implementation. Definition: Functor.h:198
Manages Reference::To references to the instance. Definition: ReferenceAble.h:40
Functor(C *instance, M method) Construct from a class instance and unary method. Definition: Functor.h:229
Implements scaffolding of Class/Method functor implementations. Definition: Functor.h:77
Reference::To< Class, false > instance The instance of the class. Definition: Functor.h:95
Implements an adaptable function object in compliance with the STL. Definition: Functor.h:39
Functor(const C &instance, M method) Construct from a class instance and unary method. Definition: Functor.h:233
Reference::To< Base > functor The implementation. Definition: Functor.h:300
Functor(F function) Construct from a unary function. Definition: Functor.h:237
R call(const A1 &p1, const A2 &p2) const Call the method through the class instance. Definition: Functor.h:387
Functor(C *instance, M method) Construct from a class instance and generator method. Definition: Functor.h:128
Functor(const C &instance, M method) Construct from a class instance and generator method. Definition: Functor.h:132
bool is_valid() const Return true if valid (able to be called) Definition: Functor.h:85
Functor() Default constructor. Definition: Functor.h:327
bool matches(const Class *_instance, Method _method) const Return true if the instance and method match. Definition: Functor.h:81
virtual bool is_valid() const =0 Return true if valid (able to be called)
Implements scaffolding of Function functor implementations. Definition: Functor.h:53
Function(F _function) Construct from a pointer to a function. Definition: Functor.h:264
Generated using doxygen 1.8.17
|