| 1 | = !CommandEvaluation = |
| 2 | [[TracNav(TracNav/TOC_Development)]] |
| 3 | |
| 4 | == Description == |
| 5 | A !CommandEvaluation is returned by [wiki:CommandExecutor#evaluate CommandExecutor::evaluate(string)]. A !CommandEvaluation is a container, storing a parsed [wiki:ConsoleCommand]. It's in fact just a function-pointer and a set of prepared arguments. This allows very efficient calls of the parsed command which is important if the same command gets called over and over (for example if it's [wiki:KeyBinder bound] to a key). |
| 6 | |
| 7 | == Usage == |
| 8 | * '''execute()''': See [wiki:CommandExecutor#execute CommandExecutor::execute(string)] |
| 9 | * '''complete()''': See [wiki:CommandExecutor#complete CommandExecutor::complete(string)] |
| 10 | * '''hint()''': See [wiki:CommandExecutor#hint CommandExecutor::hint(string)] |
| 11 | |
| 12 | * '''getOriginalCommand()''': Returns the original command string as it was typed by the user |
| 13 | * '''getCommand()''': Returns the final command string, modified by the [wiki:CommandExecutor] |
| 14 | |
| 15 | * '''isValid()''': Returns true if the command exists and all needed arguments are given |
| 16 | * '''getConsoleCommand()''': Returns a pointer to the parsed [wiki:ConsoleCommand] |
| 17 | * '''hasReturnvalue()''': Returns true if the command returns a value |
| 18 | * '''getReturnvalue()''': Returns the returnvalue (if any) |
| 19 | |
| 20 | * '''evaluateParams()''': Prepares the given arguments (by converting them to the desired types) |
| 21 | * '''setEvaluatedParameter('''''param-index (0-4), value''''')''': Changes an already evaluated parameter (''value'' is a [wiki:MultiType] so you can assign everything, but the exact type is better for performance) |
| 22 | * '''getEvaluatedParameter('''''param-index (0-4)''''')''': Returns an evaluated parameter |
| 23 | |
| 24 | * '''setAdditionalParameter('''''parameter''''')''': Adds additional parameters (as a string). '''Warning''': This destroys the evaluation of the parameters! |
| 25 | * '''getAdditionalParameter()''': Returns the additional parameters (if any) |
| 26 | |
| 27 | == Example == |
| 28 | {{{ |
| 29 | // Get the evaluation: |
| 30 | CommandEvaluation myevaluation = \ |
| 31 | CommandExecutor::evaluate("MyClass myfunction 10"); |
| 32 | |
| 33 | // Call MyClass::myfunction(10) a hundred times: |
| 34 | for (int i = 0; i < 100; i++) |
| 35 | myevaluation.execute(); |
| 36 | |
| 37 | // Change the evaluated parameter from 10 to 33: |
| 38 | myevaluation.setEvaluatedParameter(33); |
| 39 | |
| 40 | // Call MyClass::myfunction(33) once: |
| 41 | myevaluation.execute(); |
| 42 | }}} |