Orxonox  0.0.5 Codename: Arcturus
Classes | Namespaces
CommandExecutor.h File Reference

Declaration of the orxonox::CommandExecutor class which is used to execute and evaluate console commands. More...

#include "core/CorePrereqs.h"
#include <map>
#include <list>
#include <string>
#include "util/MultiType.h"
#include "CommandEvaluation.h"

Go to the source code of this file.

Classes

class  orxonox::CommandExecutor
 This class is used to execute and evaluate command-strings. More...
 
struct  orxonox::CommandExecutor::CacheEntry
 Helper struct, used to store cached entries. More...
 

Namespaces

 orxonox
 Die Wagnis Klasse hat die folgenden Aufgaben:
 

Detailed Description

Declaration of the orxonox::CommandExecutor class which is used to execute and evaluate console commands.

orxonox::CommandExecutor can be used to execute console commands (see orxonox::ConsoleCommand). Commands are strings that can be entered by the user in the shell or they can be part of a script.

A command can be passed to orxonox::CommandExecutor::execute() which will execute them - eiter directly, or - if requested - passes it to Tcl. See orxonox::TclBind for more information. Appart from execute() the command can also be passed to orxonox::CommandExecutor::query() which behaves the same except for that it returns the return value of the command.

If you don't want to execute the command, but rather gather more information about it, pass it to orxonox::CommandExecutor::evaluate(). This function returns an instance of orxonox::CommandEvaluation. This class provides more information about the command, for example the evaluated instance of orxonox::ConsoleCommand. Its also possible to gather hints about the command or to complete the command-string by using argument completion functions. More than that the command evaluation can also evaluate the arguments, which allows faster execution of the command.

Example:

CommandExecutor::execute("log test"); // writes "test" to the console
CommandExecutor::execute("log [expr 1+1]"); // writes "2" to the console - expr is a Tcl command
CommandExecutor::query("expr 1+1"); // returns "2"
CommandExecutor::queryMT("expr 1+1"); // returns 2

And another example about how to use evaluate():

CommandEvaluation evaluation;
evaluation = CommandExecutor::evaluate("log test"); // returns an evaluation of "log test"
evaluation.execute(); // writes "test" to the console
evaluation.hint(); // returns "log: {string}"

Error codes:

orxonox::CommandExecutor defines a number of error codes that are returned by different functions that operate with commands: