Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/Executor

    v1 v2  
    77== Usage ==
    88=== Creation ===
    9 To 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''''')'''.
     9To create an Executor, you first have to create a [wiki:Functor] (usually by using the helper function '''createFunctor('''''function-pointer''''')'''). Then you call '''createExecutor('''''functor''''')''' to create the Executor. Of course you can also use '''new Executor('''''functor''''')'''.
    1010{{{
    1111void function();
     
    1515
    1616'''Important''': createExecutor uses '''new''' to create the executor. If you are responsible for the Executor, you have to delete it afterwards.
     17
     18'''Important''': If an Executor gets deleted, it deletes it's Functor too, so you don't have to care about the Functor. '''Never''' share Functors among different Executors, this would lead to a crash.
     19
     20It's also possible to give the Executor a name:
     21{{{
     22void function();
     23
     24Executor* myexecutor = createExecutor(createFunctor(&function), "name");
     25}}}
     26This is usually unnecessary, but very important for [wiki:ConsoleCommand] and other features.
    1727
    1828=== Call ===
     
    4050myexecutor->setDefaultValue(2, 10);    // the third argument
    4151}}}
     52(The second variant allows you to only bind the last argument for example.)
    4253
    43 Then you can call the Executor without passing arguments:
     54Then you can call the Executor without passing arguments; the Executor uses the previously added default values to compensate the missing arguments:
    4455{{{
    4556(*myexecutor)(); // equivalent to function(false, 2.5, 10);
    4657}}}
    47 The Executor uses the previously added default values to compensate the missing arguments.
    4858
    49 Of course you can still use arguments:
     59Of course you can still use arguments to overwrite default values:
    5060{{{
    5161(*myexecutor)(true, 3.3); // equivalent to function(true, 3.3, 10);
    5262}}}
    5363
     64=== Descriptions ===
     65 * '''setDescription('''''description''''')''': Sets the description of the Executor (what the function does)
     66 * '''getDescription()''': Returns the description of the Executor
     67
     68 * '''setDescriptionParam('''''param number (0-4)''''', '''''description''''')''': Sets the description of an argument (what the argument does)
     69 * '''getDescriptionParam('''''param number (0-4)''''')''': Returns the description of an argument
     70
     71 * '''setDescriptionReturnvalue('''''description''''')''': Sets the description of the return value (what the return value does)
     72 * '''getDescriptionReturnvalue()''': Returns the description of the return value
     73
    5474=== Other Functions ===
     75 * '''getName()''': Returns the Executors name
     76 * '''getFunctor()''': Returns a pointer to the Functor
     77
     78 * '''getDefaultValue('''''param number (0-4)''''')''': Returns the default value for the given argument
     79 * '''allDefaultValuesSet()''': Returns true if there's a default value for every argument
     80
     81 * '''getParamCount()''': Returns the amount of parameters the function takes
     82 * '''hasReturnvalue()''': Returns true if the function returns a value
     83 * '''getReturnvalue()''': Returns the value returned by the last call of the Functor
     84 * '''getType()''': Returns the type of the function as an enum: FT_MEMBER, FT_CONSTMEMBER, FT_STATIC
     85 * '''getTypenameParam('''''param number (0-4)''''')''': Returns the typename
     86 * '''getTypenameReturnvalue()''': Returns the typename of the returnvalue as a string
     87
     88== Types ==
     89There are two subclasses of Executor:
     90
     91=== ExecutorStatic ===
     92ExecutorStatic accepts only [wiki:Functor#FunctorStatic]. Read the linked chapter for more information.
     93
     94=== ExecutorMember ===
     95ExecutorMember accepts only [wiki:Functor#FunctorMember]. Read the linked chapter for more information. To call an ExecutorMember, just use it like FunctorMember:
     96{{{
     97class SomeClass
     98{
     99    void someFunction(int value);
     100};
     101
     102SomeClass* object = new SomeClass();
     103ExecutorMember* executor = createExecutor(createFunctor(&SomeClass::someFunction));
     104
     105(*executor)(object, 10); // this is equivalent to object->someFunction(10);
     106
     107// And with default value:
     108executor->setDefaultValues(20);
     109
     110(*executor)(object); // this is equivalent to object->someFunction(20);
     111}}}