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);
94 // end of commands.cxx