Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages
hugin_base/appbase/ProgressDisplay.h
Go to the documentation of this file.00001 // -*- c-basic-offset: 4 -*- 00026 #ifndef _APPBASE_PROGRESSDISPLAY_H 00027 #define _APPBASE_PROGRESSDISPLAY_H 00028 00029 #include <iostream> 00030 #include <string> 00031 #include <vector> 00032 00033 #include <hugin_shared.h> 00034 #include <hugin_utils/utils.h> 00035 00036 00037 namespace AppBase { 00038 00042 class IMPEX ProgressDisplay 00043 { 00044 00045 // -- Task object -- 00046 00047 protected: 00048 00052 struct ProgressSubtask 00053 { 00055 std::string message; 00057 double maxProgress; 00059 double progressForParentTask; 00061 bool propagatesProgress; 00063 double progress; 00064 00065 public: 00066 00068 ProgressSubtask() { }; 00069 00071 ProgressSubtask(const std::string& message, 00072 const double& maxProgress, 00073 const double& progressForParentTask, 00074 const bool& propagatesProgress) 00075 : message(message), 00076 maxProgress(maxProgress), 00077 progressForParentTask(progressForParentTask), 00078 propagatesProgress(propagatesProgress), 00079 progress(0.0) 00080 {}; 00081 00083 inline bool measuresProgress() 00084 { return maxProgress != 0.0; }; 00085 00086 }; 00087 00088 00089 // -- Const/Destructors -- 00090 00091 protected: 00093 ProgressDisplay() 00094 : o_canceled(false), o_newSubtaskProgress(0), o_newSubtaskPropagates(true) 00095 {}; 00096 00097 public: 00099 virtual ~ProgressDisplay() {}; 00100 00101 00102 // -- task interface -- 00103 00104 protected: 00106 void startSubtaskWithTask(const ProgressSubtask& newSubtask); 00107 00108 public: 00110 void setParentProgressOfNewSubtasks(double subtaskTotalProgress, bool propagatesProgress = false); 00111 00113 void startSubtask(const std::string& message, 00114 const double& maxProgress, 00115 const double& progressForParentTask, 00116 const bool& propagatesProgress = false); 00117 00119 void startSubtask(const std::string& message, 00120 const double& maxProgress = 0); 00121 00123 void startSubtask(const double& maxProgress); 00124 00126 virtual void setSubtaskMessage(const std::string& message); 00127 00129 virtual std::string getSubtaskMessage() const; 00130 00132 virtual double getSubtaskMaxProgress() const; 00133 00135 virtual double getSubtaskProgress() const; 00136 00138 virtual void updateSubtaskProgress(const double& newValue); 00139 00141 virtual void increaseSubtaskProgressBy(const double& deltaValue); 00142 00144 virtual void finishSubtask(); 00145 00147 virtual bool wasCancelled(); 00148 00149 protected: 00151 virtual void cancelTask(); 00152 00153 00154 // -- callback interface -- 00155 00156 protected: 00160 virtual void updateProgressDisplay() =0; 00161 00165 virtual void subtaskStarted() 00166 { DEBUG_DEBUG("Subtask started."); }; 00167 00171 virtual void subtaskFinished() 00172 { DEBUG_DEBUG("Subtask finished."); }; 00173 00174 00175 // -- utility methods -- 00176 00177 protected: 00179 virtual void propagateProgress(const double& newProgress); 00180 00182 virtual ProgressSubtask& getCurrentSubtask() const; 00183 00185 virtual bool noSubtasksAvailable() const; 00186 00187 00188 // -- accessable variables -- 00189 00190 protected: 00192 std::vector<ProgressSubtask> o_subtasks; 00193 bool o_canceled; 00194 00196 double o_newSubtaskProgress; 00197 bool o_newSubtaskPropagates; 00198 00199 }; 00200 00201 00204 class IMPEX DummyProgressDisplay : public ProgressDisplay 00205 { 00206 public: 00208 DummyProgressDisplay() 00209 : ProgressDisplay() 00210 {}; 00211 00213 virtual ~DummyProgressDisplay() {}; 00214 00216 virtual void updateProgressDisplay() 00217 { }; 00218 protected: 00219 }; 00220 00223 class IMPEX StreamProgressDisplay : public ProgressDisplay 00224 { 00225 public: 00227 StreamProgressDisplay(std::ostream & o) 00228 : ProgressDisplay(), 00229 m_stream(o), 00230 m_printedLines(0), m_whizz("-\\|/"), m_whizzCount(0) 00231 {}; 00232 00234 virtual ~StreamProgressDisplay() {}; 00235 00237 virtual void updateProgressDisplay(); 00238 protected: 00239 std::ostream & m_stream; 00240 int m_printedLines; 00241 std::string m_whizz; 00242 int m_whizzCount; 00243 }; 00244 00245 00246 }; //namespace 00247 #endif // _H
1.3.9.1