17 ProgressBar(std::ostream* output, std::size_t total) : m_output(output), m_total(total) {}
19 void update(std::size_t completed) {
20 if (m_output ==
nullptr || m_total == 0)
return;
22 constexpr std::size_t width = 40;
23 const auto fraction =
static_cast<long double>(completed) /
static_cast<long double>(m_total);
24 const auto filled =
static_cast<std::size_t
>(fraction * width);
25 if (filled == m_last_filled && completed != m_total)
return;
26 m_last_filled = filled;
28 *m_output <<
"\rIntegrating [";
29 for (std::size_t column = 0; column < width; ++column) {
30 *m_output << (column < filled ?
'#' :
' ');
32 *m_output <<
"] " <<
static_cast<unsigned>(fraction * 100.0L) <<
"% (" << completed <<
'/'
34 if (completed == m_total) *m_output <<
'\n';
35 *m_output << std::flush;
39 std::ostream* m_output;
41 std::size_t m_last_filled = 41;