From: david Date: Sat, 26 Oct 2002 01:18:03 +0000 (+0000) Subject: Simplified the command-manager interface. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5178f69f1847f91832a97f8b6989e826213d82b2;p=simgear.git Simplified the command-manager interface. --- diff --git a/simgear/misc/commands.cxx b/simgear/misc/commands.cxx index 0b471651..88869848 100644 --- a/simgear/misc/commands.cxx +++ b/simgear/misc/commands.cxx @@ -8,36 +8,6 @@ #include "props_io.hxx" - -//////////////////////////////////////////////////////////////////////// -// Implementation of SGCommandState class. -//////////////////////////////////////////////////////////////////////// - -SGCommandState::SGCommandState () - : _args(0) -{ -} - -SGCommandState::SGCommandState (const SGPropertyNode * args) - : _args(0) -{ - setArgs(args); -} - -SGCommandState::~SGCommandState () -{ - delete _args; -} - -void -SGCommandState::setArgs (const SGPropertyNode * args) -{ - delete _args; - _args = new SGPropertyNode(); - copyProperties(args, _args); -} - - //////////////////////////////////////////////////////////////////////// // Implementation of SGCommandMgr class. @@ -81,14 +51,13 @@ SGCommandMgr::getCommandNames () const } bool -SGCommandMgr::execute (const string &name, const SGPropertyNode * arg, - SGCommandState ** state) const +SGCommandMgr::execute (const string &name, const SGPropertyNode * arg) const { command_t command = getCommand(name); if (command == 0) return false; else - return (*command)(arg, state); + return (*command)(arg); } // end of commands.cxx diff --git a/simgear/misc/commands.hxx b/simgear/misc/commands.hxx index 392120b2..55f193b4 100644 --- a/simgear/misc/commands.hxx +++ b/simgear/misc/commands.hxx @@ -24,58 +24,13 @@ SG_USING_STD(map); SG_USING_STD(vector); -/** - * Stored state for a command. - * - *

This class allows a command to cache parts of its state between - * invocations with the same parameters. Nearly every command that - * actually uses this will subclass it in some way. The command - * allocates the structure, but it is up to the caller to delete it - * when it is no longer necessary, unless the command deletes it - * and replaces the value with 0 or another command-state object - * first.

- * - *

Note that this class is for caching only; all of the information - * in it must be recoverable by other means, since the state could - * arbitrarily disappear between invocations if the caller decides to - * delete it.

- * - *

By default, the command state includes a place to keep a copy of - * the parameters.

- * - * @author David Megginson, david@megginson.com - */ -class SGCommandState -{ -public: - SGCommandState (); - SGCommandState (const SGPropertyNode * args); - virtual ~SGCommandState (); - virtual void setArgs (const SGPropertyNode * args); - virtual const SGPropertyNode * getArgs () const { return _args; } -private: - SGPropertyNode * _args; -}; - - /** * 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.

+ * 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 */ @@ -86,8 +41,7 @@ public: /** * Type for a command function. */ - typedef bool (*command_t) (const SGPropertyNode * arg, - SGCommandState ** state); + typedef bool (*command_t) (const SGPropertyNode * arg); /** @@ -136,9 +90,6 @@ public: /** * Execute a command. * - * This is the primary method for invoking a command; the others - * are convenience methods that invoke this one indirectly. - * * @param name The name of the command. * @param arg A const pointer to an SGPropertyNode. The node * may have a value and/or children, etc., so that it is possible @@ -146,9 +97,7 @@ public: * @return true if the command is present and executes successfully, * false otherwise. */ - virtual bool execute (const string &name, - const SGPropertyNode * arg, - SGCommandState ** state) const; + virtual bool execute (const string &name, const SGPropertyNode * arg) const; private: