1 // commands.cxx - encapsulated commands.
2 // Started Spring 2001 by David Megginson, david@megginson.com
3 // This code is released into the Public Domain.
7 #include "commands.hxx"
11 ////////////////////////////////////////////////////////////////////////
12 // Implementation of SGCommandState class.
13 ////////////////////////////////////////////////////////////////////////
15 SGCommandState::SGCommandState ()
20 SGCommandState::SGCommandState (const SGPropertyNode * args)
26 SGCommandState::~SGCommandState ()
32 SGCommandState::setArgs (const SGPropertyNode * args)
35 _args = new SGPropertyNode();
36 copyProperties(args, _args);
41 ////////////////////////////////////////////////////////////////////////
42 // Implementation of SGCommandMgr class.
43 ////////////////////////////////////////////////////////////////////////
46 SGCommandMgr::SGCommandMgr ()
51 SGCommandMgr::~SGCommandMgr ()
57 SGCommandMgr::addCommand (const string &name, command_t command)
59 _commands[name] = command;
62 SGCommandMgr::command_t
63 SGCommandMgr::getCommand (const string &name) const
65 const command_map::const_iterator it = _commands.find(name);
66 return (it != _commands.end() ? it->second : 0);
70 SGCommandMgr::getCommandNames () const
73 command_map::const_iterator it = _commands.begin();
74 command_map::const_iterator last = _commands.end();
76 names.push_back(it->first);
83 SGCommandMgr::execute (const string &name, const SGPropertyNode * arg,
84 SGCommandState ** state) const
86 command_t command = getCommand(name);
90 return (*command)(arg, state);
95 // SGCommandMgr::execute (const string &name) const
98 // SGPropertyNode node;
99 // return execute(name, &node);
104 // SGCommandMgr::execute (const string &name, bool value) const
107 // SGPropertyNode node;
108 // node.setBoolValue(value);
109 // return execute(name, &node);
114 // SGCommandMgr::execute (const string &name, int value) const
117 // SGPropertyNode node;
118 // node.setIntValue(value);
119 // return execute(name, &node);
124 // SGCommandMgr::execute (const string &name, long value) const
127 // SGPropertyNode node;
128 // node.setLongValue(value);
129 // return execute(name, &node);
134 // SGCommandMgr::execute (const string &name, float value) const
137 // SGPropertyNode node;
138 // node.setFloatValue(value);
139 // return execute(name, &node);
144 // SGCommandMgr::execute (const string &name, double value) const
147 // SGPropertyNode node;
148 // node.setDoubleValue(value);
149 // return execute(name, &node);
154 // SGCommandMgr::execute (const string &name, string value) const
157 // SGPropertyNode node;
158 // node.setStringValue(value);
159 // return execute(name, &node);
163 // end of commands.cxx