SGCommandMgr Class Reference

Manage commands. More...

#include <commands.hxx>

List of all members.

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 SGCommandMgrinstance ()
 Implement the classical singleton.

Protected Member Functions

 SGCommandMgr ()
 Default constructor.

Detailed Description

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.

Author:
David Megginson, david@megginson.com

Definition at line 39 of file commands.hxx.


Member Function Documentation

void SGCommandMgr::addCommand ( const string &  name,
command_t  command 
) [virtual]

Register a new command with the manager.

Parameters:
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.

Parameters:
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.
Returns:
true if the command is present and executes successfully, false otherwise.

Definition at line 82 of file commands.cxx.

SGCommandMgr::command_t SGCommandMgr::getCommand ( const string &  name  )  const [virtual]

Look up an existing command.

Parameters:
name The command name.
Returns:
A pointer to the command, or 0 if there is no registered command with the name specified.

Definition at line 62 of file commands.cxx.

vector< string > SGCommandMgr::getCommandNames (  )  const [virtual]

Get a list of all existing command names.

Returns:
A (possibly empty) vector of the names of all registered commands.

Definition at line 69 of file commands.cxx.


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

Generated on 23 Feb 2010 for SimGear by  doxygen 1.6.1