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>
10 #include <OpenThreads/Mutex>
11 #include <OpenThreads/ScopedLock>
13 #include "commands.hxx"
17 ////////////////////////////////////////////////////////////////////////
18 // Implementation of SGCommandMgr class.
19 ////////////////////////////////////////////////////////////////////////
22 SGCommandMgr::SGCommandMgr ()
27 SGCommandMgr::~SGCommandMgr ()
32 OpenThreads::Mutex SGCommandMgr::_instanceMutex;
35 SGCommandMgr::instance()
37 static std::auto_ptr<SGCommandMgr> mgr;
41 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_instanceMutex);
45 mgr = std::auto_ptr<SGCommandMgr>(new SGCommandMgr);
50 SGCommandMgr::addCommand (const string &name, command_t command)
52 _commands[name] = command;
55 SGCommandMgr::command_t
56 SGCommandMgr::getCommand (const string &name) const
58 const command_map::const_iterator it = _commands.find(name);
59 return (it != _commands.end() ? it->second : 0);
63 SGCommandMgr::getCommandNames () const
66 command_map::const_iterator it = _commands.begin();
67 command_map::const_iterator last = _commands.end();
69 names.push_back(it->first);
76 SGCommandMgr::execute (const string &name, const SGPropertyNode * arg) const
78 command_t command = getCommand(name);
82 return (*command)(arg);
85 // end of commands.cxx