00001 #ifndef PROGRESSBAR_H 00002 #define PROGRESSBAR_H 00003 00004 #include <string> 00005 00006 class ProgressBar 00007 { 00008 public: 00009 ProgressBar( const unsigned int& times, const std::string& message =""):m_curIteration(0),m_numIterations(times),m_message(message),m_curPercentage(0.01) 00010 { 00011 std::cout << "\r" << m_message << "..." << "0%" << std::flush; 00012 } 00013 00014 void operator++() 00015 { 00016 ++m_curIteration; 00017 if ( double(m_curIteration)/m_numIterations > m_curPercentage) 00018 { 00019 std::cout << "\r" << m_message << "..." << (unsigned int)(m_curPercentage*100) << "%" << std::flush; 00020 m_curPercentage += 0.01; 00021 } 00022 00023 if ( m_curIteration == m_numIterations) 00024 { 00025 std::cout << "\r" << m_message << "...done!\n" << std::flush; 00026 } 00027 } 00028 00029 void reset(const unsigned int& times, const std::string& message ="") 00030 { 00031 m_curIteration = 0; 00032 m_numIterations = times; 00033 m_message = message; 00034 m_curPercentage = 0.01; 00035 } 00036 00037 private: 00038 unsigned int m_curIteration; 00039 unsigned int m_numIterations; 00040 std::string m_message; 00041 double m_curPercentage; 00042 }; 00043 00044 #endif //PROGRESSBAR_H