]> git.mxchange.org Git - simgear.git/blobdiff - simgear/structure/commands.hxx
Fix PagedLOD for random objects.
[simgear.git] / simgear / structure / commands.hxx
index c03ef5dc1ca0a05ba56db0e509c1b607bb6e3f5f..7f4185ec421fad63aa33b4b5ae3f336dfc09baee 100644 (file)
@@ -16,7 +16,6 @@
 #include <string>
 #include <map>
 
-#include <simgear/threads/SGThread.hxx>
 #include <simgear/math/sg_types.hxx>
 
 // 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>(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<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));
   }
   
   /**
@@ -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<std::string,Command*> command_map;
   command_map _commands;
 
-  static SGMutex _instanceMutex;
-
 };
 
 #endif // __COMMANDS_HXX