CommandEvaluation is used to gather information about a command and to evaluate its arguments.
More...
#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/core/command/CommandEvaluation.h>
CommandEvaluation is used to gather information about a command and to evaluate its arguments.
This class provides several information about a command-string, for example the evaluated ConsoleCommand, but also other information like hints if the command is not yet finished.
- Note
- You don't have to call evaluateArguments() manually, it's also done automatically if you call the command the first time. However you can of course do it at any earlier time, for example to return an error message if it doesn't work.
- See also
- See this description for an example.
orxonox::CommandEvaluation::CommandEvaluation |
( |
| ) |
|
Constructor: Initializes the command evaluation with an empty command.
std::string orxonox::CommandEvaluation::complete |
( |
| ) |
|
Completes the given command string using the list of possible arguments.
- Returns
- Returns the completed command string
This is called by the shell if the user presses the tab key. The currently entered argument will be completed as good as possible by using the argument completion list of the evaluated command.
Joins the elements of the given list to a string.
std::string orxonox::CommandEvaluation::dump |
( |
const ConsoleCommand * |
command | ) |
|
|
staticprivate |
Returns a string that explains the syntax of the given command.
int orxonox::CommandEvaluation::evaluateArguments |
( |
bool |
bPrintError = false | ) |
|
Evaluates the arguments of the command.
- Parameters
-
bPrintError | If true, the function prints an error message if it doesn't succeed |
- Returns
- Returns the error code (see CommandExecutor error codes)
int orxonox::CommandEvaluation::execute |
( |
| ) |
|
std::string orxonox::CommandEvaluation::getCommandSuggestion |
( |
| ) |
const |
If the command couln't be evaluated because it doesn't exist, print a suggestion for a command that looks close to the entered command (useful if the user mistyped the command).
Returns the commond begin of all arguments in the list.
const ConsoleCommand* orxonox::CommandEvaluation::getConsoleCommand |
( |
| ) |
const |
|
inline |
Returns the console command that was evaluated by this object.
MultiType orxonox::CommandEvaluation::getEvaluatedArgument |
( |
unsigned int |
index | ) |
const |
Returns the evaluated argument with given index.
- Parameters
-
index | The index of the argument (the first argument has index 0) |
const std::string & orxonox::CommandEvaluation::getLastArgument |
( |
| ) |
const |
|
private |
Returns the last argument (which is the one the user currently enters into the shell).
unsigned int orxonox::CommandEvaluation::getNumberOfArguments |
( |
| ) |
const |
|
private |
Returns the number of tokens according to the definition of CommandExecutor (which counts also an empty argument at the end of the string).
Returns a list of possible arguments for the given command.
Note that the command's arguments may not be complete yet, so in this case this list returns the possibilities. They can then be used to display a list of the possible arguments or to apply auto-completion.
size_t orxonox::CommandEvaluation::getPossibleArgumentsSize |
( |
| ) |
const |
|
inline |
Returns the number of possible arguments. Empty ("") arguments are not counted.
Returns the size of an argument completion list - empty ("") arguments are not counted.
const std::string & orxonox::CommandEvaluation::getToken |
( |
unsigned int |
i | ) |
const |
|
private |
Returns the token with the given index (or a blank string if it doesn't exist).
std::string orxonox::CommandEvaluation::hint |
( |
| ) |
|
Returns a string containing hints or possible arguments for the evaluated command.
This is called by the shell if the user presses the tab key. It prints a list of possible arguments or other hints, returned by the argument completion list of the evaluated command. If there's no such list, the syntax of the command is returned.
void orxonox::CommandEvaluation::initialize |
( |
const std::string & |
command | ) |
|
|
private |
bool orxonox::CommandEvaluation::isValid |
( |
| ) |
const |
|
inline |
Returns true if the command evaluation contains a valid command that can be executed.
MultiType orxonox::CommandEvaluation::query |
( |
int * |
error = nullptr | ) |
|
Executes the command which was evaluated by this object and returns its return-value.
- Parameters
-
- Returns
- Returns the result of the command (or MultiType::Null if there is no return value)
void orxonox::CommandEvaluation::retrievePossibleArguments |
( |
| ) |
|
|
private |
Gets the possible arguments for the command in its current state.
void orxonox::CommandEvaluation::setEvaluatedArgument |
( |
unsigned int |
index, |
|
|
const MultiType & |
arg |
|
) |
| |
Replaces an evaluated argument with a new value.
- Parameters
-
index | The index of the parameter (the first argument has index 0) |
arg | The new value of the parameter |
Removes all elements from the list that don't start with fragment.
- Parameters
-
list | The argument completion list |
fragment | The argument that is currently entered by the user and that needs to be completed |
The evaluated arguments (the arguments from string_ or tokens_ converted to the right type)
bool orxonox::CommandEvaluation::bEvaluatedArguments_ |
|
private |
True if the arguments of the command have been evaluated (and stored in arguments_)
bool orxonox::CommandEvaluation::bPossibleArgumentsRetrieved_ |
|
private |
True if the list of possible arguments was already retrieved.
bool orxonox::CommandEvaluation::bTriedToEvaluatedArguments_ |
|
private |
True if an attempt was started to evaluate the arguments (but not necessarily successful)
unsigned int orxonox::CommandEvaluation::execArgumentsOffset_ |
|
private |
The index of the first argument in tokens_ used to execute the command.
The command that will be executed (can be nullptr if the command is not valid)
unsigned int orxonox::CommandEvaluation::hintArgumentsOffset_ |
|
private |
The index of the first argument in tokens_ used to display hints and argument lists.
The command that is used to display hints and argument lists (can be different to execCommand_ in some cases)
unsigned int orxonox::CommandEvaluation::numberOfEvaluatedArguments_ |
|
private |
The number of evaluated arguments (ranges from 0 to MAX_FUNCTOR_ARGUMENTS)
List of possible arguments for the command in the current state.
std::string orxonox::CommandEvaluation::string_ |
|
private |
The original command string, entered by the user in the shell.
SubString orxonox::CommandEvaluation::tokens_ |
|
private |
The single words of the command string, split into tokens.
The documentation for this class was generated from the following files: