API Documentation
Loading...
Searching...
No Matches
TimeSpan.h
Go to the documentation of this file.
1/**--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: TimeSpan
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/Time.h>
35#include <NDEVR/LibAssert.h>
36#include <NDEVR/ObjectInfo.h>
37namespace NDEVR
38{
40 {
41 public:
42 constexpr TimeSpan()
45 {}
46 constexpr explicit TimeSpan(sint04 elapsed_nano_seconds)
48 , m_elapsed_time(elapsed_nano_seconds)
49 {}
50 constexpr explicit TimeSpan(const sint08 elapsed_nano_seconds)
52 , m_elapsed_time(elapsed_nano_seconds)
53 {}
54 constexpr explicit TimeSpan(uint04 elapsed_nano_seconds)
56 , m_elapsed_time(cast<sint08>(elapsed_nano_seconds))
57 {}
58 constexpr explicit TimeSpan(const uint08 elapsed_nano_seconds)
60 , m_elapsed_time(cast<sint08>(elapsed_nano_seconds))
61 {}
62 constexpr explicit TimeSpan(const fltp08 elapsed_seconds)
64 , m_elapsed_time(cast<sint08>(elapsed_seconds * Time::SECOND))
65 {}
66 TimeSpan(const Time& start, const Time& end)
67 : m_start_time(start)
68 , m_elapsed_time(cast<sint08>(end.getNanoSeconds()) - cast<sint08>(start.getNanoSeconds()))
69 {
70 }
71 constexpr TimeSpan(const Time& start, const sint08& elapsed_nano_seconds)
72 : m_start_time(start)
73 , m_elapsed_time(elapsed_nano_seconds)
74 {}
75
76 constexpr TimeSpan(const Time& start, const fltp08& elapsed_seconds)
77 : m_start_time(start)
78 , m_elapsed_time(cast<sint08>(elapsed_seconds* Time::SECOND))
79 {}
80
81 NDEVR_BASE_API fltp08 elapsedPercent(Time time, bool clip_time) const;
82 NDEVR_BASE_API String getTimeString(const String& format_string) const;
83
84 [[nodiscard]] constexpr Time startTime() const
85 {
86 return m_start_time;
87 }
88 constexpr void setStartTime(Time time)
89 {
90 m_start_time = time;
91 }
92 constexpr void setEndTime(Time time)
93 {
95 }
96 NDEVR_BASE_API bool contains(const Time& time) const;
97
98 [[nodiscard]] NDEVR_BASE_API Time endTime() const;
99
100 [[nodiscard]] constexpr sint08 elapsedNanoseconds() const
101 {
102 return m_elapsed_time;
103 }
104
105 [[nodiscard]] constexpr fltp08 elapsedSeconds() const
106 {
110 }
111
112 template<class t_type = fltp08>
113 [[nodiscard]] constexpr t_type elapsedMilliseconds() const
114 {
118 }
119
120 [[nodiscard]] constexpr fltp08 elapsedMinutes() const
121 {
125 }
128 constexpr bool operator==(const TimeSpan& time) const
129 {
130 return m_elapsed_time == time.m_elapsed_time;
131 }
132 constexpr bool operator!=(const TimeSpan& time) const
133 {
134 return m_elapsed_time != time.m_elapsed_time;
135 }
136 constexpr bool operator>(const TimeSpan& other) const
137 {
138 return m_elapsed_time > other.m_elapsed_time;
139 }
140 constexpr bool operator>=(const TimeSpan& other) const
141 {
142 return m_elapsed_time >= other.m_elapsed_time;
143 }
144 constexpr bool operator<(const TimeSpan& other) const
145 {
146 return m_elapsed_time < other.m_elapsed_time;
147 }
148 constexpr bool operator<=(const TimeSpan& other) const
149 {
150 return m_elapsed_time <= other.m_elapsed_time;
151 }
152
153 constexpr fltp08 operator/(const TimeSpan& time_2) const
154 {
156 }
157 constexpr TimeSpan operator/(const sint08& den) const
158 {
159 return TimeSpan(m_start_time, m_elapsed_time / den);
160 }
161 constexpr TimeSpan operator/(const fltp08& den) const
162 {
164 }
165
166 constexpr TimeSpan operator*(const sint08& mult) const
167 {
168 return TimeSpan(m_start_time, m_elapsed_time * mult);
169 }
170 constexpr TimeSpan operator*(const fltp08& mult) const
171 {
173 }
174 constexpr TimeSpan& operator*=(const sint08& mult)
175 {
177 return *this;
178 }
179 constexpr TimeSpan& operator*=(const fltp08& mult)
180 {
182 return *this;
183 }
184 constexpr TimeSpan operator+(const TimeSpan& other) const
185 {
186 return TimeSpan(m_elapsed_time + other.m_elapsed_time);
187 }
188 constexpr TimeSpan& operator+=(const TimeSpan& other)
189 {
191 return *this;
192 }
193 constexpr TimeSpan operator-(const TimeSpan& other) const
194 {
195 return TimeSpan(m_elapsed_time - other.m_elapsed_time);
196 }
197 constexpr TimeSpan operator-() const
198 {
199 return TimeSpan(-m_elapsed_time);
200 }
201 constexpr TimeSpan& operator-=(const TimeSpan& other)
202 {
204 return *this;
205 }
206 protected:
209 };
210
211 /**--------------------------------------------------------------------------------------------------
212 Struct: ObjectInfo<TimeSpan>
213
214 Information about the object.
215
216 Author: Tyler Parke
217
218 Date: 2020-09-13
219 *-----------------------------------------------------------------------------------------------**/
220 template<>
221 struct ObjectInfo<TimeSpan, false, false>
222 {
223 static const uint01 Dimensions = 0;
224 static const bool Vector = false;
225 static const bool Primitive = true;
226 static const bool Pointer = false;
227 static const bool Unsigned = false;
228 static const bool Float = true;
229 static const bool Integer = false;
230 static const bool Number = true;
231 static const bool String = false;
232 static const bool Color = false;
233 static const bool Buffer = false;
234 static const bool Boolean = false;
236 };
237 NDEVR_BASE_API TimeSpan operator-(const Time& time, const Time& value);
238
239 NDEVR_BASE_API Time operator+(const Time& time, const TimeSpan& value);
240 NDEVR_BASE_API Time operator-(const Time& time, const TimeSpan& value);
241 NDEVR_BASE_API Time& operator+=(Time& time, const TimeSpan& value);
242 NDEVR_BASE_API Time& operator-=(Time& time, const TimeSpan& value);
243 constexpr TimeSpan abs(const TimeSpan& value)
244 {
245 return value >= TimeSpan(0) ? value : -value;
246 }
247 constexpr TimeSpan operator%(const Time& time, const TimeSpan& duration)
248 {
249 lib_assert(duration.elapsedNanoseconds() > 0, "Bad duration");
251 return TimeSpan(Time(time.getNanoSeconds() - nano), nano);
252 }
253
254
255
259}
#define NDEVR_BASE_API
Definition DLLInfo.h:78
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
Definition Color.h:36
Definition Pointer.hpp:62
Definition String.h:40
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
static constexpr uint08 SECOND
Definition Time.h:84
constexpr uint08 getNanoSeconds() const
Gets the timestamp in nanoseconds.
Definition Time.h:185
static constexpr uint08 MINUTE
Definition Time.h:85
static constexpr uint08 MILLISECOND
Definition Time.h:83
Definition TimeSpan.h:40
constexpr sint08 elapsedNanoseconds() const
Definition TimeSpan.h:100
TimeSpan(const Time &start, const Time &end)
Definition TimeSpan.h:66
constexpr bool operator<=(const TimeSpan &other) const
Definition TimeSpan.h:148
constexpr TimeSpan(const Time &start, const fltp08 &elapsed_seconds)
Definition TimeSpan.h:76
constexpr bool operator==(const TimeSpan &time) const
Definition TimeSpan.h:128
constexpr TimeSpan(const uint08 elapsed_nano_seconds)
Definition TimeSpan.h:58
constexpr TimeSpan operator/(const fltp08 &den) const
Definition TimeSpan.h:161
constexpr TimeSpan()
Definition TimeSpan.h:42
NDEVR_BASE_API bool contains(const Time &time) const
Definition TimeSpan.cpp:14
NDEVR_BASE_API String getTimeString(const String &format_string) const
Definition TimeSpan.cpp:18
constexpr void setEndTime(Time time)
Definition TimeSpan.h:92
constexpr fltp08 elapsedSeconds() const
Definition TimeSpan.h:105
constexpr TimeSpan operator-(const TimeSpan &other) const
Definition TimeSpan.h:193
constexpr TimeSpan & operator+=(const TimeSpan &other)
Definition TimeSpan.h:188
constexpr TimeSpan & operator*=(const sint08 &mult)
Definition TimeSpan.h:174
constexpr t_type elapsedMilliseconds() const
Definition TimeSpan.h:113
constexpr bool operator<(const TimeSpan &other) const
Definition TimeSpan.h:144
constexpr TimeSpan(uint04 elapsed_nano_seconds)
Definition TimeSpan.h:54
constexpr fltp08 elapsedMinutes() const
Definition TimeSpan.h:120
Time m_start_time
Definition TimeSpan.h:207
constexpr TimeSpan(sint04 elapsed_nano_seconds)
Definition TimeSpan.h:46
NDEVR_BASE_API Time endTime() const
Definition TimeSpan.cpp:182
constexpr TimeSpan operator+(const TimeSpan &other) const
Definition TimeSpan.h:184
constexpr bool operator!=(const TimeSpan &time) const
Definition TimeSpan.h:132
constexpr TimeSpan operator*(const fltp08 &mult) const
Definition TimeSpan.h:170
constexpr TimeSpan & operator*=(const fltp08 &mult)
Definition TimeSpan.h:179
sint08 m_elapsed_time
Definition TimeSpan.h:208
constexpr TimeSpan(const Time &start, const sint08 &elapsed_nano_seconds)
Definition TimeSpan.h:71
constexpr bool operator>=(const TimeSpan &other) const
Definition TimeSpan.h:140
constexpr Time startTime() const
Definition TimeSpan.h:84
NDEVR_BASE_API sint08 elapsedDays() const
Definition TimeSpan.cpp:186
constexpr TimeSpan operator/(const sint08 &den) const
Definition TimeSpan.h:157
constexpr TimeSpan operator*(const sint08 &mult) const
Definition TimeSpan.h:166
constexpr TimeSpan & operator-=(const TimeSpan &other)
Definition TimeSpan.h:201
constexpr TimeSpan operator-() const
Definition TimeSpan.h:197
constexpr bool operator>(const TimeSpan &other) const
Definition TimeSpan.h:136
constexpr fltp08 operator/(const TimeSpan &time_2) const
Definition TimeSpan.h:153
constexpr void setStartTime(Time time)
Definition TimeSpan.h:88
constexpr TimeSpan(const fltp08 elapsed_seconds)
Definition TimeSpan.h:62
constexpr TimeSpan(const sint08 elapsed_nano_seconds)
Definition TimeSpan.h:50
NDEVR_BASE_API fltp08 elapsedPercent(Time time, bool clip_time) const
Definition TimeSpan.cpp:6
NDEVR_BASE_API sint08 elapsedMonths() const
Definition TimeSpan.cpp:195
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
Definition ACIColor.h:37
int32_t sint04
-Defines an alias representing a 4 byte, signed integer. -Can represent exact integer values -2147483...
Definition BaseValues.hpp:76
int64_t sint08
-Defines an alias representing an 8 byte, signed integer -Can represent exact integer values -9223372...
Definition BaseValues.hpp:86
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer -Can represent exact integer values 0 thro...
Definition BaseValues.hpp:132
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Definition AngleFunctions.h:750
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200
constexpr Vector< t_dims, Angle< t_angle_type > > operator%(const Vector< t_dims, Angle< t_angle_type > > &vec_a, const Vector< t_dims, Angle< t_angle_type > > &vec_b)
Definition AngleFunctions.h:734
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
Definition BaseValues.hpp:272
static constexpr ObjectInfo< TimeSpan, false, false > VectorSub()
Definition TimeSpan.h:235
Information about the object.
Definition ObjectInfo.h:56