Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Realtime.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include <cmath>
5
7#include "Stroika/Foundation/Math/Common.h"
8
9namespace Stroika::Foundation::Time {
10
11 /*
12 ********************************************************************************
13 ******************************* Time::GetTickCount *****************************
14 ********************************************************************************
15 */
16 inline TimePointSeconds GetTickCount () noexcept
17 {
18 return RealtimeClock::now ();
19 }
20
21 ////////////////// DEPRECATED STUFF BELOW
22
23 DISABLE_COMPILER_MSC_WARNING_START (4996);
24 DISABLE_COMPILER_GCC_WARNING_START ("GCC diagnostic ignored \"-Wdeprecated-declarations\"");
25 DISABLE_COMPILER_CLANG_WARNING_START ("clang diagnostic ignored \"-Wdeprecated-declarations\"");
26 [[deprecated ("Since Stroika v3.0d5 use kInfinity")]] constexpr DurationSeconds kInfinite =
27 DurationSeconds{numeric_limits<DurationSeconds::rep>::infinity ()};
28 using DurationSecondsType [[deprecated ("Since Stroika v3.0d5 - use DurationSeconds or TimePointSeconds")]] = double;
29
30 template <typename Clock, typename Duration>
31 [[deprecated ("Since Stroika v3.0d5 - use TimePointSeconds")]] inline DurationSecondsType
32 time_point2DurationSeconds (const time_point<Clock, Duration>& tp)
33 {
34 return TimePointSeconds{tp}.time_since_epoch ().count ();
35 }
36 template <typename Clock, typename Duration>
37 [[deprecated ("Since Stroika v3.0d5 - use TimePointSeconds")]] time_point<Clock, Duration> DurationSeconds2time_point (DurationSecondsType t)
38 {
39 Require (t >= 0);
41 }
42 DISABLE_COMPILER_MSC_WARNING_END (4996);
43 DISABLE_COMPILER_GCC_WARNING_END ("GCC diagnostic ignored \"-Wdeprecated-declarations\"");
44 DISABLE_COMPILER_CLANG_WARNING_END ("clang diagnostic ignored \"-Wdeprecated-declarations\"");
45
46}
47
49
50 /*
51 ********************************************************************************
52 *********** Traversal::RangeTraits::Default<Time::DurationSeconds> *************
53 ********************************************************************************
54 */
55 inline auto Default<Time::DurationSeconds>::GetNext (value_type i) -> value_type
56 {
57 using namespace Time;
58 return DurationSeconds{nextafter (i.count (), numeric_limits<DurationSeconds::rep>::max ())};
59 }
60 inline auto Default<Time::DurationSeconds>::GetPrevious (value_type i) -> value_type
61 {
62 using namespace Time;
63 return DurationSeconds{nextafter (i.count (), numeric_limits<DurationSeconds::rep>::min ())};
64 }
65 constexpr auto Default<Time::DurationSeconds>::Difference (Common::ArgByValueType<value_type> lhs, Common::ArgByValueType<value_type> rhs) -> SignedDifferenceType
66 {
67 return rhs - lhs;
68 }
69
70 /*
71 ********************************************************************************
72 *********** Traversal::RangeTraits::Default<Time::TimePointSeconds> ************
73 ********************************************************************************
74 */
75 inline auto Default<Time::TimePointSeconds>::GetNext (value_type i) -> value_type
76 {
77 using namespace Time;
78 return TimePointSeconds{
79 TimePointSeconds::duration{nextafter (i.time_since_epoch ().count (), numeric_limits<TimePointSeconds::duration::rep>::max ())}};
80 }
81 inline auto Default<Time::TimePointSeconds>::GetPrevious (value_type i) -> value_type
82 {
83 using namespace Time;
84 return TimePointSeconds{
85 TimePointSeconds::duration{nextafter (i.time_since_epoch ().count (), numeric_limits<TimePointSeconds::duration::rep>::min ())}};
86 }
87 constexpr auto Default<Time::TimePointSeconds>::Difference (Common::ArgByValueType<value_type> lhs, Common::ArgByValueType<value_type> rhs) -> SignedDifferenceType
88 {
89 return rhs - lhs;
90 }
91
92 /*
93 ********************************************************************************
94 ** RangeTraits::Default<chrono::time_point<Time::DisplayedRealtimeClock, Time::DurationSeconds>> **
95 ********************************************************************************
96 */
97 inline auto Default<chrono::time_point<Time::DisplayedRealtimeClock, Time::DurationSeconds>>::GetNext (value_type i) -> value_type
98 {
99 using namespace Time;
100 return value_type{value_type::duration{nextafter (i.time_since_epoch ().count (), numeric_limits<value_type::duration::rep>::max ())}};
101 }
102 inline auto Default<chrono::time_point<Time::DisplayedRealtimeClock, Time::DurationSeconds>>::GetPrevious (value_type i) -> value_type
103 {
104 using namespace Time;
105 return value_type{value_type::duration{nextafter (i.time_since_epoch ().count (), numeric_limits<value_type::duration::rep>::min ())}};
106 }
107 constexpr auto Default<chrono::time_point<Time::DisplayedRealtimeClock, Time::DurationSeconds>>::Difference (
108 Common::ArgByValueType<value_type> lhs, Common::ArgByValueType<value_type> rhs) -> SignedDifferenceType
109 {
110 return rhs - lhs;
111 }
112
113}
time_point< RealtimeClock, DurationSeconds > TimePointSeconds
TimePointSeconds is a simpler approach to chrono::time_point, which doesn't require using templates e...
Definition Realtime.h:82
chrono::duration< double > DurationSeconds
chrono::duration<double> - a time span (length of time) measured in seconds, but high precision.
Definition Realtime.h:57
TimePointSeconds GetTickCount() noexcept
get the current (monotonically increasing) time - from RealtimeClock
Definition Realtime.inl:16