]> git.mxchange.org Git - simgear.git/blob - simgear/misc/commands.cxx
Patch from Tony Peden to remove unused variable and eliminate compiler
[simgear.git] / simgear / misc / 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 "commands.hxx"
8 #include "props_io.hxx"
9
10
11 \f
12 ////////////////////////////////////////////////////////////////////////
13 // Implementation of SGCommandState class.
14 ////////////////////////////////////////////////////////////////////////
15
16 SGCommandState::SGCommandState ()
17   : _args(0)
18 {
19 }
20
21 SGCommandState::SGCommandState (const SGPropertyNode * args)
22   : _args(0)
23 {
24   setArgs(args);
25 }
26
27 SGCommandState::~SGCommandState ()
28 {
29   delete _args;
30 }
31
32 void
33 SGCommandState::setArgs (const SGPropertyNode * args)
34 {
35   delete _args;
36   _args = new SGPropertyNode();
37   copyProperties(args, _args);
38 }
39
40
41 \f
42 ////////////////////////////////////////////////////////////////////////
43 // Implementation of SGCommandMgr class.
44 ////////////////////////////////////////////////////////////////////////
45
46
47 SGCommandMgr::SGCommandMgr ()
48 {
49   // no-op
50 }
51
52 SGCommandMgr::~SGCommandMgr ()
53 {
54   // no-op
55 }
56
57 void
58 SGCommandMgr::addCommand (const string &name, command_t command)
59 {
60   _commands[name] = command;
61 }
62
63 SGCommandMgr::command_t
64 SGCommandMgr::getCommand (const string &name) const
65 {
66   const command_map::const_iterator it = _commands.find(name);
67   return (it != _commands.end() ? it->second : 0);
68 }
69
70 vector<string>
71 SGCommandMgr::getCommandNames () const
72 {
73   vector<string> names;
74   command_map::const_iterator it = _commands.begin();
75   command_map::const_iterator last = _commands.end();
76   while (it != last) {
77     names.push_back(it->first);
78     it++;
79   }
80   return names;
81 }
82
83 bool
84 SGCommandMgr::execute (const string &name, const SGPropertyNode * arg,
85                        SGCommandState ** state) const
86 {
87   command_t command = getCommand(name);
88   if (command == 0)
89     return false;
90   else
91     return (*command)(arg, state);
92 }
93
94
95 // bool
96 // SGCommandMgr::execute (const string &name) const
97 // {
98 //                              // FIXME
99 //   SGPropertyNode node;
100 //   return execute(name, &node);
101 // }
102
103
104 // bool
105 // SGCommandMgr::execute (const string &name, bool value) const
106 // {
107 //                              // FIXME
108 //   SGPropertyNode node;
109 //   node.setBoolValue(value);
110 //   return execute(name, &node);
111 // }
112
113
114 // bool
115 // SGCommandMgr::execute (const string &name, int value) const
116 // {
117 //                              // FIXME
118 //   SGPropertyNode node;
119 //   node.setIntValue(value);
120 //   return execute(name, &node);
121 // }
122
123
124 // bool
125 // SGCommandMgr::execute (const string &name, long value) const
126 // {
127 //                              // FIXME
128 //   SGPropertyNode node;
129 //   node.setLongValue(value);
130 //   return execute(name, &node);
131 // }
132
133
134 // bool
135 // SGCommandMgr::execute (const string &name, float value) const
136 // {
137 //                              // FIXME
138 //   SGPropertyNode node;
139 //   node.setFloatValue(value);
140 //   return execute(name, &node);
141 // }
142
143
144 // bool
145 // SGCommandMgr::execute (const string &name, double value) const
146 // {
147 //                              // FIXME
148 //   SGPropertyNode node;
149 //   node.setDoubleValue(value);
150 //   return execute(name, &node);
151 // }
152
153
154 // bool
155 // SGCommandMgr::execute (const string &name, string value) const
156 // {
157 //                              // FIXME
158 //   SGPropertyNode node;
159 //   node.setStringValue(value);
160 //   return execute(name, &node);
161 // }
162
163
164 // end of commands.cxx