/* */ #ifndef D_TIMER_A2_H #define D_TIMER_A2_H #include "common.h" #include #include "a2time.h" #include "a2functional.h" namespace aria2 { class Timer { public: using Clock = std::chrono::steady_clock; // The time value is initialized so that it represents the time at which // this object was created. Timer(); Timer(const Timer& time) = default; Timer(Timer&& time) = default; template constexpr explicit Timer(const duration& t) : tp_(t) { } explicit Timer(const Clock::time_point& tp); Timer& operator=(Timer&& timer) = default; Timer& operator=(const Timer& timer) = default; bool operator<(const Timer& timer) const { return tp_ < timer.tp_; } bool operator>(const Timer& timer) const { return timer < *this; } bool operator<=(const Timer& timer) const { return !(timer < *this); } bool operator>=(const Timer& timer) const { return !(*this < timer); } void reset(); template void reset(const duration& t) { tp_ = Clock::time_point(t); } Clock::duration difference() const; Clock::duration difference(const Timer& timer) const; // Returns true if this object's time value is zero. bool isZero() const; template void advance(const duration& t) { tp_ += t; } template void sub(const duration& t) { tp_ -= t; } const Clock::time_point& getTime() const { return tp_; } static Timer zero() { return Timer(0_s); } private: Clock::time_point tp_; }; } // namespace aria2 #endif // D_TIMER_A2_H