]> git.mxchange.org Git - simgear.git/blobdiff - simgear/structure/commands.cxx
Some Linux platforms need <cstdio> for snprintf.
[simgear.git] / simgear / structure / commands.cxx
index f293c16b264324ec344d93eaa53f1f3a7cfb0089..752f880c2ad13c60eb36f63e987516a8e77d4854 100644 (file)
@@ -9,6 +9,8 @@
 #endif
 
 #include <memory>
+#include <cassert>
+
 #include <simgear/props/props_io.hxx>
 
 #include "commands.hxx"
 // Implementation of SGCommandMgr class.
 ////////////////////////////////////////////////////////////////////////
 
+static SGCommandMgr* static_instance = NULL;
 
 SGCommandMgr::SGCommandMgr ()
 {
-  // no-op
+    assert(static_instance == NULL);
+    static_instance = this;
 }
 
 SGCommandMgr::~SGCommandMgr ()
 {
-  // no-op
+    assert(static_instance == this);
+    static_instance = NULL;
 }
 
-SGMutex SGCommandMgr::_instanceMutex;
-
 SGCommandMgr*
 SGCommandMgr::instance()
 {
-  static std::auto_ptr<SGCommandMgr> mgr;
-  if (mgr.get())
-    return mgr.get();
-
-  SGGuard<SGMutex> lock(_instanceMutex);
-  if (mgr.get())
-    return mgr.get();
-
-  mgr = std::auto_ptr<SGCommandMgr>(new SGCommandMgr);
-  return mgr.get();
+    return static_instance ? static_instance : new SGCommandMgr;
 }
 
 void
@@ -126,4 +120,15 @@ SGCommandMgr::execute (const std::string &name, const SGPropertyNode * arg) cons
   return false;
 }
 
+bool SGCommandMgr::removeCommand(const std::string& name)
+{
+    command_map::iterator it = _commands.find(name);
+    if (it == _commands.end())
+        return false;
+    
+    delete it->second;
+    _commands.erase(it);
+    return true;
+}
+
 // end of commands.cxx