X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2Fcommands.hxx;h=7f4185ec421fad63aa33b4b5ae3f336dfc09baee;hb=9da0031039bb534011591ce3bd6fede21030c345;hp=c03ef5dc1ca0a05ba56db0e509c1b607bb6e3f5f;hpb=b0063f8db67066c1ad4d9481c33b4627a1c51d3b;p=simgear.git diff --git a/simgear/structure/commands.hxx b/simgear/structure/commands.hxx index c03ef5dc..7f4185ec 100644 --- a/simgear/structure/commands.hxx +++ b/simgear/structure/commands.hxx @@ -16,7 +16,6 @@ #include #include -#include #include // forward decls @@ -45,17 +44,19 @@ public: virtual bool operator()(const SGPropertyNode * arg) = 0; }; + + typedef bool (*command_t) (const SGPropertyNode * arg); + private: - template< typename Fun > class FunctionCommand : public Command { public: - FunctionCommand( const Fun* fun ) + FunctionCommand( command_t fun ) : f_(fun) {} virtual bool operator()(const SGPropertyNode * arg) { return (*f_)(arg); } private: - Fun* f_; + command_t f_; }; template< class ObjPtr, typename MemFn > @@ -78,12 +79,6 @@ private: * Helper template functions. */ - template< typename Fun > - Command* make_functor( const Fun* fun ) - { - return new FunctionCommand(fun); - } - template< class ObjPtr, typename MemFn > Command* make_functor( const ObjPtr& pObj, MemFn pMemFn ) { @@ -91,38 +86,36 @@ private: } public: - - typedef bool (*command_t) (const SGPropertyNode * arg); + /** + * Default constructor (sets instance to created item) + */ + SGCommandMgr (); /** - * Destructor. + * Destructor. (sets instance to NULL) */ virtual ~SGCommandMgr (); - /** - * Implement the classical singleton. - */ static SGCommandMgr* instance(); /** * Register a new command with the manager. * - * @param name The command name. Any existing command with - * the same name will silently be overwritten. - * @param 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). + * @param name The command name. Any existing command with the same name + * will silently be overwritten. + * @param f 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). */ - template - void addCommand(const std::string& name, const FUNC* f) - { addCommand(name, make_functor(f)); } + void addCommand(const std::string& name, command_t f) + { addCommandObject(name, new FunctionCommand(f)); } - void addCommand (const std::string &name, Command* command); + void addCommandObject (const std::string &name, Command* command); template void addCommand(const std::string& name, const OBJ& o, METHOD m) { - addCommand(name, make_functor(o,m)); + addCommandObject(name, make_functor(o,m)); } /** @@ -156,11 +149,12 @@ public: */ virtual bool execute (const std::string &name, const SGPropertyNode * arg) const; -protected: /** - * Default constructor. + * Remove a command registration */ - SGCommandMgr (); + bool removeCommand(const std::string& name); +protected: + private: @@ -168,8 +162,6 @@ private: typedef std::map command_map; command_map _commands; - static SGMutex _instanceMutex; - }; #endif // __COMMANDS_HXX