39 std::int64_t horizon)
noexcept {
40 if (
total <= 0)
return 0;
41 if (horizon <= 0 || elapsed >= horizon)
return total;
42 if (elapsed <= 0)
return 0;
43 const std::int64_t num =
static_cast<std::int64_t
>(
total) * elapsed;
44 return static_cast<int>((num + horizon - 1) / horizon);
49 void begin(
int total_steps)
noexcept {
50 total_ = std::max(total_steps, 0);
62 template <
typename Step>
63 int run_due(std::int64_t elapsed, std::int64_t horizon, Step&& step) {
64 return run_until(
due_steps(total_, elapsed, horizon), step);
68 template <
typename Step>
70 return run_until(done_ + std::max(count, 0), step);
75 template <
typename Step>
77 return run_until(total_, step);
80 bool active() const noexcept {
return done_ < total_; }
81 int total() const noexcept {
return total_; }
83 int remaining() const noexcept {
return total_ - done_; }
86 template <
typename Step>
87 int run_until(
int target, Step& step) {
88 target = std::min(target, total_);
89 const int start = done_;
90 while (done_ < target) {
91 const int index = done_;
Definition staged_transition.hpp:33
bool active() const noexcept
Definition staged_transition.hpp:80
int completed() const noexcept
Definition staged_transition.hpp:82
int run_due(std::int64_t elapsed, std::int64_t horizon, Step &&step)
Run every step due by elapsed of horizon (see due_steps()).
Definition staged_transition.hpp:63
void cancel() noexcept
Drop the schedule without running the remaining steps.
Definition staged_transition.hpp:55
void begin(int total_steps) noexcept
Schedule total_steps steps; runs nothing.
Definition staged_transition.hpp:49
int remaining() const noexcept
Definition staged_transition.hpp:83
static constexpr int due_steps(int total, std::int64_t elapsed, std::int64_t horizon) noexcept
Steps that must have completed once elapsed of horizon units have passed: ceil(total * elapsed / hori...
Definition staged_transition.hpp:38
int total() const noexcept
Definition staged_transition.hpp:81
int run_next(int count, Step &&step)
Run up to count further steps. Returns the number run.
Definition staged_transition.hpp:69
int finish_now(Step &&step)
Run every remaining step now (for a consumer that needs the finished state immediately).
Definition staged_transition.hpp:76
Definition additive_bank.hpp:218