Changes between Version 1 and Version 2 of code/doc/Executor
- Timestamp:
- Sep 30, 2008, 7:46:37 PM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
code/doc/Executor
v1 v2 7 7 == Usage == 8 8 === 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''''')'''.9 To 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''''')'''. 10 10 {{{ 11 11 void function(); … … 15 15 16 16 '''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 20 It's also possible to give the Executor a name: 21 {{{ 22 void function(); 23 24 Executor* myexecutor = createExecutor(createFunctor(&function), "name"); 25 }}} 26 This is usually unnecessary, but very important for [wiki:ConsoleCommand] and other features. 17 27 18 28 === Call === … … 40 50 myexecutor->setDefaultValue(2, 10); // the third argument 41 51 }}} 52 (The second variant allows you to only bind the last argument for example.) 42 53 43 Then you can call the Executor without passing arguments :54 Then you can call the Executor without passing arguments; the Executor uses the previously added default values to compensate the missing arguments: 44 55 {{{ 45 56 (*myexecutor)(); // equivalent to function(false, 2.5, 10); 46 57 }}} 47 The Executor uses the previously added default values to compensate the missing arguments.48 58 49 Of course you can still use arguments :59 Of course you can still use arguments to overwrite default values: 50 60 {{{ 51 61 (*myexecutor)(true, 3.3); // equivalent to function(true, 3.3, 10); 52 62 }}} 53 63 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 54 74 === 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 == 89 There are two subclasses of Executor: 90 91 === ExecutorStatic === 92 ExecutorStatic accepts only [wiki:Functor#FunctorStatic]. Read the linked chapter for more information. 93 94 === ExecutorMember === 95 ExecutorMember accepts only [wiki:Functor#FunctorMember]. Read the linked chapter for more information. To call an ExecutorMember, just use it like FunctorMember: 96 {{{ 97 class SomeClass 98 { 99 void someFunction(int value); 100 }; 101 102 SomeClass* object = new SomeClass(); 103 ExecutorMember* executor = createExecutor(createFunctor(&SomeClass::someFunction)); 104 105 (*executor)(object, 10); // this is equivalent to object->someFunction(10); 106 107 // And with default value: 108 executor->setDefaultValues(20); 109 110 (*executor)(object); // this is equivalent to object->someFunction(20); 111 }}}