MRPT  1.9.9
Clock.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "core-precomp.h" // Precompiled headers
11 
12 #include <mrpt/core/Clock.h>
13 
14 #ifdef _WIN32
15 #include <windows.h>
16 #else
17 #include <sys/time.h> // timeval
18 #endif
19 
20 #include <ctime> // clock_gettime
21 
23 {
24 #ifdef _WIN32
25  FILETIME t;
26  GetSystemTimeAsFileTime(&t);
27  return (((uint64_t)t.dwHighDateTime) << 32) | ((uint64_t)t.dwLowDateTime);
28 #else
29 #if defined(__APPLE__)
30  struct timeval tv;
31  timespec tim{0, 0};
32  gettimeofday(&tv, nullptr);
33  tim.tv_sec = tv.tv_sec;
34  tim.tv_nsec = tv.tv_usec * 1000;
35 #else
36  timespec tim{0, 0};
37  clock_gettime(CLOCK_REALTIME, &tim);
38 #endif
39 
40  // Convert to TTimeStamp 100-nanoseconds representation:
41  return uint64_t(tim.tv_sec) * UINT64_C(10000000) +
42  UINT64_C(116444736) * UINT64_C(1000000000) + tim.tv_nsec / 100;
43 #endif
44 }
45 
47 {
49 }
50 
52 {
54  uint64_t(t * 10000000.0) + UINT64_C(116444736) * UINT64_C(1000000000)));
55 }
56 
57 // Convert to time_t UNIX timestamp, with fractional part.
59 {
60  return double(
61  t.time_since_epoch().count() -
62  UINT64_C(116444736) * UINT64_C(1000000000)) /
63  10000000.0;
64 }
static double toDouble(const time_point t) noexcept
Converts a timestamp to a UNIX time_t-like number, with fractional part.
Definition: Clock.cpp:58
std::chrono::duration< rep, period > duration
Definition: Clock.h:25
GLdouble GLdouble t
Definition: glext.h:3695
static time_point fromDouble(const double t) noexcept
Create a timestamp from its double representation.
Definition: Clock.cpp:51
std::chrono::time_point< Clock > time_point
Definition: Clock.h:26
static time_point now() noexcept
Returns the current time, with the highest resolution available.
Definition: Clock.cpp:46
static uint64_t getCurrentTime()
Definition: Clock.cpp:22
unsigned __int64 uint64_t
Definition: rptypes.h:53



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019