Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

CommandQueue.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 #include "CommandQueue.h"
00010 
00011 #include "Command.h"
00012 
00013 //-----------------------------------------------------------------
00014 CommandQueue::CommandQueue()
00015 {
00016     m_count = 0;
00017 }
00018 //-----------------------------------------------------------------
00019 /**
00020  * Remove all commands.
00021  */
00022 CommandQueue::~CommandQueue()
00023 {
00024     removeAll();
00025 }
00026 //-----------------------------------------------------------------
00027 /**
00028  * Add new command at the end of queue.
00029  */
00030 void
00031 CommandQueue::planCommand(Command *new_command)
00032 {
00033     m_commands.push_back(new_command);
00034 }
00035 //-----------------------------------------------------------------
00036 /**
00037  * Execute first command.
00038  * Execute none command when queue is empty.
00039  * If the command returns true, remove him from queue.
00040  * @return true when a command was executed
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  * Remove all commands.
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 

Generated on Wed Jun 1 09:54:30 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2