Global Functions and Macros
rwtMakeFunctor0() rwtMakeFunctor0G() rwtMakeFunctor0GA1() |
rwtMakeFunctor0GA2() rwtMakeFunctor0GA3() rwtMakeFunctor0M() |
rwtMakeFunctor0MA1() rwtMakeFunctor0MA2() rwtMakeFunctor0MA3() |
#include <rw/functor/functor0.h>
A function object, or functor, is an object that encapsulates a call to an associated global or member function. When a functor is invoked, it calls the associated function.
The rwtMakeFunctor0 functions and macros are provided to construct functors based on the RWFunctor0 class. The RWFunctor0 class acts as the handle for a family of functor implementation classes based on the RWFunctor0Imp class. A functor based on RWFunctor0 is invoked with no arguments and returns no value, but the implementation classes can accept functions with up to three arguments and any return type. The values for the additional arguments are defined when an implementation class instance is constructed, and are passed to the function each time the functor is invoked.
Each rwtMakeFunctor0 function or macro instantiates and constructs an appropriate functor implementation class instance and returns an RWFunctor0 handle that is bound to that instance.
rwtMakeFunctor0 comes in two flavors. First, there is a set of overloaded global function templates. Since not all compilers are able to handle templates to the degree required by these functions, we also provide a corresponding set of macros. The template functions are slightly easier to use and you only have to remember one name. The macros are more portable but they do require more arguments; and because we cannot overload macros, each must have a unique name.
In naming the macros we have employed a convention to make the names easier to remember. Each name begins with rwtMakeFunctor0, which will be followed by either a G if the macro is expecting a global function, or an M if it is expecting a member function. At that point the name is complete if the associated global or member function takes no arguments. Otherwise we add one of A1, A2, or A3 for functions with 1, 2, or 3 arguments respectively. For example, you will use macro rwtMakeFunctor0G to create a functor that calls a global function that takes no arguments. The macro rwtMakeFunctor0MA2 will create a functor that calls a member function that takes two arguments.
class A { public: int bar(char); // Member function with 1 argument }; A a; // an instance of class A int foo(double, long); // Global function with 2 arguments // Create an rwtFunctor0 set to call foo(3.14,11): RWFunctor0 t1 = rwtMakeFunctor0(NULL, foo, 3.14, 11); // Create an rwtFunctor0 set to call a.bar(`x'): RWFunctor0 t2 = rwtMakeFunctor0(NULL, a, &A::bar, `x');
class A { public: int bar(char); // Member function with 1 argument }; A a; // An instance of class A int foo(double, long); // Global function with 2 arguments // Create an rwtFunctor0 set to call foo(3.14,11): RWFunctor0 t1
= rwtMakeFunctor0GA2(int, foo, double, 3.14, long, 11); // Create an rwtFunctor0 set to call a.bar(`x'): RWFunctor0 t2
= rwtMakeFunctor0MA1(A, a, int, &A::bar, char, `x');
The following information applies to each of the function templates in this section:
The invokeAs argument is not used at this time and should be passed as NULL, as done in the example above.
Where applicable, a1, a2 and a3 must be convertible to instances of types A1, A2 and A3 respectively.
template <class DR> RWFunctor0 rwtMakeFunctor0(void (*invokeAs)(void), DR (*function)(void));
Creates an RWFunctor0 set to call function().
template <class DR, class A1, class AA1> RWFunctor0 rwtMakeFunctor0(void (*invokeAs)(void), DR (*function)(A1), AA1 a1)
Creates an RWFunctor0 set to call function(a1).
template <class DR, class A1, class A2, class AA1, class AA2> RWFunctor0 rwtMakeFunctor0(void (*invokeAs)(void),
DR (*function)(A1,A2), AA1 a1, AA2 a2)
Creates an RWFunctor0 set to call function(a1,a2).
template <class DR, class A1, class A2, class A3,
class AA1, class AA2, class AA3> RWFunctor0 rwtMakeFunctor0(void (*invokeAs)(void),
DR (*function)(A1,A2,A3),
AA1 a1, AA2 a2,AA3 a3)
Creates an RWFunctor0 set to call function(a1,a2,a3).
template <class Callee, class DR> RWFunctor0 rwtMakeFunctor0(void(*invokeAs)(void), Callee& callee, DR (Callee::*function)(void))
Creates an RWFunctor0 set to call callee.function().
template <class Callee, class DR, class A1, class AA1> RWFunctor0 rwtMakeFunctor0(void(*invokeAs)(void), Callee& callee, DR (Callee::*function)(A1), AA1 a1)
Creates an RWFunctor0 set to call callee.function(a1).
template <class Callee, class DR, class A1, class A2, class AA1, class AA2> RWFunctor0 rwtMakeFunctor0(void(*invokeAs)(void), Callee& callee, DR (Callee::*function)(A1,A2), AA1 a1, AA2 a2)
Creates an RWFunctor0 set to call callee.function(a1,a2).
template <class Callee, class DR, class A1, class A2,
class A3, class AA1, class AA2, class AA3> RWFunctor0 rwtMakeFunctor0(void(*invokeAs)(void), Callee& callee, DR (Callee::*function)(A1,A2,A3), AA1 a1, AA2 a2, AA3 a3)
Creates an RWFunctor0 set to call callee.function(a1,a2,a3).
The macros in this section use the following naming conventions for the macro arguments:
DR | Type name of the function return value. |
function | Global function pointer. |
A1 | Type name of the first argument. |
a1 | Expression that can be converted to an instance of A1. |
A2 | Type name of the second argument. |
a2 | Expression that can be converted to an instance of A2. |
A3 | Type name of the third argument. |
a3 | Expression that can be converted to an instance of A3. |
rwtMakeFunctor0G(DR,function)
Creates an RWFunctor0 set to call function().
function must have signature DR (*)(void)
rwtMakeFunctor0GA1(DR,function,A1,a1)
Creates an RWFunctor0 set to call function(a1).
function must have signature DR (*)(A1)
rwtMakeFunctor0GA2(DR,function,A1,a1,A2,a2)
Creates an RWFunctor0 set to call function(a1,a2).
function must have signature DR (*)(A1,A2)
rwtMakeFunctor0GA3(DR,function,A1,a1,A2,a2,A3,a3)
Creates an RWFunctor0 set to call function(a1,a2,a3).
function must have signature DR (*)(A1,A2,A3)
The macros in this section use the following naming conventions for the macro arguments:
Callee | Type name of the function's class. |
callee | Expression that results in a reference to a Callee instance. |
DR | Type name of the function return value. |
function | Pointer to member function of class Callee |
A1 | Type name of the first argument. |
a1 | Expression that can be converted to an instance of A1. |
A2 | Type name of the second argument. |
a2 | Expression that can be converted to an instance of A2. |
A3 | Type name of the second argument. |
a3 | Expression that can be converted to an instance of A3. |
rwtMakeFunctor0M(Callee,callee,DR,function)
Creates an RWFunctor0 set to call callee.function(). function must have signature DR (Caller::*)(void).
rwtMakeFunctor0MA1(Callee,callee,DR,function,A1,a1)
Creates an RWFunctor0 set to call callee.function(a1).
function must have signature DR (Caller::*)(A1).
rwtMakeFunctor0MA2(Callee,callee,DR,function,A1,a1,A2,a2)
Creates an RWFunctor0 set to call callee.function(a1,a2).
function must have signature DR (Caller::*)(A1,A2).
rwtMakeFunctor0MA3(Callee,callee,DR,function, A1,a1,A2,a2,A3,a3)
Creates an RWFunctor0 set to call callee.function(a1,a2,a3).
function must have signature DR (Caller::*)(A1,A2,A3).
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.