Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Initial Version and Version 1 of code/doc/Executor


Ignore:
Timestamp:
Sep 30, 2008, 7:22:35 PM (16 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/Executor

    v1 v1  
     1= Executor =
     2[[TracNav(TracNav/TOC_Development)]]
     3
     4== Description ==
     5Executor is a wrapper around [wiki:Functor]. Executor implements additional features like a name, default values, descriptions and more. While Functor already allows you to bind an object to the function, Executor allows you to bind arguments to the function by using default values. With that you can store a whole functioncall (including object and arguments) in one single class and execute it whenever and wherever you want. This features is used by [wiki:Timer], [wiki:ConsoleCommand] and many more.
     6
     7== Usage ==
     8=== Creation ===
     9To create an Executor, you first have to create a [wiki:Functor] (usually with '''createFunctor('''''function-pointer''''')'''). Then you call '''createExecutor('''''functor''''')''' to create the Executor. Of course you can also use '''new Executor('''''functor''''')'''.
     10{{{
     11void function();
     12
     13Executor* myexecutor = createExecutor(createFunctor(&function));
     14}}}
     15
     16'''Important''': createExecutor uses '''new''' to create the executor. If you are responsible for the Executor, you have to delete it afterwards.
     17
     18=== Call ===
     19You can call an Executor just as you call a [wiki:Functor]:
     20{{{
     21void function(int value);
     22Executor* myexecutor = createExecutor(createFunctor(&function));
     23
     24(*myexecutor)(10); // equivalent to function(10);
     25}}}
     26
     27=== Default Values ===
     28It's possible to add a default value for every argument:
     29{{{
     30void function(bool value1, float value2, int value3);
     31Executor* myexecutor = createExecutor(createFunctor(&function));
     32
     33// Variant 1: Bind a default value to all arguments:
     34myexecutor->setDefaultValues(false, 2.5, 10);
     35}}}
     36{{{
     37// Variant 2: Bind default values to specific arguments:
     38myexecutor->setDefaultValue(0, false); // the first argument
     39myexecutor->setDefaultValue(1, 2.5);   // the second argument
     40myexecutor->setDefaultValue(2, 10);    // the third argument
     41}}}
     42
     43Then you can call the Executor without passing arguments:
     44{{{
     45(*myexecutor)(); // equivalent to function(false, 2.5, 10);
     46}}}
     47The Executor uses the previously added default values to compensate the missing arguments.
     48
     49Of course you can still use arguments:
     50{{{
     51(*myexecutor)(true, 3.3); // equivalent to function(true, 3.3, 10);
     52}}}
     53
     54=== Other Functions ===