-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.hpp
76 lines (65 loc) · 3.36 KB
/
timer.hpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//Copyright © 2023 Charles Kerr. All rights reserved.
#ifndef timer_hpp
#define timer_hpp
#include <cstdint>
#include <string>
#include <chrono>
//=========================================================================================
namespace util {
//=================================================================================
/// Class that allows one to time events, in terms of milliseconds
class timer_t{
std::chrono::time_point<std::chrono::steady_clock> start_time ;
std::int64_t time_duration ;
public:
//=================================================================================
/// Provides the current time
/// - Returns: A string value of the current time
static auto now() ->std::string ;
//=================================================================================
/// Provides the current time point for the steady clock
/// - Returns: Steady clock time point
static auto current() ->std::chrono::system_clock::time_point;
//=================================================================================
/// Provides the number of millisconds from a timepoint
/// - Parameters:
/// - time: The time point to delta from
/// - Returns: millisconds from the time point
static auto delta(const std::chrono::steady_clock::time_point &time) ->std::int64_t;
//=================================================================================
/// Default constructor for the timer
/// - Returns:Nothing
timer_t();
//=================================================================================
/// Constructor for the timer
/// - Parameters:
/// - milliseconds: The number of millisonds it should time
/// - block: If true, will block until time has elapsed
/// - Returns:Nothing
timer_t(std::int64_t milliseconds,bool block);
//=================================================================================
/// Sets the time to measure from
/// - Parameters:
/// - milliseconds: The number of millisonds it should time
/// - block: If true, will block until time has elapsed
/// - Returns:Nothing
auto time(std::int64_t milliseconds,bool block)->void;
//=================================================================================
/// Starts the timer
/// - Returns:Nothing
auto start() ->void ;
//=================================================================================
/// Calculates the number of millisconds since started
/// - Returns:Returns the number of milliseconds that have elapsed since started
auto elapsed() const ->std::int64_t ;
//=================================================================================
/// Determines if the time has expired
/// - Returns:Returns true if the number of milliseconds has expired
auto expired() const ->bool;
//=================================================================================
/// Determines the remaining milliseconds
/// - Returns:Returns the number of milliseconds that remain
auto remaining() const -> std::int64_t ;
};
}
#endif /* timer_hpp */