commands.cxx

00001 // commands.cxx - encapsulated commands.
00002 // Started Spring 2001 by David Megginson, david@megginson.com
00003 // This code is released into the Public Domain.
00004 //
00005 // $Id: commands_8cxx-source.html,v 1.8 2007-12-17 15:37:00 curt Exp $
00006 
00007 #include <simgear/props/props_io.hxx>
00008 
00009 #include "commands.hxx"
00010 
00011 
00012 
00014 // Implementation of SGCommandMgr class.
00016 
00017 
00018 SGCommandMgr::SGCommandMgr ()
00019 {
00020   // no-op
00021 }
00022 
00023 SGCommandMgr::~SGCommandMgr ()
00024 {
00025   // no-op
00026 }
00027 
00028 void
00029 SGCommandMgr::addCommand (const string &name, command_t command)
00030 {
00031   _commands[name] = command;
00032 }
00033 
00034 SGCommandMgr::command_t
00035 SGCommandMgr::getCommand (const string &name) const
00036 {
00037   const command_map::const_iterator it = _commands.find(name);
00038   return (it != _commands.end() ? it->second : 0);
00039 }
00040 
00041 vector<string>
00042 SGCommandMgr::getCommandNames () const
00043 {
00044   vector<string> names;
00045   command_map::const_iterator it = _commands.begin();
00046   command_map::const_iterator last = _commands.end();
00047   while (it != last) {
00048     names.push_back(it->first);
00049     it++;
00050   }
00051   return names;
00052 }
00053 
00054 bool
00055 SGCommandMgr::execute (const string &name, const SGPropertyNode * arg) const
00056 {
00057   command_t command = getCommand(name);
00058   if (command == 0)
00059     return false;
00060   else
00061     return (*command)(arg);
00062 }
00063 
00064 // end of commands.cxx

Generated on Mon Dec 17 09:30:54 2007 for SimGear by  doxygen 1.5.1