00001 00002 //---------------------------------------------------------------------------------------------------------------- 00003 // Class definition include 00004 //---------------------------------------------------------------------------------------------------------------- 00005 #include "ComposedCommand.h" 00006 00007 //---------------------------------------------------------------------------------------------------------------- 00008 // Class implementation 00009 //---------------------------------------------------------------------------------------------------------------- 00012 //------------------------------------------------------------------------------------------------------------ 00013 // Constructors & Destructors 00014 //------------------------------------------------------------------------------------------------------------ 00015 00016 00017 ComposedCommand :: ComposedCommand( ) 00018 { 00019 00020 } 00021 00022 ComposedCommand :: ~ComposedCommand( ) 00023 { 00024 clear(); 00025 } 00026 00027 //------------------------------------------------------------------------------------------------------------ 00028 // Methods 00029 //------------------------------------------------------------------------------------------------------------ 00030 00031 /* 00032 * Adds a command to the list of command 00033 * @param nwCommand Is the new command to include 00034 */ 00035 void ComposedCommand :: addCommand(CommandObject * nwCommand) 00036 { 00037 internalCommands.push_back(nwCommand); 00038 } 00039 00040 /* 00041 * Virtual method implentation that includes the commands list into the given queue for execution 00042 * @param executionQueue Is the queue in which is included the command 00043 */ 00044 void ComposedCommand :: includeToExecute(std::deque<CommandObject* > &executionQueue) 00045 { 00046 std::deque<CommandObject *>::iterator actualCommandIter = internalCommands.end(); 00047 while( actualCommandIter != internalCommands.begin()) 00048 { 00049 (*actualCommandIter)->includeToExecute(executionQueue); 00050 actualCommandIter--; 00051 } 00052 } 00053 00054 /* 00055 * Virtual method implementation that returns 1 as the ExecutableCommand is just one command effective 00056 * @return The value of commands that represents this 00057 */ 00058 int ComposedCommand :: count() 00059 { 00060 int count = 0; 00061 int i =0; 00062 while( i<internalCommands.size() ) 00063 { 00064 count += internalCommands[i]->count(); 00065 i++; 00066 } 00067 return count; 00068 } 00069 00070 /* 00071 * Virtual method implentation that that clears the commands inside the composed command calling each one to clean it self 00072 */ 00073 void ComposedCommand :: clear() 00074 { 00075 while( internalCommands.size()>0 ) 00076 { 00077 internalCommands.back()->clear(); 00078 internalCommands.pop_back(); 00079 } 00080 internalCommands.clear(); 00081 } 00082 00083