Global Functions and Macros
#include <rw/thread/rwtMakeRunnableIOUFunction.h>
int foo(void); RWTRunnableIOUFunction<int> runFunc = rwtMakeRunnableIOUFunction(foo);
The easiest way to create a runnable object with Threads.h++ is to begin with rwtMakeRunnableIOUFunction. By supplying a global or member function pointer you control what your runnable will do after starting. If you wish your runnable to start by calling a function that takes arguments, rwtMakeRunnableIOUFunction allows you to specify the values that should be passed to that function. Note that runnables created with rwtMakeRunnableIOUFunction allow you to extract the return value from the associated function. This distinguishes them from those created by rwtMakeRunnableFunction, which do not.
rwtMakeRunnableIOUFunction 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 as we can not 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 rwtMakeRunnableIOUFunction, 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 rwtMakeRunnableIOUFunctionG to create a runnable that calls a global function that takes no arguments. The macro rwtMakeRunnableIOUFunctionMA2 will create a runnable 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 RWTRunnableIOUFunction set to call foo(3.14,11): RWTRunnableIOUFunction<int> t1
= rwtMakeRunnableIOUFunction(foo, 3.14, 11); // Create an RWTRunnableIOUFunction set to call a.bar(`x'): RWTRunnableIOUFunction<int> t2 = rwtMakeRunnableIOUFunction(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 RWTRunnableIOUFunction set to call foo(3.14,11): RWTRunnableIOUFunction<int> t1
= rwtMakeRunnableIOUFunctionGA2(int, foo, double, 3.14, long, 11); // Create an RWTRunnableIOUFunction set to call a.bar(`x'): RWTRunnableIOUFunction<int> t2 = rwtMakeRunnableIOUFunctionMA1(A, a, int, &A::bar, char, `x');
template <class R> RWTRunnableIOUFunction<R> rwtMakeRunnableIOUFunction(R (*function)(void))
Creates an RWTRunnableIOUFunction set to call function().
template <class R, class A1, class AA1> RWTRunnableIOUFunction<R> rwtMakeRunnableIOUFunction(R (*function)(A1), AA1 a1)
Creates an RWTRunnableIOUFunction set to call function(a1).
a1 must be convertible to an instance of type A1.
template <class R, class A1, class A2, class AA1,
class AA2> RWTRunnableIOUFunction<R> rwtMakeRunnableIOUFunction(R (*function)(A1,A2), AA1 a1,
AA2 a2)
Creates an RWTRunnableIOUFunction set to call function(a1,a2) .
a1 and a2 must be convertible to instances of types A1 and A2 respectively.
template <class R, class A1, class A2, class A3, class AA1, class AA2, class AA3> RWTRunnableIOUFunction<R> rwtMakeRunnableIOUFunction(R (*function)(A1,A2,A3), AA1 a1, AA2 a2,AA3 a3)
Creates an RWTRunnableIOUFunction set to call function(a1,a2,a3).
a1, a2, and a3 must be convertible to instances of types A1, A2, and A3 respectively.
template <class Callee, class R> RWTRunnableIOUFunction<R> rwtMakeRunnableIOUFunction(Callee& callee, R (Callee::*function)(void))
Creates an RWTRunnableIOUFunction set to call callee.function().
template <class Callee, class R, class A1, class AA1> RWTRunnableIOUFunction<R> rwtMakeRunnableIOUFunction(Callee& callee, R (Callee::*function)(A1), AA1 a1)
Creates an RWTRunnableIOUFunction set to call callee.function(a1). a1 must be convertible to an instance of A1.
template <class Callee, class R, class A1, class A2, class AA1, class AA2> RWTRunnableIOUFunction<R> rwtMakeRunnableIOUFunction(Callee& callee, R (Callee::*function)(A1,A2), AA1 a1, AA2 a2)
Creates an RWTRunnableIOUFunction set to call callee.function(a1,a2). a1 and a2 must be convertible to instances of types A1 and A2 respectively.
template <class Callee, class R, class A1, class A2, class A3, class AA1, class AA2, class AA3> RWTRunnableIOUFunction<R> rwtMakeRunnableIOUFunction(Callee& callee, (Callee::*function)(A1,A2,A3), AA1 a1, AA2 a2, AA3 a3)
Creates an RWTRunnableIOUFunction set to call callee.function(a1,a2,a3). a1, a2, and a3 must be convertible to instances of types A1, A2, and A3 respectively.
The macros in this section use the following naming conventions for the macro arguments:
R | 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. |
rwtMakeRunnableIOUFunctionG(R,function)
Creates an RWTRunnableIOUFunction set to call function().
function must have signature R (*)(void)
rwtMakeRunnableIOUFunctionGA1(R,function,A1,a1)
Creates an RWTRunnableIOUFunction set to call function(a1).
function must have signature R (*)(A1)
rwtMakeRunnableIOUFunctionGA2(R,function,A1,a1,A2,a2)
Creates an RWTRunnableIOUFunction set to call function(a1,a2). function must have signature R (*)(A1,A2)
rwtMakeRunnableIOUFunctionGA3(R,function,A1,a1,A2,a2,A3,a3)
Creates an RWTRunnableIOUFunction set to call function(a1,a2,a3). function must have signature R (*)(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. |
R | 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. |
rwtMakeRunnableIOUFunctionM(Callee,callee,R,function)
Creates an RWTRunnableIOUFunction set to call callee.function().
function must have signature R (Caller::*)(void).
rwtMakeRunnableIOUFunctionMA1(Callee,callee,R,function,A1,a1)
Creates an RWTRunnableIOUFunction set to call callee.function(a1). function must have signature R (Caller::*)(A1).
rwtMakeRunnableIOUFunctionMA2(Callee,callee,R, function,A1,a1,A2,a2)
Creates an RWTRunnableIOUFunction set to call callee.function(a1,a2). function must have signature R (Caller::*)(A1,A2).
rwtMakeRunnableIOUFunctionMA3(Callee,callee,R,function, A1,a1,A2,a2,A3,a3)
Creates an RWTRunnableIOUFunction set to call
callee.function(a1,a2,a3). function must have signature
R (Caller::*)(A1,A2,A3).
RWTRunnableIOUFunction<Return>
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.