progress_meter.H

00001 /*
00002  * This file is part of the "Archon" framework.
00003  * (http://files3d.sourceforge.net)
00004  *
00005  * Copyright © 2002 by Kristian Spangsege and Brian Kristiansen.
00006  *
00007  * Permission to use, copy, modify, and distribute this software and
00008  * its documentation under the terms of the GNU General Public License is
00009  * hereby granted. No representations are made about the suitability of
00010  * this software for any purpose. It is provided "as is" without express
00011  * or implied warranty. See the GNU General Public License
00012  * (http://www.gnu.org/copyleft/gpl.html) for more details.
00013  *
00014  * The characters in this file are ISO8859-1 encoded.
00015  *
00016  * The documentation in this file is in "Doxygen" style
00017  * (http://www.doxygen.org).
00018  */
00019 
00020 #ifndef UTILITIES_PROGRESS_METER_H
00021 #define UTILITIES_PROGRESS_METER_H
00022 
00023 // ANSI-C++ headers:
00024 #include <string>
00025 
00026 namespace Archon
00027 {
00028   namespace Utilities
00029   {
00030     struct ProgressBase
00031     {
00032       /*
00033        * Place the call to this method after each unit of work.
00034        * That is, if the work units are the iterations of a loop
00035        * then the call should be placed as the very last thing in the loop.
00036        */
00037       void tick() { if(++skippedWorkUnits == workUnitsPerUpdate) update(); }
00038 
00039     protected:
00040       const unsigned long totalWorkUnits;
00041       unsigned long completedWorkUnits;
00042       unsigned long updateTime;
00043 
00044       ProgressBase(unsigned long totalWorkUnits);
00045       virtual ~ProgressBase() {}
00046       virtual void display() = 0;
00047 
00048     private:
00049       static const unsigned long millisBetweenUpdates = 250;
00050       unsigned long skippedWorkUnits;
00051       unsigned long workUnitsPerUpdate;
00052 
00053       unsigned long getTimeInMilliSeconds();
00054       void update();
00055     };
00056 
00057     struct ProgressBar: ProgressBase
00058     {
00059       ProgressBar(unsigned long totalWorkUnits, int width = 60,
00060                   bool extraResolution = false, std::string leadText = ""):
00061         ProgressBase(totalWorkUnits), width(width),
00062         extraResolution(extraResolution), leadText(leadText) {}
00063 
00064       virtual ~ProgressBar() {}
00065 
00066     private:
00067       const int width;
00068       const bool extraResolution;
00069       const std::string leadText;
00070 
00071       void display();
00072     };
00073 
00074     struct ProgressStatus: ProgressBase
00075     {
00076       ProgressStatus(unsigned long totalWorkUnits, std::string leadText = ""):
00077         ProgressBase(totalWorkUnits), leadText(leadText), startTime(updateTime) {}
00078 
00079       virtual ~ProgressStatus() {}
00080 
00081     private:
00082       static const unsigned long millisUntilFirstTotalTimeEstimate = 2000;
00083       const std::string leadText;
00084       const unsigned long startTime;
00085 
00086       void display();
00087     };
00088   }
00089 }
00090 
00091 #endif // UTILITIES_PROGRESS_METER_H

Generated on Sun Jul 30 22:55:45 2006 for Archon by  doxygen 1.4.4