timer.h 544 B

12345678910111213141516171819202122232425
  1. #include <chrono>
  2. class timer
  3. {
  4. public:
  5. using clock = std::chrono::steady_clock;
  6. timer(clock::duration duration, bool autostart = false) noexcept;
  7. bool check() noexcept;
  8. void pause(bool) noexcept;
  9. void pause() noexcept;
  10. void resume() noexcept;
  11. bool paused() const noexcept;
  12. clock::duration duration() const noexcept;
  13. clock::duration remaining_duration() const noexcept;
  14. clock::time_point target_time_point() const noexcept;
  15. private:
  16. clock::duration set;
  17. clock::duration remaining;
  18. clock::time_point target;
  19. bool _paused;
  20. };