#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;
}
void
#include <string>
#include <map>
-#include <simgear/threads/SGThread.hxx>
#include <simgear/math/sg_types.hxx>
// forward decls
}
public:
-
+ /**
+ * Default constructor (sets instance to created item)
+ */
+ SGCommandMgr ();
/**
- * Destructor.
+ * Destructor. (sets instance to NULL)
*/
virtual ~SGCommandMgr ();
- /**
- * Implement the classical singleton.
- */
static SGCommandMgr* instance();
/**
*/
bool removeCommand(const std::string& name);
protected:
- /**
- * Default constructor.
- */
- SGCommandMgr ();
+
private:
typedef std::map<std::string,Command*> command_map;
command_map _commands;
- static SGMutex _instanceMutex;
-
};
#endif // __COMMANDS_HXX