#include <string>
#include <map>
-#include <simgear/threads/SGThread.hxx>
#include <simgear/math/sg_types.hxx>
// forward decls
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 >
* Helper template functions.
*/
- template< typename Fun >
- Command* make_functor( const Fun* fun )
- {
- return new FunctionCommand<Fun>(fun);
- }
-
template< class ObjPtr, typename MemFn >
Command* make_functor( const ObjPtr& pObj, MemFn pMemFn )
{
}
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();
/**
* a bool result. The argument is always a const pointer to
* an SGPropertyNode (which may contain multiple values).
*/
- template<typename FUNC>
- 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<class OBJ, typename METHOD>
void addCommand(const std::string& name, const OBJ& o, METHOD m)
{
- addCommand(name, make_functor(o,m));
+ addCommandObject(name, make_functor(o,m));
}
/**
*/
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:
typedef std::map<std::string,Command*> command_map;
command_map _commands;
- static SGMutex _instanceMutex;
-
};
#endif // __COMMANDS_HXX