-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.h
42 lines (34 loc) · 779 Bytes
/
timer.h
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
34
35
36
37
38
39
40
41
42
#ifndef TIMER_H
#define TIMER_H
#include <cstdio>
#include <stdexcept>
#include <algorithm>
#include <functional>
class Timer {
public:
typedef double timer_t;
int time_cmp (const Timer & rhs);
private:
static constexpr timer_t PREC_MIN = 1E-6;
static constexpr timer_t DEF_NUM = 1;
const timer_t prec_;
timer_t time_;
timer_t handle_prec (timer_t prec) {
if (prec < PREC_MIN) {
throw std::invalid_argument("Wrong precision got in Timer");
}
else
return prec;
}
public:
explicit Timer (timer_t prec = DEF_NUM, timer_t init_val = 0):
prec_ (handle_prec(prec)),
time_ (init_val) {}
void operator ++ () {
time_ += prec_;
}
timer_t get_time () const {
return time_;
}
};
#endif //TIMER_H