1 // commands.cxx - encapsulated commands.
2 // Started Spring 2001 by David Megginson, david@megginson.com
3 // This code is released into the Public Domain.
8 #include <simgear/props/props_io.hxx>
9 #include <simgear/threads/SGThread.hxx>
10 #include <simgear/threads/SGGuard.hxx>
12 #include "commands.hxx"
16 ////////////////////////////////////////////////////////////////////////
17 // Implementation of SGCommandMgr class.
18 ////////////////////////////////////////////////////////////////////////
21 SGCommandMgr::SGCommandMgr ()
26 SGCommandMgr::~SGCommandMgr ()
32 SGCommandMgr::instance()
34 static std::auto_ptr<SGCommandMgr> mgr;
39 SGGuard<SGMutex> guard(lock);
43 mgr = std::auto_ptr<SGCommandMgr>(new SGCommandMgr);
48 SGCommandMgr::addCommand (const string &name, command_t command)
50 _commands[name] = command;
53 SGCommandMgr::command_t
54 SGCommandMgr::getCommand (const string &name) const
56 const command_map::const_iterator it = _commands.find(name);
57 return (it != _commands.end() ? it->second : 0);
61 SGCommandMgr::getCommandNames () const
64 command_map::const_iterator it = _commands.begin();
65 command_map::const_iterator last = _commands.end();
67 names.push_back(it->first);
74 SGCommandMgr::execute (const string &name, const SGPropertyNode * arg) const
76 command_t command = getCommand(name);
80 return (*command)(arg);
83 // end of commands.cxx