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_config.h>
12 #include <simgear/props/props_io.hxx>
14 #include <OpenThreads/Mutex>
15 #include <OpenThreads/ScopedLock>
17 #include "commands.hxx"
19 #include <simgear/math/SGMath.hxx>
23 ////////////////////////////////////////////////////////////////////////
24 // Implementation of SGCommandMgr class.
25 ////////////////////////////////////////////////////////////////////////
28 SGCommandMgr::SGCommandMgr ()
33 SGCommandMgr::~SGCommandMgr ()
38 OpenThreads::Mutex SGCommandMgr::_instanceMutex;
41 SGCommandMgr::instance()
43 static std::auto_ptr<SGCommandMgr> mgr;
47 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_instanceMutex);
51 mgr = std::auto_ptr<SGCommandMgr>(new SGCommandMgr);
56 SGCommandMgr::addCommand (const string &name, command_t command)
58 _commands[name] = command;
61 SGCommandMgr::command_t
62 SGCommandMgr::getCommand (const string &name) const
64 const command_map::const_iterator it = _commands.find(name);
65 return (it != _commands.end() ? it->second : 0);
69 SGCommandMgr::getCommandNames () const
72 command_map::const_iterator it = _commands.begin();
73 command_map::const_iterator last = _commands.end();
75 names.push_back(it->first);
82 SGCommandMgr::execute (const string &name, const SGPropertyNode * arg) const
84 command_t command = getCommand(name);
88 return (*command)(arg);
91 // end of commands.cxx