Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

LoopCommand.h

Go to the documentation of this file.
00001 //     $Id: LoopCommand.h,v 1.1.1.1 2001/01/04 01:01:11 burnett Exp $
00002 //  Author: Toby Burnett
00003 
00004 
00005 #ifndef LOOPCOMMAND_H
00006 #define LOOPCOMMAND_H
00007 
00008 #include "gui/Command.h"
00009 namespace gui {
00010 
00011 class LoopCommand : public Command {
00012     // Loops over a contained command.
00013     // It provides functions to control the loop, and will return 
00014     // <Command>> instances for each.
00015 public:
00016     LoopCommand(Command* command, long count);
00017     // Constructor has a <<Command>> to loop over for "count" times
00018 
00019     ~LoopCommand();
00020     // dtor - delete the command
00021 
00022     void setCount(long count){m_count = count;}
00023     // Set the loop count. It will have been set initially by the 
00024     // constructor.
00025 
00026     int getCount()const{return m_count;}
00027     // Return the loop count (includes those executed and those yet
00028     // to be done)
00029 
00030     int getCurrent()const{return m_current;}
00031     // Return the number of loops still to be executed
00032 
00033     void setCommand(Command* cmd){m_command =cmd;}
00034     // Set a new command
00035 
00036     void execute();
00037     // Start looping for the specified number of times.
00038 
00039     void pause();
00040     // Pause the loop
00041     
00042     void abort();
00043     // Abort the loop
00044 
00045     void resume();
00046     // Resume looping
00047 
00048     void stop();
00049     // Stop the loop  
00050  
00051     enum Status {STOPPED, RUNNING, PAUSED, ABORTED};
00052 
00053     Status status()const;
00054     // Access to the status. It may be STOPPED, RUNNING, PAUSED or ABORTED
00055 
00056     Command* abortCommand();
00057     // Return the command that will abort the loop
00058     
00059     Command* pauseCommand();
00060     // Return the command that will pause the loop
00061 
00062     Command* resumeCommand();
00063     // Return the command that will resume the loop
00064 
00065 private:
00066     class LCommand : public Command {
00067         // inner private class that defines simple commands affecting the loop itself  
00068         friend class LoopCommand;
00069         typedef void (LoopCommand::* Action)();
00070 
00071         LCommand(LoopCommand* r, Action a):
00072             _receiver(r), _action(a) {}
00073 
00074         virtual void execute(){ (_receiver->*_action)();}
00075 
00076         LoopCommand* _receiver;
00077         Action _action;
00078     };
00079 
00080     Command*  m_command; // the command to execute in the loop
00081     unsigned long      m_count;   // max loop count, set by constructor
00082     unsigned long      m_current; // loop counter: count up to the max
00083     Status    m_status;  // control start/stop
00084 };
00085 } //namespace dove
00086 #endif

Generated at Wed Nov 21 12:20:55 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000