head 1.4; access; symbols; locks; strict; comment @# @; 1.4 date 2002.09.07.01.50.35; author curt; state Exp; branches; next 1.3; 1.3 date 2002.08.31.19.01.50; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.18.53.58; author curt; state Exp; branches; next 1.1; 1.1 date 2002.02.15.17.21.54; author curt; state Exp; branches; next ; desc @@ 1.4 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# SGCommandMgr Class Reference

Manage commands. More...

`#include <commands.hxx>`

List of all members.

## Public Types
typedef bool(* | command_t )(const SGPropertyNode *arg, SGCommandState **state)
| Type for a command function.
## Public Methods
| SGCommandMgr ()
| Default constructor.
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, SGCommandState **state) const
| Execute a command.

## 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 and a pointer to a pointer variable (which should be 0 initially) where the function can store compiled copies of its arguments, etc. to avoid expensive recalculations. If the command deletes the SGCommandState, it must replace it with a new pointer or 0; otherwise, the caller is free to delete and zero the pointer at any time and the command will start fresh with the next invocation. The command must return a bool value indicating success or failure. The property node may be ignored, or it may contain values that the command uses as parameters.

There are convenience methods for invoking a command function with no arguments or with a single, primitive argument.

Author:
  David Megginson, david@@megginson.com

Definition at line 82 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 58 of file commands.cxx.

bool SGCommandMgr::execute | ( | const string & | name,
|  | const SGPropertyNode * | arg,
|  | SGCommandState ** | state
| ) | const`[virtual]`

  | Execute a command. This is the primary method for invoking a command; the others are convenience methods that invoke this one indirectly. 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 84 of file commands.cxx. References command_t, and getCommand().

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 64 of file commands.cxx. Referenced by execute().

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 71 of file commands.cxx.

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

- commands.hxx
- commands.cxx

@ 1.3 log @Oops, try again. @ text @d242 1 a242 1