29 #ifndef GLOBAL_CALLS_HPP 30 #define GLOBAL_CALLS_HPP 32 #include <QElapsedTimer> 54 m_workSize = workSize > 1 ? workSize : 1;
58 std::cout <<
'\r' <<
"0% done... remaining time not yet available" << std::flush;
63 m_workProgress = workProgress;
64 int percentage = ((float)m_workProgress / (
float)m_workSize) * 100.0;
65 if(percentage >= 100) percentage = 99;
66 if(percentage > m_lastPercentage){
67 m_lastPercentage = percentage;
68 std::cout <<
'\r' << percentage <<
"% done... approx. ";
69 printFormattedTime((((
float)m_startTime.elapsed() / (float)m_workProgress) * (float)(m_workSize - m_workProgress)) / 1000.0);
70 std::cout <<
" remaining " << std::flush;
76 m_lastPercentage = 100;
77 std::cout <<
'\r' <<
"100% done... ";
78 printFormattedTime((
float)m_startTime.elapsed() / 1000.0);
79 std::cout <<
" elapsed. " << std::endl << std::flush;
82 static void printFormattedTime(
size_t sec){
87 size_t days = sec / 86400;
89 size_t hours = sec / 3600;
91 size_t minutes = sec / 60;
92 size_t seconds = sec % 60;
93 if(days) std::cout << days <<
"d, ";
94 if(days || hours) std::cout << hours <<
"h, ";
95 if(days || hours || minutes) std::cout << minutes <<
"m, ";
96 if(days || hours || minutes || seconds) std::cout << seconds <<
"s";
102 size_t m_workProgress;
103 int m_lastPercentage;
104 QElapsedTimer m_startTime;
108 CoutProgress(): m_workSize(1), m_workProgress(0), m_lastPercentage(0) {}
static CoutProgress & get()
Singleton instance getter.
Definition: global_calls.hpp:46
A singleton class providing a standard output progress bar, including remaining time estimate.
Definition: global_calls.hpp:41
void start(size_t workSize)
Start displaying the progress bar and define the amout of work that's left to be done.
Definition: global_calls.hpp:53
void update(size_t workProgress)
Update the progress bar, 0 <= workProgress <= workSize.
Definition: global_calls.hpp:62
void finish()
Call when the work is done to stop the progress bar.
Definition: global_calls.hpp:75