32 return std::chrono::duration_cast<cloe::Duration>(tp);
37 using Clock = std::chrono::steady_clock;
38 using TimePoint = std::chrono::steady_clock::time_point;
42 virtual ~
Progress() noexcept =
default;
50 void begin() { beg_ = Clock::now(); }
68 bool is_ended()
const {
return cur_ == 1.0 && eta_ == Duration{0}; }
80 assert(p > 0.0 && p <= 1.0);
81 auto dur = Clock::now() - beg_;
82 assert(cast_duration(dur) > Duration(0));
84 auto total = Duration(
static_cast<long long>(
static_cast<double>(dur.count()) / p));
85 assert(total >= Duration(0));
87 assert(eta_ >= Duration(0));
111 Duration
eta()
const {
return eta_; }
118 auto now = Clock::now();
119 return cast_duration(now - beg_);
121 return cast_duration(end_ - beg_);
124 friend void to_json(cloe::Json& j,
const Progress& e) {
Definition: progress.hpp:35
void update_safe(double p)
Definition: progress.hpp:94
double percent() const
Definition: progress.hpp:106
Duration elapsed() const
Definition: progress.hpp:116
void update(double p)
Definition: progress.hpp:73
void end()
Definition: progress.hpp:59
bool is_ended() const
Definition: progress.hpp:68
Duration eta() const
Definition: progress.hpp:111
void begin()
Definition: progress.hpp:50
std::chrono::nanoseconds Duration
Definition: cloe_fwd.hpp:36