head 1.4; access; symbols; locks; strict; comment @# @; 1.4 date 2002.09.07.01.50.37; author curt; state Exp; branches; next 1.3; 1.3 date 2002.08.31.19.01.53; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.18.54.00; author curt; state Exp; branches; next 1.1; 1.1 date 2002.02.15.17.21.55; author curt; state Exp; branches; next ; desc @@ 1.4 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# commands.cxx

    00001 // commands.cxx - encapsulated commands.
    00002 // Started Spring 2001 by David Megginson, david@@megginson.com
    00003 // This code is released into the Public Domain.
    00004 //
    00005 // $Id: commands.cxx,v 1.5 2002/03/22 13:18:49 david Exp $
    00006
    00007 #include "commands.hxx"
    00008 #include "props_io.hxx"
    00009
    00010
    00011
    00013 // Implementation of SGCommandState class.
    00015
    00016 SGCommandState::SGCommandState ()
    00017   : _args(0)
    00018 {
    00019 }
    00020
    00021 SGCommandState::SGCommandState (const SGPropertyNode * args)
    00022   : _args(0)
    00023 {
    00024   setArgs(args);
    00025 }
    00026
    00027 SGCommandState::~SGCommandState ()
    00028 {
    00029   delete _args;
    00030 }
    00031
    00032 void
    00033 SGCommandState::setArgs (const SGPropertyNode * args)
    00034 {
    00035   delete _args;
    00036   _args = new SGPropertyNode();
    00037   copyProperties(args, _args);
    00038 }
    00039
    00040
    00041
    00043 // Implementation of SGCommandMgr class.
    00045
    00046
    00047 SGCommandMgr::SGCommandMgr ()
    00048 {
    00049   // no-op
    00050 }
    00051
    00052 SGCommandMgr::~SGCommandMgr ()
    00053 {
    00054   // no-op
    00055 }
    00056
    00057 void
    00058 SGCommandMgr::addCommand (const string &name, command_t command)
    00059 {
    00060   _commands[name] = command;
    00061 }
    00062
    00063 SGCommandMgr::command_t
    00064 SGCommandMgr::getCommand (const string &name) const
    00065 {
    00066   const command_map::const_iterator it = _commands.find(name);
    00067   return (it != _commands.end() ? it->second : 0);
    00068 }
    00069
    00070 vector<string>
    00071 SGCommandMgr::getCommandNames () const
    00072 {
    00073   vector<string> names;
    00074   command_map::const_iterator it = _commands.begin();
    00075   command_map::const_iterator last = _commands.end();
    00076   while (it != last) {
    00077     names.push_back(it->first);
    00078     it++;
    00079   }
    00080   return names;
    00081 }
    00082
    00083 bool
    00084 SGCommandMgr::execute (const string &name, const SGPropertyNode * arg,
    00085                        SGCommandState ** state) const
    00086 {
    00087   command_t command = getCommand(name);
    00088   if (command == 0)
    00089     return false;
    00090   else
    00091     return (*command)(arg, state);
    00092 }
    00093
    00094 // end of commands.cxx

@ 1.3 log @Oops, try again. @ text @d99 1 a99 1