OSVR-Core
TimeValueChrono.h
Go to the documentation of this file.
1 
11 // Copyright 2016 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_TimeValueChrono_h_GUID_19CA90DA_70CF_4CBD_2327_5B6335744E91
26 #define INCLUDED_TimeValueChrono_h_GUID_19CA90DA_70CF_4CBD_2327_5B6335744E91
27 
28 // Internal Includes
29 // - none
30 
31 // Library/third-party includes
32 #include <osvr/Util/TimeValue.h>
33 
34 // Standard includes
35 #include <chrono>
36 
43 template <typename Rep, typename Period>
44 inline OSVR_TimeValue
46  std::chrono::duration<Rep, Period> const &additionalTime) {
47  using namespace std::chrono;
48  using SecondsDuration = duration<OSVR_TimeValue_Seconds>;
49  using USecondsDuration = duration<OSVR_TimeValue_Microseconds, std::micro>;
50  auto ret = tv;
51  auto seconds = duration_cast<SecondsDuration>(additionalTime);
52  ret.seconds += seconds.count();
53  ret.microseconds +=
54  duration_cast<USecondsDuration>(additionalTime - seconds).count();
56  return ret;
57 }
58 
59 #endif // INCLUDED_TimeValueChrono_h_GUID_19CA90DA_70CF_4CBD_2327_5B6335744E91
friend const ScalarAddReturnType operator+(const Scalar &scalar, const Cwise &mat)
Definition: Cwise.h:101
OSVR_UTIL_EXPORT void osvrTimeValueNormalize(OSVR_INOUT_PTR OSVR_TimeValue *tv) OSVR_FUNC_NONNULL((1))
"Normalizes" a time value so that the absolute number of microseconds is less than 1...
Definition: TimeValueC.cpp:46
Definition: TimeValueChrono.h:60
Header providing a C++ wrapper around TimeValueC.h.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81