acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
aaa_time.h
1// Created by camilo on 2022-05-31 05:43 AM <3ThomasLikesNumber5 (really will he raise ca-square)
2#pragma once
3
4
5#ifdef time
6#undef time
7#endif
8
9// time : Duration "with-no-templates"
10
11class CLASS_DECL_ACME time :
12 public DURATION
13{
14public:
15
16
17 //::f64 m_f64; // seconds
18
19
20 constexpr time(no_initialize_t) {}
21 constexpr time():time(0, 0) {}
22 constexpr time(::i64 iSecond, ::i64 iNanosecond) {m_iSecond = iSecond; m_iNanosecond = iNanosecond; normalize();}
23 constexpr time(zero_t) :time(0, 0) {}
24 time(::f64 d) {m_iSecond = (::i64)d; m_iNanosecond = (::i64) ((d - floor(d)) * 1'000'000'000.0); normalize();}
25 constexpr time(const class ::time& time) {m_iSecond = time.m_iSecond; m_iNanosecond = time.m_iNanosecond;}
26 constexpr time(const struct ::timespec& timespec) {m_iSecond = timespec.tv_sec; m_iNanosecond = timespec.tv_nsec; normalize(); }
27 inline time(const class duration & duration);
28 inline time(const ::integral_nanosecond & integral);
29 inline time(const ::floating_nanosecond & floating);
30 inline time(const ::integral_microsecond & integral);
31 inline time(const ::floating_microsecond & floating);
32 inline time(const ::integral_millisecond & integral);
33 inline time(const ::floating_millisecond & floating);
34 inline time(const ::integral_second & integral);
35 inline time(const ::floating_second & floating);
36 inline time(const ::integral_minute & integral);
37 inline time(const ::floating_minute & floating);
38 inline time(const ::integral_hour & integral);
39 inline time(const ::floating_hour & floating);
40 inline time(const ::integral_day & integral);
41 inline time(const ::floating_day & floating);
42
43
44 static class ::time now();
45
46 inline class ::time elapsed(const class ::time& waitSample = now()) { return waitSample - *this; }
47
48
49 constexpr class ::time &operator =(const struct ::timespec & timespec)
50 {
51
52 m_iSecond = timespec.tv_sec;
53 m_iNanosecond = timespec.tv_nsec;
54
55 return *this;
56
57 }
58
59 constexpr class ::time & normalize()
60 {
61
62 normalize_second_nanosecond(m_iSecond, m_iNanosecond);
63
64 return *this;
65
66 }
67
68
69 constexpr time & operator += (const time & time)
70 {
71
72 add_second_nanosecond(m_iSecond, m_iNanosecond, time.m_iSecond, time.m_iNanosecond);
73
74 return *this;
75
76 }
77
78
79 constexpr time & operator -= (const time & time)
80 {
81
82 subtract_second_nanosecond(m_iSecond, m_iNanosecond, time.m_iSecond, time.m_iNanosecond);
83
84 return *this;
85
86 }
87
88
89 constexpr class ::time operator + (const time & time) const
90 {
91
92 class ::time timeResult(*this);
93
94 timeResult += time;
95
96 return timeResult;
97
98 }
99
100
101 constexpr class ::time operator - (const time & time) const
102 {
103
104 class ::time timeResult(*this);
105
106 timeResult -= time;
107
108 return timeResult;
109 }
110
111 inline bool operator !() const { return m_iSecond != 0 && m_iNanosecond != 0; }
112
113
114 constexpr integral_millisecond integral_milliseconds() const { return m_iSecond * 1'000 + m_iNanosecond / 1'000'000;}
115
116
117 constexpr ::u32 ::u32() const { return constrain_u32(integral_milliseconds().m_i); }
118
119 constexpr operator ::u32() const { return this->::u32(); }
120
121
122
123 DECLARE_COMPARISON_WITH_DURATION(NON_INLINE)
124
125
126 template < prototype_number NUMBER >
127 inline class time operator / (const NUMBER & number)const{ return time(m_iSecond / number, m_iNanosecond / number); }
128 template < prototype_number NUMBER >
129 inline class time operator * (const NUMBER & number) const{ return time(m_iSecond * number, m_iNanosecond * number); }
130
131
132
133};
134
135
136CLASS_DECL_ACME void preempt(const class ::time& duration);
137
138
139
Definition _tags.h:5
Definition _structures.h:50