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