00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef UTILITIES_PROGRESS_METER_H
00021 #define UTILITIES_PROGRESS_METER_H
00022
00023
00024 #include <string>
00025
00026 namespace Archon
00027 {
00028 namespace Utilities
00029 {
00030 struct ProgressBase
00031 {
00032
00033
00034
00035
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