-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElapsedTimer.h
50 lines (39 loc) · 1.15 KB
/
ElapsedTimer.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
#pragma once
#include"BaseLib/CommonDefines.h"
#include"BaseLib/Timestamp.h"
#include"BaseLib/Duration.h"
#include"BaseLib/Export.h"
namespace BaseLib {
/**
* @brief The ElapsedTimer class provides lap stop-watch functionality. The constructor
* is given an intervalTime in milliseconds, and the class functions check wether
* the interval (lap) has expired.
*/
class DLL_STATE ElapsedTimer
{
public:
ElapsedTimer(int64 intervalMsecs);
ElapsedTimer(Duration interval = Duration::Infinite());
~ElapsedTimer();
public:
void Start(Duration interval = Duration::Infinite());
void Restart();
void Update();
bool HasExpired() const;
bool CheckHasExpiredAndUpdate();
Duration Elapsed() const;
Duration Remaining() const;
Duration IntervalMs() const;
friend std::ostream& operator<<(std::ostream& ostr, const ElapsedTimer& timer)
{
ostr << TYPE_NAME(timer) << "(" << timer.startTime_ << "," << timer.intervalTime_ << "," << timer.totalTime_ << ")";
return ostr;
}
private:
Duration elapsed() const;
private:
Timestamp startTime_;
Duration intervalTime_;
Duration totalTime_;
};
}