diff --git a/progress_tracker.cpp b/progress_tracker.cpp index 81bdbef..e5da829 100644 --- a/progress_tracker.cpp +++ b/progress_tracker.cpp @@ -17,7 +17,7 @@ void ProgressTrackerImpl::update() { void ProgressTrackerImpl::updateTimeWidth() { int number_width = 3; // 0.0 - for (auto t = 10; t <= (timeTotal().count() + 500) * 0.001; t *= 10) { + for (auto t = 10; t <= (timeTotal().count() + 500) / 1000; t *= 10) { ++number_width; } if (number_width > time_width) { diff --git a/progress_tracker.h b/progress_tracker.h index d562b18..6156706 100644 --- a/progress_tracker.h +++ b/progress_tracker.h @@ -13,10 +13,11 @@ using std::chrono::milliseconds; */ class ProgressTracker { public: - virtual unsigned int operator++() = 0; //!< next tick in progress - virtual float progress() const = 0; //!< current progress as number between 0 and 1 - virtual void display() = 0; //!< update the visual representation of progress - virtual void done() = 0; //!< update the visual representation of progress when finished + virtual unsigned int operator++() = 0; //!< next tick in progress (++tracker) + virtual unsigned int operator++(int) = 0; //!< next tick in progress (tracker++) + virtual float progress() const = 0; //!< current progress as number between 0 and 1 + virtual void display() = 0; //!< update the visual representation of progress + virtual void done() = 0; //!< update the visual representation of progress when finished virtual ~ProgressTracker() = default; }; @@ -40,6 +41,8 @@ class ProgressTrackerImpl : public ProgressTracker { unsigned int inline operator++() { return ++ticks; }; + unsigned int inline operator++(int) { return ticks++; }; + float inline progress() const { return float(ticks) / float(total_ticks); }; virtual void display() = 0; @@ -108,6 +111,8 @@ class ProgressTrackerDecorator : public ProgressTracker { unsigned int operator++() { return progress_tracker->operator++(); } + unsigned int operator++(int) { return progress_tracker->operator++(0); } + float progress() const { return progress_tracker->progress(); }; void display() { progress_tracker->display(); }; diff --git a/progress_tracker.hpp b/progress_tracker.hpp index fd7317c..6bc1bee 100644 --- a/progress_tracker.hpp +++ b/progress_tracker.hpp @@ -25,6 +25,8 @@ class ProgressTrackerImpl { auto inline operator++() -> decltype(ticks) { return ++ticks; }; + auto inline operator++(int) -> decltype(ticks) { return ticks++; }; + float inline progress() const { return float(ticks) / float(total_ticks); }; virtual void display() = 0; @@ -47,7 +49,7 @@ class ProgressTrackerImpl { */ void updateTimeWidth() { int number_width = 3; // 0.0 - for (auto t = 10; t <= (timeTotal().count() + 500) * 0.001; t *= 10) { + for (auto t = 10; t <= (timeTotal().count() + 500) / 1000; t *= 10) { ++number_width; } if (number_width > time_width) {