summaryrefslogtreecommitdiffhomepage
path: root/Timer.h
blob: c42db78e575ddb36783887eb7c59d68ea74ff860 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once

#include <boost/signals2.hpp>

#include <chrono>

using namespace std::chrono_literals;

using clock_type = std::chrono::high_resolution_clock;

class Timer
{
public:
  Timer(std::chrono::milliseconds interval, bool cyclic);

  // connect to this signal
  boost::signals2::signal<void()> elapsed;

  void start();

  void stop();

  bool is_elapsed() const;

  void update();

private:
  std::chrono::time_point<clock_type> m_start_time;
  std::chrono::milliseconds m_interval;
  bool m_running;
  bool m_cyclic;
};