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"
8 #include "props_io.hxx"
12 ////////////////////////////////////////////////////////////////////////
13 // Implementation of SGCommandState class.
14 ////////////////////////////////////////////////////////////////////////
16 SGCommandState::SGCommandState ()
21 SGCommandState::SGCommandState (const SGPropertyNode * args)
27 SGCommandState::~SGCommandState ()
33 SGCommandState::setArgs (const SGPropertyNode * args)
36 _args = new SGPropertyNode();
37 copyProperties(args, _args);
42 ////////////////////////////////////////////////////////////////////////
43 // Implementation of SGCommandMgr class.
44 ////////////////////////////////////////////////////////////////////////
47 SGCommandMgr::SGCommandMgr ()
52 SGCommandMgr::~SGCommandMgr ()
58 SGCommandMgr::addCommand (const string &name, command_t command)
60 _commands[name] = command;
63 SGCommandMgr::command_t
64 SGCommandMgr::getCommand (const string &name) const
66 const command_map::const_iterator it = _commands.find(name);
67 return (it != _commands.end() ? it->second : 0);
71 SGCommandMgr::getCommandNames () const
74 command_map::const_iterator it = _commands.begin();
75 command_map::const_iterator last = _commands.end();
77 names.push_back(it->first);
84 SGCommandMgr::execute (const string &name, const SGPropertyNode * arg,
85 SGCommandState ** state) const
87 command_t command = getCommand(name);
91 return (*command)(arg, state);
96 // SGCommandMgr::execute (const string &name) const
99 // SGPropertyNode node;
100 // return execute(name, &node);
105 // SGCommandMgr::execute (const string &name, bool value) const
108 // SGPropertyNode node;
109 // node.setBoolValue(value);
110 // return execute(name, &node);
115 // SGCommandMgr::execute (const string &name, int value) const
118 // SGPropertyNode node;
119 // node.setIntValue(value);
120 // return execute(name, &node);
125 // SGCommandMgr::execute (const string &name, long value) const
128 // SGPropertyNode node;
129 // node.setLongValue(value);
130 // return execute(name, &node);
135 // SGCommandMgr::execute (const string &name, float value) const
138 // SGPropertyNode node;
139 // node.setFloatValue(value);
140 // return execute(name, &node);
145 // SGCommandMgr::execute (const string &name, double value) const
148 // SGPropertyNode node;
149 // node.setDoubleValue(value);
150 // return execute(name, &node);
155 // SGCommandMgr::execute (const string &name, string value) const
158 // SGPropertyNode node;
159 // node.setStringValue(value);
160 // return execute(name, &node);
164 // end of commands.cxx