]> git.mxchange.org Git - simgear.git/blob - simgear/structure/commands.cxx
Mathias Fröhlich:
[simgear.git] / simgear / structure / commands.cxx
1 // commands.cxx - encapsulated commands.
2 // Started Spring 2001 by David Megginson, david@megginson.com
3 // This code is released into the Public Domain.
4 //
5 // $Id$
6
7 #include <simgear/props/props_io.hxx>
8
9 #include "commands.hxx"
10
11
12 \f
13 ////////////////////////////////////////////////////////////////////////
14 // Implementation of SGCommandMgr class.
15 ////////////////////////////////////////////////////////////////////////
16
17
18 SGCommandMgr::SGCommandMgr ()
19 {
20   // no-op
21 }
22
23 SGCommandMgr::~SGCommandMgr ()
24 {
25   // no-op
26 }
27
28 void
29 SGCommandMgr::addCommand (const string &name, command_t command)
30 {
31   _commands[name] = command;
32 }
33
34 SGCommandMgr::command_t
35 SGCommandMgr::getCommand (const string &name) const
36 {
37   const command_map::const_iterator it = _commands.find(name);
38   return (it != _commands.end() ? it->second : 0);
39 }
40
41 vector<string>
42 SGCommandMgr::getCommandNames () const
43 {
44   vector<string> names;
45   command_map::const_iterator it = _commands.begin();
46   command_map::const_iterator last = _commands.end();
47   while (it != last) {
48     names.push_back(it->first);
49     it++;
50   }
51   return names;
52 }
53
54 bool
55 SGCommandMgr::execute (const string &name, const SGPropertyNode * arg) const
56 {
57   command_t command = getCommand(name);
58   if (command == 0)
59     return false;
60   else
61     return (*command)(arg);
62 }
63
64 // end of commands.cxx