6 #include "Mountain/core.hpp" 16 static constexpr int64_t NanosecondsPerTick = 100;
18 static constexpr int64_t TicksPerMicrosecond = 10;
20 static constexpr int64_t TicksPerMillisecond = TicksPerMicrosecond * 1000;
22 static constexpr int64_t TicksPerSecond = TicksPerMillisecond * 1000;
24 static constexpr int64_t TicksPerMinute = TicksPerSecond * 60;
26 static constexpr int64_t TicksPerHour = TicksPerMinute * 60;
28 static constexpr int64_t TicksPerDay = TicksPerHour * 24;
33 static constexpr
TimeSpan MaxValue();
35 static constexpr
TimeSpan MinValue();
38 static TimeSpan FromDays(double_t days);
40 static TimeSpan FromHours(double_t hours);
42 static TimeSpan FromMinutes(double_t minutes);
44 static TimeSpan FromSeconds(double_t seconds);
46 static TimeSpan FromMilliseconds(double_t milliseconds);
48 static TimeSpan FromMicroseconds(double_t microseconds);
50 static TimeSpan FromTicks(int64_t ticks);
53 explicit constexpr
TimeSpan(int64_t ticks);
55 constexpr
TimeSpan(int32_t hours, int32_t minutes, int32_t seconds);
57 constexpr
TimeSpan(int32_t days, int32_t hours, int32_t minutes, int32_t seconds, int32_t milliseconds = 0, int32_t microseconds = 0);
59 GETTER(int64_t, Ticks, m_Ticks)
62 int32_t GetDays()
const;
64 int32_t GetHours()
const;
66 int32_t GetMinutes()
const;
68 int32_t GetSeconds()
const;
70 int32_t GetMilliseconds()
const;
72 int32_t GetMicroseconds()
const;
74 int32_t GetNanoseconds()
const;
77 double_t GetTotalDays()
const;
79 double_t GetTotalHours()
const;
81 double_t GetTotalMinutes()
const;
83 double_t GetTotalSeconds()
const;
85 double_t GetTotalMilliseconds()
const;
87 double_t GetTotalMicroseconds()
const;
89 double_t GetTotalNanoseconds()
const;
113 static constexpr int64_t MaxSeconds = std::numeric_limits<int64_t>::max() / TicksPerSecond;
114 static constexpr int64_t MinSeconds = std::numeric_limits<int64_t>::min() / TicksPerSecond;
116 static constexpr int64_t MaxMilliSeconds = std::numeric_limits<int64_t>::max() / TicksPerMillisecond;
117 static constexpr int64_t MinMilliSeconds = std::numeric_limits<int64_t>::min() / TicksPerMillisecond;
119 static constexpr int64_t MaxMicroSeconds = std::numeric_limits<int64_t>::max() / TicksPerMicrosecond;
120 static constexpr int64_t MinMicroSeconds = std::numeric_limits<int64_t>::min() / TicksPerMicrosecond;
122 static constexpr int64_t TicksPerTenthSecond = TicksPerMillisecond * 100;
125 static TimeSpan Interval(double_t ticks, double_t scale);
127 static TimeSpan IntervalFromDoubleTicks(double_t ticks);
139 return timeSpan.GetTicks() ^ (timeSpan.GetTicks() >> 32);
148 template <
class ParseContext>
149 constexpr
typename ParseContext::iterator
parse(ParseContext& ctx)
151 auto it = ctx.begin();
156 throw std::format_error(
"Invalid format args for Mountain::TimeSpan");
163 template <
class FormatContext>
166 std::ostringstream out;
168 const bool_t daysCheck = timeSpan.GetDays() > 0;
169 const bool_t hoursCheck = timeSpan.GetHours() > 0;
170 const bool_t minutesCheck = timeSpan.GetMinutes() > 0;
173 out << timeSpan.GetDays() <<
'.';
175 if (daysCheck || hoursCheck)
176 out << std::format(
"{:2}:", timeSpan.GetHours());
178 if (daysCheck || hoursCheck || minutesCheck)
179 out << std::format(
"{:2}:", timeSpan.GetMinutes());
181 out << timeSpan.GetSeconds();
183 const bool_t millisecondsCheck = timeSpan.GetMilliseconds() > 0;
184 const bool_t microsecondsCheck = timeSpan.GetMicroseconds() > 0;
185 const bool_t nanosecondsCheck = timeSpan.GetNanoseconds() > 0;
187 if (nanosecondsCheck || microsecondsCheck)
188 out << std::format(
".{:03}", timeSpan.GetMilliseconds());
189 else if (millisecondsCheck)
190 out << std::format(
".{}", timeSpan.GetMilliseconds());
192 if (nanosecondsCheck || microsecondsCheck)
193 out << std::format(
"{:03}", timeSpan.GetMicroseconds());
194 else if (microsecondsCheck)
195 out << std::format(
".{}", timeSpan.GetMilliseconds());
197 if (nanosecondsCheck)
198 out << std::format(
"{}", timeSpan.GetNanoseconds());
200 return std::ranges::copy(std::move(out).str(), ctx.out()).out;
204 #include "Mountain/utils/time_span.inl" constexpr Matrix & operator*=(Matrix &m, const float_t scalar) noexcept
constexpr Color operator*(const Color &c1, const Color &c2)
Multiplies 2 Color.
constexpr Matrix operator-(const Matrix &matrix) noexcept
constexpr Color operator+(const Color &c1, const Color &c2)
Adds 2 Color, caps at 1.f.
constexpr Matrix & operator-=(Matrix &m1, const Matrix &m2) noexcept
C++ reimplementation of the .NET TimeSpan struct.
constexpr Quaternion operator/(const Quaternion &v, const float_t factor) noexcept
constexpr Quaternion & operator/=(Quaternion &q, const float_t factor) noexcept
constexpr Matrix & operator+=(Matrix &m1, const Matrix &m2) noexcept
MATH_TOOLBOX std::ostream & operator<<(std::ostream &out, const Matrix &m)
Contains all declarations of the Mountain Framework.