00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "CommandQueue.h"
00010
00011 #include "Command.h"
00012
00013
00014 CommandQueue::CommandQueue()
00015 {
00016 m_count = 0;
00017 }
00018
00019
00020
00021
00022 CommandQueue::~CommandQueue()
00023 {
00024 removeAll();
00025 }
00026
00027
00028
00029
00030 void
00031 CommandQueue::planCommand(Command *new_command)
00032 {
00033 m_commands.push_back(new_command);
00034 }
00035
00036
00037
00038
00039
00040
00041
00042 bool
00043 CommandQueue::executeFirst()
00044 {
00045 bool result = false;
00046 if (!m_commands.empty()) {
00047 Command *command = m_commands.front();
00048 if (command->finish(m_count)) {
00049 m_commands.pop_front();
00050 m_count = 0;
00051 delete command;
00052 }
00053 else {
00054 m_count++;
00055 }
00056 result = true;
00057 }
00058
00059 return result;
00060 }
00061
00062
00063
00064
00065 void
00066 CommandQueue::removeAll()
00067 {
00068 t_commands::iterator end = m_commands.end();
00069 for (t_commands::iterator i = m_commands.begin(); i != end; ++i) {
00070 delete (*i);
00071 }
00072 m_commands.clear();
00073 m_count = 0;
00074 }
00075