#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
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