00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "CommandHandler.h"
00021 #include "Stream.h"
00022
00023 namespace mdw
00024 {
00025
00026 CommandHandler::CommandHandler()
00027 {
00028 }
00029
00030
00031 CommandHandler::~CommandHandler()
00032 {
00033 }
00034
00035 CommandHandler *CommandHandler::getHandler (const std::string &subHandler)
00036 {
00037 std::map<std::string, CommandHandler*>::iterator aIter = _subCommands.find(subHandler);
00038 if (aIter == _subCommands.end())
00039 {
00040 return 0;
00041 }
00042 return aIter->second;
00043 }
00044
00045 void CommandHandler::execute (const std::vector<std::string> args, int startArgs, Stream &output)
00046 {
00047 output << "Incomplete command : ";
00048 for (std::vector<std::string>::const_iterator aIter = args.begin();
00049 aIter != args.end();
00050 ++aIter)
00051 {
00052 output << *aIter << " ";
00053 }
00054 output << endl;
00055 }
00056
00057 CommandHandler &CommandHandler::createNode (const std::string &subHandler, CommandHandler *handler)
00058 {
00059 std::map<std::string, CommandHandler*>::iterator aIter = _subCommands.find(subHandler);
00060 if (aIter == _subCommands.end())
00061 {
00062 if (handler == 0)
00063 {
00064 handler = new CommandHandler();
00065 }
00066
00067 _subCommands.insert(make_pair(subHandler, handler));
00068 }
00069 else
00070 {
00071 if (handler != 0)
00072 {
00073 for (std::map<std::string, CommandHandler*>::iterator aIter = aIter->second->_subCommands.begin();
00074 aIter != aIter->second->_subCommands.end();
00075 ++aIter)
00076 {
00077 handler->_subCommands.insert(*aIter);
00078 }
00079 _subCommands.insert(make_pair(subHandler, handler));
00080 }
00081 }
00082 return *handler;
00083 }
00084 }