-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDuration.h
59 lines (45 loc) · 1.48 KB
/
Duration.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
#pragma once
#include <stdlib.h>
#include <stdint.h>
#include"BaseLib/CommonDefines.h"
#include"BaseLib/Export.h"
namespace BaseLib {
/**
* This class represents a time interval.
*/
class DLL_STATE Duration : public std::chrono::nanoseconds
{
public:
Duration(int64 nanosecs = std::numeric_limits<int64>::max());
Duration(std::chrono::nanoseconds nanosecs);
~Duration();
// -----------------------------------------
// Getters
// -----------------------------------------
int64 InMillis() const;
int64 InMicrosecs() const;
int64 InNanosecs() const;
int64 InSecs() const;
long InMinutes() const;
long InHours() const;
bool IsInfinite() const;
// -----------------------------------------
// Factory functions
// -----------------------------------------
static Duration Zero(); // {0, 0}
static Duration Infinite(); // {0x7fffffff, 0x7fffffff}
static Duration FromMicroseconds(const int64& micros);
static Duration FromMilliseconds(const int64& millis);
static Duration FromSeconds(const int64& secs);
static Duration FromMinutes(const long& mins);
static Duration FromHours(const long& hrs);
// -----------------------------------------
// friend operators
// -----------------------------------------
friend std::ostream& operator<<(std::ostream& ostr, const Duration& dur)
{
ostr << "Duration(millisecs=" << dur.InMillis() << ")";
return ostr;
}
};
}