00001 /* 00002 * ProgressBar.h 00003 * 00004 * Created on: 14.01.2011 00005 * Author: Thomas Wiemann 00006 */ 00007 00008 #ifndef PROGRESSBAR_H_ 00009 #define PROGRESSBAR_H_ 00010 00011 #include <string> 00012 #include <sstream> 00013 #include <iostream> 00014 00015 using std::stringstream; 00016 using std::cout; 00017 using std::endl; 00018 using std::flush; 00019 using std::string; 00020 00021 #include <boost/thread/mutex.hpp> 00022 00023 namespace lssr{ 00024 00034 class ProgressBar 00035 { 00036 public: 00037 00044 ProgressBar(int max_val, string prefix = ""); 00045 00049 void operator++(); 00050 00051 protected: 00052 00054 void print_bar(); 00055 00057 string m_prefix; 00058 00060 size_t m_maxVal; 00061 00063 size_t m_currentVal; 00064 00066 size_t m_stepSize; 00067 00069 boost::mutex m_mutex; 00070 00072 int m_percent; 00073 00075 stringstream m_stream; 00076 00078 string m_fillstring; 00079 }; 00080 00081 00089 class ProgressCounter 00090 { 00091 public: 00092 00093 /*** 00094 * @brief CTor. 00095 * 00096 * @param stepVal After m_stepVal operations a new output is generated 00097 * @param prefix The prefix string for progress output 00098 */ 00099 ProgressCounter(int stepVal, string prefix = ""); 00100 00101 /*** 00102 * @brief Increase the progress counter 00103 */ 00104 void operator++(); 00105 00106 protected: 00107 00109 void print_progress(); 00110 00112 string m_prefix; 00113 00115 size_t m_stepVal; 00116 00118 size_t m_currentVal; 00119 00121 boost::mutex m_mutex; 00122 00124 stringstream m_stream; 00125 00127 string m_fillstring; 00128 }; 00129 00130 } // namespace lssr 00131 00132 #endif /* PROGRESSBAR_H_ */