Manage commands. More...
#include <commands.hxx>
Public Types | |
typedef bool(* | command_t )(const SGPropertyNode *arg) |
Type for a command function. | |
Public Member Functions | |
virtual | ~SGCommandMgr () |
Destructor. | |
virtual void | addCommand (const string &name, command_t command) |
Register a new command with the manager. | |
virtual command_t | getCommand (const string &name) const |
Look up an existing command. | |
virtual vector< string > | getCommandNames () const |
Get a list of all existing command names. | |
virtual bool | execute (const string &name, const SGPropertyNode *arg) const |
Execute a command. | |
Static Public Member Functions | |
static SGCommandMgr * | instance () |
Implement the classical singleton. | |
Protected Member Functions | |
SGCommandMgr () | |
Default constructor. |
Manage commands.
This class allows the application to register and unregister commands, and provides shortcuts for executing them. Commands are simple functions that take a const pointer to an SGPropertyNode: the function may use the nodes children as parameters.
Definition at line 39 of file commands.hxx.
void SGCommandMgr::addCommand | ( | const string & | name, | |
command_t | command | |||
) | [virtual] |
Register a new command with the manager.
name | The command name. Any existing command with the same name will silently be overwritten. | |
command | A pointer to a one-arg function returning a bool result. The argument is always a const pointer to an SGPropertyNode (which may contain multiple values). |
Definition at line 56 of file commands.cxx.
bool SGCommandMgr::execute | ( | const string & | name, | |
const SGPropertyNode * | arg | |||
) | const [virtual] |
Execute a command.
name | The name of the command. | |
arg | A const pointer to an SGPropertyNode. The node may have a value and/or children, etc., so that it is possible to pass an arbitrarily complex data structure to a command. |
Definition at line 82 of file commands.cxx.
SGCommandMgr::command_t SGCommandMgr::getCommand | ( | const string & | name | ) | const [virtual] |
Look up an existing command.
name | The command name. |
Definition at line 62 of file commands.cxx.
vector< string > SGCommandMgr::getCommandNames | ( | ) | const [virtual] |
Get a list of all existing command names.
Definition at line 69 of file commands.cxx.