25 #ifndef INCLUDED_TimeValueChrono_h_GUID_62662C09_CE8E_4394_87A9_26D2FC0D2920 26 #define INCLUDED_TimeValueChrono_h_GUID_62662C09_CE8E_4394_87A9_26D2FC0D2920 41 #ifdef OSVR_DUMMY_DEFINE //_WIN32 46 std::ratio_multiply<std::ratio<100>, std::nano>::type;
52 using time_value_scalar_rep = std::uint64_t;
53 using time_value_scalar_duration =
54 std::chrono::duration<time_value_scalar_rep, time_value_period>;
74 using duration = std::chrono::duration<rep, period>;
76 using time_point = std::chrono::time_point<clock>;
79 static const bool is_steady =
true;
81 static time_point now() {
94 return tp.time_since_epoch().count();
99 std::chrono::duration<OSVR_TimeValue_Seconds>;
102 std::chrono::duration<OSVR_TimeValue_Microseconds, std::micro>;
108 using derived_type = Derived;
111 return get().seconds;
117 return get().microseconds;
121 getMicrosecondsPartAsDuration()
const {
123 getMicrosecondsPart()};
126 time_value_scalar_duration toScalarDuration()
const {
127 using std::chrono::duration_cast;
128 return duration_cast<time_value_scalar_duration>(
129 getSecondsPartAsDuration()) +
130 duration_cast<time_value_scalar_duration>(
131 getMicrosecondsPartAsDuration());
134 derived_type
const &derived()
const {
135 return *
static_cast<derived_type
const *
>(
this);
138 return derived().get();
146 TimeValueChronoValueWrapper> {
160 TimeValueChronoConstRefWrapper> {
168 : m_timeval(other.m_timeval) {}
188 wrap_time_value(TimeValueClock::time_point
const &
tp) {
190 tp.time_since_epoch().count()};
200 template <
typename DerivedA,
typename DerivedB>
201 inline time_value_scalar_duration
208 a.getMicrosecondsPart() - b.getMicrosecondsPart()};
209 return duration_cast<time_value_scalar_duration>(diffSeconds) +
210 duration_cast<time_value_scalar_duration>(diffUsec);
214 template <
typename Derived>
215 inline time_value_scalar_duration
218 return a - detail::wrap_time_value(b);
221 template <
typename Derived>
222 inline time_value_scalar_duration
225 return detail::wrap_time_value(a) - b;
231 inline time_value_scalar_duration
233 TimeValueClock::time_point
const &b) {
234 return detail::wrap_time_value(a) - detail::wrap_time_value(b);
238 template <
typename Derived>
239 inline time_value_scalar_duration
242 return detail::wrap_time_value(a) - b;
246 template <
typename Derived>
247 inline time_value_scalar_duration
249 TimeValueClock::time_point
const &b) {
250 return a - detail::wrap_time_value(b);
254 inline time_value_scalar_duration
257 return detail::wrap_time_value(a) - detail::wrap_time_value(b);
261 template <
typename Derived>
262 inline time_value_scalar_duration
264 TimeValueClock::time_point
const &b) {
265 return detail::wrap_time_value(a) - detail::wrap_time_value(b);
269 inline TimeValueClock::time_point
271 return TimeValueClock::time_point{TimeValueClock::duration{tv}};
277 return detail::wrap_time_value(tv).toScalarDuration();
283 #endif // INCLUDED_TimeValueChrono_h_GUID_62662C09_CE8E_4394_87A9_26D2FC0D2920 A simple argument-pack-based metaprogramming library, inspired by and based partially on https://eric...
Definition: Always.h:41
osvr::util::time::TimeValue getTimeValue(TimeValueClock::time_point const &tp)
Get the TimeValue inside of a TimeValueClock time_point.
Definition: TimeValueChrono.h:93
Definition: RunLoopManager.h:42
time_value_scalar_duration scalar_duration
When we want a short-ish duration (time difference), we can go to a scalar instead of the structure -...
Definition: TimeValueChrono.h:88
TimeValueClock::time_point as_time_point(time::TimeValue const &tv)
Treat/convert a TimeValue into a time point.
Definition: TimeValueChrono.h:270
void getNow(TimeValue &tv)
Set the given TimeValue to the current time.
Definition: TimeValue.h:51
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Definition: TypeSafeIdHash.h:44
CRTP base class for things that wrap a OSVR_TimeValue for the purposes of some interop with std::chro...
Definition: TimeValueChrono.h:106
std::chrono::duration< OSVR_TimeValue_Microseconds, std::micro > time_value_microseconds_duration
Duration representation of the second element of the structure.
Definition: TimeValueChrono.h:102
Copy and store a TimeValue in a wrapper for std::chrono interop.
Definition: TimeValueChrono.h:144
int32_t OSVR_TimeValue_Microseconds
The signed integer type storing the microseconds in a struct OSVR_TimeValue.
Definition: TimeValueC.h:69
Store a reference to const to a TimeValue for std::chrono interop.
Definition: TimeValueChrono.h:158
::OSVR_TimeValue TimeValue
C++-friendly typedef for the OSVR_TimeValue structure.
Definition: TimeValue.h:48
TimeValueClock::scalar_duration to_duration(time::TimeValue const &tv)
Convert a TimeValue into a scalar duration.
Definition: TimeValueChrono.h:276
Definition: newuoa.h:1888
int64_t OSVR_TimeValue_Seconds
The signed integer type storing the seconds in a struct OSVR_TimeValue.
Definition: TimeValueC.h:66
Definition: TimeValueChrono.h:68
Definition: TimeValueChrono.h:60
TimeValueChronoConstRefWrapper(TimeValueChronoConstRefWrapper &&other)
movable
Definition: TimeValueChrono.h:166
time_value_scalar_duration operator-(detail::TimeValueChronoWrapperBase< DerivedA > const &a, detail::TimeValueChronoWrapperBase< DerivedB > const &b)
Subtract one wrapped TimeValue from another and get a std::duration back!
Definition: TimeValueChrono.h:202
Header providing a C++ wrapper around TimeValueC.h.
std::chrono::duration< OSVR_TimeValue_Seconds > time_value_seconds_duration
Duration representation of the first element in the structure.
Definition: TimeValueChrono.h:99
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
std::micro time_value_period
Assumes the max representable resolution otherwise.
Definition: TimeValueChrono.h:49