-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnitTimer.h
136 lines (114 loc) · 5.2 KB
/
UnitTimer.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// ---------------------------------------------------------------------------
#ifndef UnitTimerH
#define UnitTimerH
// ---------------------------------------------------------------------------
// Include
// ---------------------------------------------------------------------------
#include <windows.h>
// ---------------------------------------------------------------------------
namespace NSApplication {
// ---------------------------------------------------------------------------
// Using
// ---------------------------------------------------------------------------
using microseconds = long long;
using roundminutes = int;
using roundhours = int;
using milliseconds = double;
using seconds = double;
using minutes = double;
using hours = double;
using symbolsPerMinute = double;
using wordsPerMinute = double;
// ---------------------------------------------------------------------------
// Declaration of LARGE_INTEGER Streaming
// ---------------------------------------------------------------------------
template<class TStreamer>
TStreamer& operator<<(TStreamer& Streamer, const LARGE_INTEGER& LInteger);
// ---------------------------------------------------------------------------
template<class TStreamer>
TStreamer& operator>>(TStreamer& Streamer, LARGE_INTEGER& LInteger);
// ---------------------------------------------------------------------------
// Declaration of CTimer
// ---------------------------------------------------------------------------
class CTimer {
public:
CTimer();
CTimer(const CTimer&) = delete;
CTimer(CTimer&&) = delete;
CTimer& operator=(const CTimer&) = delete;
CTimer& operator=(CTimer&&) = delete;
// returns the time in microseconds from the moment of creation of the Timer
microseconds getTime() const;
// Conversions from microseconds
static milliseconds MicroSecondsToMilliSeconds(microseconds Time);
static seconds MicroSecondsToSeconds(microseconds Time);
static minutes MicroSecondsToMinutes(microseconds Time);
static hours MicroSecondsToHours(microseconds Time);
static roundminutes MicroSecondsToRoundMinutes(microseconds Time);
static roundhours MicroSecondsToRoundHours(microseconds Time);
// Conversions to microseconds
static microseconds MillisecondsToMicroseconds(milliseconds Time);
static microseconds SecondsToMicroseconds(milliseconds Time);
static microseconds MinutesToMicroseconds(roundminutes Time);
static microseconds HoursToMicroseconds(roundhours Time);
// Conversion time to speed
static symbolsPerMinute convertTimeToSpeed(microseconds Time);
// Constants
static constexpr microseconds microsecondsInOneMillisecond = 1000;
static constexpr microseconds microsecondsInOneSecond = 1000000;
static constexpr microseconds microsecondsInOneMinute = 60000000;
static constexpr microseconds microsecondsInOneHour = 3600000000;
private:
LARGE_INTEGER startingTime;
LARGE_INTEGER frequency;
template<class TStreamer>
friend TStreamer& operator<<(TStreamer& Streamer, const CTimer& Timer);
template<class TStreamer>
friend TStreamer& operator>>(TStreamer& Streamer, CTimer& Timer);
};
// ---------------------------------------------------------------------------
// Declaration of CTimer Streaming
// ---------------------------------------------------------------------------
template<class TStreamer>
TStreamer& operator<<(TStreamer& Streamer, const CTimer& Timer);
// ---------------------------------------------------------------------------
template<class TStreamer>
TStreamer& operator>>(TStreamer& Streamer, CTimer& Timer);
// ---------------------------------------------------------------------------
} // NSApplication
// ---------------------------------------------------------------------------
namespace NSApplication {
// ---------------------------------------------------------------------------
// Definition of LARGE_INTEGER Streaming
// ---------------------------------------------------------------------------
template<class TStreamer>
TStreamer& operator<<(TStreamer& Streamer, const LARGE_INTEGER& LInteger) {
Streamer.writePOD(LInteger);
return Streamer;
}
// ---------------------------------------------------------------------------
template<class TStreamer>
TStreamer& operator>>(TStreamer& Streamer, LARGE_INTEGER& LInteger) {
Streamer.readPOD(&LInteger);
return Streamer;
}
// ---------------------------------------------------------------------------
// Definition of CTimer Streaming
// ---------------------------------------------------------------------------
template<class TStreamer>
TStreamer& operator<<(TStreamer& Streamer, const CTimer& Timer) {
Streamer << Timer.startingTime;
Streamer << Timer.frequency;
return Streamer;
}
// ---------------------------------------------------------------------------
template<class TStreamer>
TStreamer& operator>>(TStreamer& Streamer, CTimer& Timer) {
Streamer >> Timer.startingTime;
Streamer >> Timer.frequency;
return Streamer;
}
// ---------------------------------------------------------------------------
} // NSApplication
// ---------------------------------------------------------------------------
#endif