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

This class is used to execute and evaluate command-strings. More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/core/command/CommandExecutor.h>

Classes

struct  CacheEntry
 Helper struct, used to store cached entries. More...
 

Static Public Member Functions

static void _autocomplete (const std::string &group, const std::string &name)
 Pseudo console command used whenever no real command is available. In these cases this command provides auto-completion for console commands and groups. More...
 
static void alias (const std::string &alias, const std::string &command)
 This function is used as console command which saves a command and optionally also it's arguments as a new console command with a new name. More...
 
static CommandEvaluation evaluate (const std::string &command)
 Evaluates the given command. More...
 
static int execute (const std::string &command, bool useTcl=true, bool printErrors=true)
 Executes a command. More...
 
static std::string getErrorDescription (int error)
 Returns a description of the error code. More...
 
static std::string query (const std::string &command, int *error=NULL, bool useTcl=true)
 Executes a command and returns its return-value as string. More...
 
static MultiType queryMT (const std::string &command, int *error=nullptr, bool useTcl=true)
 Executes a command and returns its return-value. More...
 
static MultiType unhide (const std::string &command)
 This function is used as console command which executes commands that are usually hidden. More...
 

Static Public Attributes

static constexpr int Deactivated = 3
 Error code if the command is not active. More...
 
static constexpr int Denied = 4
 Error code if the command needs a different access level. More...
 
static constexpr int Error = 5
 Error code if the command returned an error. More...
 
static constexpr int Incomplete = 2
 Error code if the command needs more arguments. More...
 
static constexpr int Inexistent = 1
 Error code if the command doesn't exist. More...
 
static constexpr int Success = 0
 Error code for "success" (or no error) More...
 

Private Member Functions

 CommandExecutor ()=default
 Empty constructor. More...
 
 CommandExecutor (const CommandExecutor &)=delete
 
 ~CommandExecutor ()=default
 Empty destructor. More...
 
void cache (const std::string &command, const CommandEvaluation &evaluation)
 Writes a command evaluation for a given command to the cache. More...
 
bool getCached (const std::string &command, CommandEvaluation &evaluation)
 Gets an evaluated command from the cache. More...
 
CommandExecutoroperator= (const CommandExecutor &)=delete
 

Static Private Member Functions

static CommandExecutorgetInstance ()
 Returns a reference to the only instance of CommandExecutor. More...
 

Private Attributes

std::map< std::string, CacheEntrycache_
 A map that connects command strings and evaluated commands in the cache. More...
 
std::list< std::string > cachelist_
 A list used to sort the elements in the cache by their age. More...
 

Detailed Description

This class is used to execute and evaluate command-strings.

CommandExecutor executes command-strings and returns evaluated commands. It's also possible to execute Tcl commands if the corresponding argument of execute() is true.

See also
See this description for more information and some examples.

Constructor & Destructor Documentation

orxonox::CommandExecutor::CommandExecutor ( )
privatedefault

Empty constructor.

orxonox::CommandExecutor::~CommandExecutor ( )
privatedefault

Empty destructor.

orxonox::CommandExecutor::CommandExecutor ( const CommandExecutor )
privatedelete

Member Function Documentation

static void orxonox::CommandExecutor::_autocomplete ( const std::string &  group,
const std::string &  name 
)
inlinestatic

Pseudo console command used whenever no real command is available. In these cases this command provides auto-completion for console commands and groups.

void orxonox::CommandExecutor::alias ( const std::string &  alias,
const std::string &  command 
)
static

This function is used as console command which saves a command and optionally also it's arguments as a new console command with a new name.

Parameters
aliasThe name of the new command alias
commandThe existing command and (optionally) its arguments
void orxonox::CommandExecutor::cache ( const std::string &  command,
const CommandEvaluation evaluation 
)
private

Writes a command evaluation for a given command to the cache.

CommandEvaluation orxonox::CommandExecutor::evaluate ( const std::string &  command)
static

Evaluates the given command.

Parameters
commandA string containing the command
Returns
Returns an instance of CommandEvaluation, which contains the evaluated ConsoleCommand, if the command is valid.

Evaluates the given command string and returns an instance of CommandEvaluation. If the command is valid, this contains the evaluated ConsoleCommand. Otherwise it can still be used to print hints or complete the command.

Note
Tcl commands can not be evaluated. You have to pass them to execute() or to TclBind directly.
int orxonox::CommandExecutor::execute ( const std::string &  command,
bool  useTcl = true,
bool  printErrors = true 
)
static

Executes a command.

Parameters
commandA string containing the command
useTclIf true, the command is passed to tcl (see TclBind)
printErrorsIf true, print an error when command failed
Returns
Returns the error-code (see error codes)
bool orxonox::CommandExecutor::getCached ( const std::string &  command,
CommandEvaluation evaluation 
)
private

Gets an evaluated command from the cache.

Parameters
commandThe command that should be looked up in the cache
evaluationReference to a CommandEvaluation that will be used to return the cached evaluation.
Returns
Returns true if the command was found in the cache
std::string orxonox::CommandExecutor::getErrorDescription ( int  error)
static

Returns a description of the error code.

Parameters
errorThe error code
CommandExecutor & orxonox::CommandExecutor::getInstance ( )
staticprivate

Returns a reference to the only instance of CommandExecutor.

CommandExecutor& orxonox::CommandExecutor::operator= ( const CommandExecutor )
privatedelete
std::string orxonox::CommandExecutor::query ( const std::string &  command,
int *  error = NULL,
bool  useTcl = true 
)
static

Executes a command and returns its return-value as string.

Parameters
commandA string containing the command
errorA pointer to a value (or nullptr) where the error-code should be written to (see error codes)
useTclIf true, the command is passed to tcl (see TclBind)
Returns
Returns the return-value of the command converted to a string (or "" if there's no return value)
MultiType orxonox::CommandExecutor::queryMT ( const std::string &  command,
int *  error = nullptr,
bool  useTcl = true 
)
static

Executes a command and returns its return-value.

Parameters
commandA string containing the command
errorA pointer to a value (or nullptr) where the error-code should be written to (see error codes)
useTclIf true, the command is passed to tcl (see TclBind)
Returns
Returns the return-value of the command (if any - MultiType::Null otherwise)
MultiType orxonox::CommandExecutor::unhide ( const std::string &  command)
static

This function is used as console command which executes commands that are usually hidden.

The argument completion function of this console commands is used to find and enter hidden commands and their arguments.

Member Data Documentation

std::map<std::string, CacheEntry> orxonox::CommandExecutor::cache_
private

A map that connects command strings and evaluated commands in the cache.

std::list<std::string> orxonox::CommandExecutor::cachelist_
private

A list used to sort the elements in the cache by their age.

constexpr int orxonox::CommandExecutor::Deactivated = 3
static

Error code if the command is not active.

constexpr int orxonox::CommandExecutor::Denied = 4
static

Error code if the command needs a different access level.

constexpr int orxonox::CommandExecutor::Error = 5
static

Error code if the command returned an error.

constexpr int orxonox::CommandExecutor::Incomplete = 2
static

Error code if the command needs more arguments.

constexpr int orxonox::CommandExecutor::Inexistent = 1
static

Error code if the command doesn't exist.

constexpr int orxonox::CommandExecutor::Success = 0
static

Error code for "success" (or no error)


The documentation for this class was generated from the following files: