-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwrap_around_time_stamp.hpp
More file actions
52 lines (41 loc) · 923 Bytes
/
wrap_around_time_stamp.hpp
File metadata and controls
52 lines (41 loc) · 923 Bytes
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
43
44
45
46
47
48
49
50
51
52
#ifndef _TSD_WRAP_AROUND_TIME_STAMP_HPP
#define _TSD_WRAP_AROUND_TIME_STAMP_HPP
namespace tsd
{
class wrap_around_time_stamp
{
public:
static constexpr int64_t max = 0x1FFFFFFFF;
public:
wrap_around_time_stamp() :
time_(0) {}
explicit wrap_around_time_stamp(int64_t t) :
time_(t) {}
explicit wrap_around_time_stamp(uint64_t t) :
time_(t) {}
int64_t get() const {
return time_;
}
const int64_t operator-(
const wrap_around_time_stamp& o) const {
if(std::abs(time_ - o.time_) <= max/2) {
return time_ - o.time_;
}
else {
if(time_ < o.time_)
return (time_+max+1) - o.time_;
else
return time_ - (o.time_+max+1);
}
}
bool operator<(const wrap_around_time_stamp& o) const {
if(std::abs(time_ - o.time_) <= max/2)
return time_ < o.time_;
else
return o.time_ < time_;
}
private:
int64_t time_;
};
}
#endif