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

The ConsoleCommand class stores all information about a console command which can be executed by CommandExecutor. More...

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

Classes

struct  Command
 Helper class that is used to put the current state of the ConsoleCommand on a stack. More...
 
struct  CommandName
 Defines the name of a command, consisting of an optional group ("" means no group) and the name itself. More...
 
struct  ConsoleCommandManipulator
 Helper class that is used to manipulate console commands. More...
 

Public Member Functions

 ConsoleCommand (const std::string &name, const ExecutorPtr &executor, bool bInitialized=true)
 Constructor: Initializes all values and registers the command (without a group). More...
 
 ConsoleCommand (const std::string &group, const std::string &name, const ExecutorPtr &executor, bool bInitialized=true)
 Constructor: Initializes all values and registers the command (with a group). More...
 
 ~ConsoleCommand ()
 Destructor: Unregisters the command. More...
 
ConsoleCommandaccessLevel (AccessLevel level)
 Changes the access level of the command. More...
 
ConsoleCommandactivate ()
 Activates the command. More...
 
ConsoleCommandaddGroup (const std::string &group)
 Registers the command in a different group but with the same name. More...
 
ConsoleCommandaddGroup (const std::string &group, const std::string &name)
 Registers an alias of the command in a different group with a different name. More...
 
ConsoleCommandaddShortcut ()
 Registers the command with the same name, but without group, as shortcut. More...
 
ConsoleCommandaddShortcut (const std::string &name)
 Registers the command with an alias as shortcut. More...
 
ConsoleCommandargumentCompleter (unsigned int index, ArgumentCompleter *completer)
 Changes the argument completer for the given argument. More...
 
ConsoleCommandchangeKeybindMode (KeybindMode::Value mode)
 Changes the keybind mode. More...
 
ConsoleCommanddeactivate ()
 Deactivates the command. More...
 
ConsoleCommanddefaultValue (unsigned int index, const MultiType &arg)
 Changes the default value of the argument with given index of the current executor. More...
 
ConsoleCommanddefaultValues (const MultiType &arg1)
 Changes the default values of the current executor. More...
 
ConsoleCommanddefaultValues (const MultiType &arg1, const MultiType &arg2)
 Changes the default values of the current executor. More...
 
ConsoleCommanddefaultValues (const MultiType &arg1, const MultiType &arg2, const MultiType &arg3)
 Changes the default values of the current executor. More...
 
ConsoleCommanddefaultValues (const MultiType &arg1, const MultiType &arg2, const MultiType &arg3, const MultiType &arg4)
 Changes the default values of the current executor. More...
 
ConsoleCommanddefaultValues (const MultiType &arg1, const MultiType &arg2, const MultiType &arg3, const MultiType &arg4, const MultiType &arg5)
 Changes the default values of the current executor. More...
 
ConsoleCommanddescription (const std::string &description)
 Sets the description of this command. More...
 
ConsoleCommanddescriptionParam (unsigned int index, const std::string &description)
 Sets the description for an argument with given index. More...
 
ConsoleCommanddescriptionReturnvalue (const std::string &description)
 Sets the description for the return-value. More...
 
AccessLevel getAccessLevel () const
 Returns the access level of the command. More...
 
ArgumentCompletergetArgumentCompleter (unsigned int index) const
 Returns the argument completer for the argument with given index. More...
 
const FunctorPtrgetBaseFunctor () const
 Returns the functor that defines the required header for this command (but isn't necessarily executed). More...
 
const std::string & getDescription () const
 Returns the description of this command. More...
 
const std::string & getDescriptionParam (unsigned int index) const
 Returns the description for the argument with given index. More...
 
const std::string & getDescriptionReturnvalue (int index) const
 Returns the description for the return-value. More...
 
const ExecutorPtrgetExecutor () const
 Returns the current executor which can be used to execute the command. More...
 
int getInputConfiguredParam () const
 Returns the input configured param. More...
 
KeybindMode::Value getKeybindMode () const
 Returns the keybind mode. More...
 
ConsoleCommandManipulator getManipulator ()
 Returns a manipulator for this command. More...
 
const std::string & getName () const
 Returns the name that was first used for this command. More...
 
const std::vector< CommandName > & getNames ()
 
bool hasAccess () const
 Returns true if the current state of the game matches the required access level. More...
 
ConsoleCommandhide ()
 Hides the command (can still be executed, but is not visible in the list of available commands). More...
 
ConsoleCommandinputConfiguredParam (int index)
 Changes the input configured param to the given index. More...
 
bool isActive () const
 Returns true if the command can be executed right now. More...
 
bool isHidden () const
 Returns true if the command is currently hidden. More...
 
ConsoleCommandkeybindMode (KeybindMode::Value mode)
 Sets the keybind mode. Note: use changeKeybindMode if you intend to change the mode. More...
 
ConsoleCommandsetActive (bool bActive)
 Changes the activity of the command. More...
 
ConsoleCommandsetAsInputCommand ()
 Defines the command to be an input command. More...
 
ConsoleCommandsetHidden (bool bHidden)
 Changes the visibility of the command. More...
 
ConsoleCommandshow ()
 Makes the command visible. More...
 

Private Member Functions

voidgetObject () const
 Returns the current object pointer that is used to execute member-functions. More...
 
bool headersMatch (const FunctorPtr &functor)
 Returns true if the headers of the given functor match the declaration of this command. More...
 
bool headersMatch (const ExecutorPtr &executor)
 Returns true if the headers of the given executor match the declaration of this command. More...
 
void init (const std::string &group, const std::string &name, const ExecutorPtr &executor, bool bInitialized)
 
void popFunction ()
 Removes the current function from the stack and restores the old state. More...
 
void popObject ()
 Removes the current object from the stack an restores the old object. More...
 
void pushFunction (const ExecutorPtr &executor, bool bForce=false)
 Pushes a new executor to the command-stack. More...
 
void pushFunction (const FunctorPtr &functor, bool bForce=false)
 Pushes a new functor to the command-stack. More...
 
void pushFunction ()
 Pushes a copy of the current executor and functor on the stack. More...
 
void pushObject (void *object)
 Push a new object to the object-stack. More...
 
void resetFunction ()
 Sets the functor to nullptr (which also deactivates the command). More...
 
bool setFunction (const ExecutorPtr &executor, bool bForce=false)
 Changes the executor. More...
 
bool setFunction (const FunctorPtr &functor, bool bForce=false)
 Changes the functor of the current executor. More...
 
bool setObject (void *object)
 Changes the current object that is used to execute member-functions. More...
 

Private Attributes

AccessLevel accessLevel_
 The access level (the state of the game in which you can access the command) More...
 
ArgumentCompleterargumentCompleter_ [MAX_FUNCTOR_ARGUMENTS]
 ArgumentCompleter for each argument. More...
 
bool bActive_
 True if the command should be active (it can still be inactive, for example if the function is missing) More...
 
FunctorPtr baseFunctor_
 The functor that defines the header of the command-function. More...
 
std::string baseName_
 The name that was first assigned to the command. More...
 
bool bHidden_
 True if the command is hidden (it is still executable, but not visible in the list of available commands) More...
 
std::stack< CommandcommandStack_
 A stack of commands, used to push and pop different functions. More...
 
LanguageEntryLabel description_
 The description of the command. More...
 
LanguageEntryLabel descriptionParam_ [MAX_FUNCTOR_ARGUMENTS]
 A description for each argument. More...
 
LanguageEntryLabel descriptionReturnvalue_
 A description of the return-value. More...
 
ExecutorPtr executor_
 The Executor that is used to execute the command. More...
 
int inputConfiguredParam_
 The input configured param. More...
 
KeybindMode::Value keybindMode_
 The keybind mode. More...
 
std::vector< CommandNamenames_
 All names and aliases of this command. More...
 
std::vector< void * > objectStack_
 A stack of objects, used to push and pop different objects for a function. More...
 

Friends

struct ConsoleCommandManipulator
 

Detailed Description

The ConsoleCommand class stores all information about a console command which can be executed by CommandExecutor.

Console commands can be entered by the user into the shell, called in scripts, or used for key-bindings. They are simple text strings that can be executed by CommandExecutor. CommandExecutor will search for a ConsoleCommand with the given group and name and will execute it's Executor (which again calls the Functor and this finally calls the command-function).

See also
See ConsoleCommand.h for more information and some examples.

Constructor & Destructor Documentation

orxonox::ConsoleCommand::ConsoleCommand ( const std::string &  name,
const ExecutorPtr executor,
bool  bInitialized = true 
)

Constructor: Initializes all values and registers the command (without a group).

Parameters
nameThe name of the command
executorThe executor of the command
bInitializedIf true, the executor is used for both, the definition of the function-header AND to executute the command. If false, the command is inactive and needs to be assigned a function before it can be used.
orxonox::ConsoleCommand::ConsoleCommand ( const std::string &  group,
const std::string &  name,
const ExecutorPtr executor,
bool  bInitialized = true 
)

Constructor: Initializes all values and registers the command (with a group).

Parameters
groupThe group of the command
nameThe name of the command
executorThe executor of the command
bInitializedIf true, the executor is used for both, the definition of the function-header AND to executute the command. If false, the command is inactive and needs to be assigned a function before it can be used.
orxonox::ConsoleCommand::~ConsoleCommand ( )

Destructor: Unregisters the command.

Member Function Documentation

ConsoleCommand& orxonox::ConsoleCommand::accessLevel ( AccessLevel  level)
inline

Changes the access level of the command.

ConsoleCommand& orxonox::ConsoleCommand::activate ( )
inline

Activates the command.

ConsoleCommand & orxonox::ConsoleCommand::addGroup ( const std::string &  group)

Registers the command in a different group but with the same name.

ConsoleCommand & orxonox::ConsoleCommand::addGroup ( const std::string &  group,
const std::string &  name 
)

Registers an alias of the command in a different group with a different name.

ConsoleCommand & orxonox::ConsoleCommand::addShortcut ( )

Registers the command with the same name, but without group, as shortcut.

ConsoleCommand & orxonox::ConsoleCommand::addShortcut ( const std::string &  name)

Registers the command with an alias as shortcut.

ConsoleCommand & orxonox::ConsoleCommand::argumentCompleter ( unsigned int  index,
ArgumentCompleter completer 
)

Changes the argument completer for the given argument.

Parameters
indexThe index of the argument (the first argument has index 0)
completerThe new argument completer
ConsoleCommand & orxonox::ConsoleCommand::changeKeybindMode ( KeybindMode::Value  mode)

Changes the keybind mode.

ConsoleCommand& orxonox::ConsoleCommand::deactivate ( )
inline

Deactivates the command.

ConsoleCommand & orxonox::ConsoleCommand::defaultValue ( unsigned int  index,
const MultiType arg 
)

Changes the default value of the argument with given index of the current executor.

Parameters
indexThe index of the argument (the first argument has index 0)
argThe new default value
ConsoleCommand & orxonox::ConsoleCommand::defaultValues ( const MultiType arg1)

Changes the default values of the current executor.

ConsoleCommand & orxonox::ConsoleCommand::defaultValues ( const MultiType arg1,
const MultiType arg2 
)

Changes the default values of the current executor.

ConsoleCommand & orxonox::ConsoleCommand::defaultValues ( const MultiType arg1,
const MultiType arg2,
const MultiType arg3 
)

Changes the default values of the current executor.

ConsoleCommand & orxonox::ConsoleCommand::defaultValues ( const MultiType arg1,
const MultiType arg2,
const MultiType arg3,
const MultiType arg4 
)

Changes the default values of the current executor.

ConsoleCommand & orxonox::ConsoleCommand::defaultValues ( const MultiType arg1,
const MultiType arg2,
const MultiType arg3,
const MultiType arg4,
const MultiType arg5 
)

Changes the default values of the current executor.

ConsoleCommand & orxonox::ConsoleCommand::description ( const std::string &  description)

Sets the description of this command.

ConsoleCommand & orxonox::ConsoleCommand::descriptionParam ( unsigned int  index,
const std::string &  description 
)

Sets the description for an argument with given index.

ConsoleCommand & orxonox::ConsoleCommand::descriptionReturnvalue ( const std::string &  description)

Sets the description for the return-value.

AccessLevel orxonox::ConsoleCommand::getAccessLevel ( ) const
inline

Returns the access level of the command.

ArgumentCompleter * orxonox::ConsoleCommand::getArgumentCompleter ( unsigned int  index) const

Returns the argument completer for the argument with given index.

const FunctorPtr& orxonox::ConsoleCommand::getBaseFunctor ( ) const
inline

Returns the functor that defines the required header for this command (but isn't necessarily executed).

const std::string & orxonox::ConsoleCommand::getDescription ( ) const

Returns the description of this command.

const std::string & orxonox::ConsoleCommand::getDescriptionParam ( unsigned int  index) const

Returns the description for the argument with given index.

const std::string & orxonox::ConsoleCommand::getDescriptionReturnvalue ( int  index) const

Returns the description for the return-value.

const ExecutorPtr & orxonox::ConsoleCommand::getExecutor ( ) const

Returns the current executor which can be used to execute the command.

int orxonox::ConsoleCommand::getInputConfiguredParam ( ) const
inline

Returns the input configured param.

KeybindMode::Value orxonox::ConsoleCommand::getKeybindMode ( ) const
inline

Returns the keybind mode.

ConsoleCommandManipulator orxonox::ConsoleCommand::getManipulator ( )
inline

Returns a manipulator for this command.

const std::string& orxonox::ConsoleCommand::getName ( void  ) const
inline

Returns the name that was first used for this command.

const std::vector<CommandName>& orxonox::ConsoleCommand::getNames ( )
inline
void * orxonox::ConsoleCommand::getObject ( ) const
private

Returns the current object pointer that is used to execute member-functions.

bool orxonox::ConsoleCommand::hasAccess ( ) const

Returns true if the current state of the game matches the required access level.

bool orxonox::ConsoleCommand::headersMatch ( const FunctorPtr functor)
private

Returns true if the headers of the given functor match the declaration of this command.

bool orxonox::ConsoleCommand::headersMatch ( const ExecutorPtr executor)
private

Returns true if the headers of the given executor match the declaration of this command.

ConsoleCommand& orxonox::ConsoleCommand::hide ( )
inline

Hides the command (can still be executed, but is not visible in the list of available commands).

void orxonox::ConsoleCommand::init ( const std::string &  group,
const std::string &  name,
const ExecutorPtr executor,
bool  bInitialized 
)
private
ConsoleCommand& orxonox::ConsoleCommand::inputConfiguredParam ( int  index)
inline

Changes the input configured param to the given index.

bool orxonox::ConsoleCommand::isActive ( void  ) const

Returns true if the command can be executed right now.

This returns only true, if the following conditions are met:

  • The command is active
  • The command has an executor
  • The executor has a functor
  • The functor is static or has an object
bool orxonox::ConsoleCommand::isHidden ( ) const
inline

Returns true if the command is currently hidden.

ConsoleCommand& orxonox::ConsoleCommand::keybindMode ( KeybindMode::Value  mode)
inline

Sets the keybind mode. Note: use changeKeybindMode if you intend to change the mode.

void orxonox::ConsoleCommand::popFunction ( )
private

Removes the current function from the stack and restores the old state.

void orxonox::ConsoleCommand::popObject ( )
private

Removes the current object from the stack an restores the old object.

void orxonox::ConsoleCommand::pushFunction ( const ExecutorPtr executor,
bool  bForce = false 
)
private

Pushes a new executor to the command-stack.

Parameters
executorThe new executor
bForceIf true, the executor is always assigned, even if the headers don't match
void orxonox::ConsoleCommand::pushFunction ( const FunctorPtr functor,
bool  bForce = false 
)
private

Pushes a new functor to the command-stack.

Parameters
functorThe new functor
bForceIf true, the functor is always assigned, even if the headers don't match
void orxonox::ConsoleCommand::pushFunction ( )
private

Pushes a copy of the current executor and functor on the stack.

void orxonox::ConsoleCommand::pushObject ( void object)
private

Push a new object to the object-stack.

void orxonox::ConsoleCommand::resetFunction ( )
private

Sets the functor to nullptr (which also deactivates the command).

ConsoleCommand& orxonox::ConsoleCommand::setActive ( bool  bActive)
inline

Changes the activity of the command.

ConsoleCommand& orxonox::ConsoleCommand::setAsInputCommand ( )
inline

Defines the command to be an input command.

bool orxonox::ConsoleCommand::setFunction ( const ExecutorPtr executor,
bool  bForce = false 
)
private

Changes the executor.

Parameters
executorThe new executor
bForceIf true, the executor is always assigned, even if the headers don't match
Returns
Returns true if the assignment was successful
bool orxonox::ConsoleCommand::setFunction ( const FunctorPtr functor,
bool  bForce = false 
)
private

Changes the functor of the current executor.

Parameters
functorThe new functor
bForceIf true, the functor is always assigned, even if the headers don't match
Returns
Returns true if the assignment was successful
ConsoleCommand& orxonox::ConsoleCommand::setHidden ( bool  bHidden)
inline

Changes the visibility of the command.

bool orxonox::ConsoleCommand::setObject ( void object)
private

Changes the current object that is used to execute member-functions.

Returns
Returns true if the object was successfully changed
ConsoleCommand& orxonox::ConsoleCommand::show ( )
inline

Makes the command visible.

Friends And Related Function Documentation

friend struct ConsoleCommandManipulator
friend

Member Data Documentation

AccessLevel orxonox::ConsoleCommand::accessLevel_
private

The access level (the state of the game in which you can access the command)

ArgumentCompleter* orxonox::ConsoleCommand::argumentCompleter_[MAX_FUNCTOR_ARGUMENTS]
private

ArgumentCompleter for each argument.

bool orxonox::ConsoleCommand::bActive_
private

True if the command should be active (it can still be inactive, for example if the function is missing)

FunctorPtr orxonox::ConsoleCommand::baseFunctor_
private

The functor that defines the header of the command-function.

std::string orxonox::ConsoleCommand::baseName_
private

The name that was first assigned to the command.

bool orxonox::ConsoleCommand::bHidden_
private

True if the command is hidden (it is still executable, but not visible in the list of available commands)

std::stack<Command> orxonox::ConsoleCommand::commandStack_
private

A stack of commands, used to push and pop different functions.

LanguageEntryLabel orxonox::ConsoleCommand::description_
private

The description of the command.

LanguageEntryLabel orxonox::ConsoleCommand::descriptionParam_[MAX_FUNCTOR_ARGUMENTS]
private

A description for each argument.

LanguageEntryLabel orxonox::ConsoleCommand::descriptionReturnvalue_
private

A description of the return-value.

ExecutorPtr orxonox::ConsoleCommand::executor_
private

The Executor that is used to execute the command.

int orxonox::ConsoleCommand::inputConfiguredParam_
private

The input configured param.

KeybindMode::Value orxonox::ConsoleCommand::keybindMode_
private

The keybind mode.

std::vector<CommandName> orxonox::ConsoleCommand::names_
private

All names and aliases of this command.

std::vector<void*> orxonox::ConsoleCommand::objectStack_
private

A stack of objects, used to push and pop different objects for a function.


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