-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcache.hh
48 lines (37 loc) · 958 Bytes
/
cache.hh
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
// Copyright (c) 2022 Mikael Simonsson <https://mikaelsimonsson.com>.
// SPDX-License-Identifier: BSL-1.0
// # Cache
#pragma once
#include "snn-core/time/steady/since_boot.hh"
namespace snn::time::steady
{
// ## Classes
// ### cache
class cache final
{
public:
explicit cache() noexcept
: d_{time::steady::since_boot()}
{
}
[[nodiscard]] time::duration get() const noexcept
{
return d_;
}
[[nodiscard]] i64 milliseconds() const noexcept
{
// This will not overflow for millions of years.
return (d_.seconds() * 1'000) + (d_.nanoseconds() / 1'000'000);
}
[[nodiscard]] i64 seconds() const noexcept
{
return d_.seconds();
}
void update() noexcept
{
d_ = time::steady::since_boot();
}
private:
time::duration d_;
};
}