Orxonox  0.0.5 Codename: Arcturus
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
orxonox::CommandEvaluation Class Reference

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>

Public Member Functions

 CommandEvaluation ()
 Constructor: Initializes the command evaluation with an empty command. More...
 
std::string complete ()
 Completes the given command string using the list of possible arguments. More...
 
int evaluateArguments (bool bPrintError=false)
 Evaluates the arguments of the command. More...
 
int execute ()
 Executes the command which was evaluated by this object. More...
 
std::string 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). More...
 
const ConsoleCommandgetConsoleCommand () const
 Returns the console command that was evaluated by this object. More...
 
MultiType getEvaluatedArgument (unsigned int index) const
 Returns the evaluated argument with given index. More...
 
const ArgumentCompletionListgetPossibleArguments () const
 Returns a list of possible arguments for the given command. More...
 
size_t getPossibleArgumentsSize () const
 Returns the number of possible arguments. Empty ("") arguments are not counted. More...
 
std::string hint ()
 Returns a string containing hints or possible arguments for the evaluated command. More...
 
bool isValid () const
 Returns true if the command evaluation contains a valid command that can be executed. More...
 
MultiType query (int *error=nullptr)
 Executes the command which was evaluated by this object and returns its return-value. More...
 
void setEvaluatedArgument (unsigned int index, const MultiType &arg)
 Replaces an evaluated argument with a new value. More...
 

Private Member Functions

const std::string & getLastArgument () const
 Returns the last argument (which is the one the user currently enters into the shell). More...
 
unsigned int getNumberOfArguments () const
 Returns the number of tokens according to the definition of CommandExecutor (which counts also an empty argument at the end of the string). More...
 
const std::string & getToken (unsigned int i) const
 Returns the token with the given index (or a blank string if it doesn't exist). More...
 
void initialize (const std::string &command)
 Initializes all values. More...
 
void retrievePossibleArguments ()
 Gets the possible arguments for the command in its current state. More...
 

Static Private Member Functions

static std::string dump (const ArgumentCompletionList &list)
 Joins the elements of the given list to a string. More...
 
static std::string dump (const ConsoleCommand *command)
 Returns a string that explains the syntax of the given command. More...
 
static std::string getCommonBegin (const ArgumentCompletionList &list)
 Returns the commond begin of all arguments in the list. More...
 
static size_t getSize (const ArgumentCompletionList &list)
 Returns the size of an argument completion list - empty ("") arguments are not counted. More...
 
static void strip (ArgumentCompletionList &list, const std::string &fragment)
 Removes all elements from the list that don't start with fragment. More...
 

Private Attributes

MultiType arguments_ [MAX_FUNCTOR_ARGUMENTS]
 The evaluated arguments (the arguments from string_ or tokens_ converted to the right type) More...
 
bool bEvaluatedArguments_
 True if the arguments of the command have been evaluated (and stored in arguments_) More...
 
bool bPossibleArgumentsRetrieved_
 True if the list of possible arguments was already retrieved. More...
 
bool bTriedToEvaluatedArguments_
 True if an attempt was started to evaluate the arguments (but not necessarily successful) More...
 
unsigned int execArgumentsOffset_
 The index of the first argument in tokens_ used to execute the command. More...
 
const ConsoleCommandexecCommand_
 The command that will be executed (can be nullptr if the command is not valid) More...
 
unsigned int hintArgumentsOffset_
 The index of the first argument in tokens_ used to display hints and argument lists. More...
 
const ConsoleCommandhintCommand_
 The command that is used to display hints and argument lists (can be different to execCommand_ in some cases) More...
 
unsigned int numberOfEvaluatedArguments_
 The number of evaluated arguments (ranges from 0 to MAX_FUNCTOR_ARGUMENTS) More...
 
ArgumentCompletionList possibleArguments_
 List of possible arguments for the command in the current state. More...
 
std::string string_
 The original command string, entered by the user in the shell. More...
 
SubString tokens_
 The single words of the command string, split into tokens. More...
 

Friends

class CommandExecutor
 

Detailed Description

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.
Remarks
execCommand_ and hintCommand_ can be different in this case: There are multiple commands avaliable, let's say "tcl" and "TclThreadManager". The user enters "tcl", which is already a valid command. Now execCommand_ points to the "tcl"-command, but hintCommand_ still points to the autocompletion command of CommandExecutor, because the auto-completion list must still return the two possible commands, "tcl TclThreadManager" because the user may want to write "TclThreadManager ..." and needs auto-completion.
See also
See this description for an example.

Constructor & Destructor Documentation

orxonox::CommandEvaluation::CommandEvaluation ( )

Constructor: Initializes the command evaluation with an empty command.

Member Function Documentation

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.

std::string orxonox::CommandEvaluation::dump ( const ArgumentCompletionList list)
staticprivate

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
bPrintErrorIf 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 ( )

Executes the command which was evaluated by this object.

Returns
Returns the error code (see CommandExecutor error codes)
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).

std::string orxonox::CommandEvaluation::getCommonBegin ( const ArgumentCompletionList list)
staticprivate

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
indexThe 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).

const ArgumentCompletionList& orxonox::CommandEvaluation::getPossibleArguments ( ) const
inline

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.

size_t orxonox::CommandEvaluation::getSize ( const ArgumentCompletionList list)
staticprivate

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

Initializes all values.

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
errorA pointer to an integer (or nullptr) which will be used to write error codes to (see CommandExecutor error codes)
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
indexThe index of the parameter (the first argument has index 0)
argThe new value of the parameter
void orxonox::CommandEvaluation::strip ( ArgumentCompletionList list,
const std::string &  fragment 
)
staticprivate

Removes all elements from the list that don't start with fragment.

Parameters
listThe argument completion list
fragmentThe argument that is currently entered by the user and that needs to be completed

Friends And Related Function Documentation

friend class CommandExecutor
friend

Member Data Documentation

MultiType orxonox::CommandEvaluation::arguments_[MAX_FUNCTOR_ARGUMENTS]
private

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.

const ConsoleCommand* orxonox::CommandEvaluation::execCommand_
private

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.

const ConsoleCommand* orxonox::CommandEvaluation::hintCommand_
private

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)

ArgumentCompletionList orxonox::CommandEvaluation::possibleArguments_
private

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: