- Aldebaran documentation |
- C++ Libraries |
- index

libqi-api 2.8.7.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
clock.hpp
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2013 Aldebaran Robotics. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the COPYING file.
5 */
6
7 #pragma once
8 #ifndef _QI_CLOCK_HPP_
9 # define _QI_CLOCK_HPP_
10
11 # include <qi/api.hpp>
12 # include <qi/types.hpp>
13 # include <boost/chrono/chrono.hpp>
14
15 namespace qi
16 {
18
19 template<class Rep, class Ratio>
20 using DurationType = boost::chrono::duration<Rep, Ratio>;
21
22 template<class ClockType>
23 using TimePoint = boost::chrono::time_point<ClockType>;
24
25 using NanoSeconds = DurationType<int64_t, boost::nano>;
26 using MicroSeconds = DurationType<int64_t, boost::micro>;
27 using MilliSeconds = DurationType<int64_t, boost::milli>;
28 using Seconds = DurationType<int64_t, boost::ratio<1>>;
29 using Minutes = DurationType<int64_t, boost::ratio<60>>;
30 using Hours = DurationType<int64_t, boost::ratio<3600>>;
31
32 using Duration = NanoSeconds;
33
42 class QI_API SteadyClock
43 {
44 public:
45 using rep = Duration::rep;
46 using period = Duration::period;
47 using duration = Duration;
48
53 using time_point = TimePoint<SteadyClock>;
54
59 BOOST_STATIC_CONSTEXPR bool is_steady = boost::chrono::steady_clock::is_steady;
60
61 public:
62 QI_API_DEPRECATED
63 typedef time_point SteadyClockTimePoint;
64
66 enum Expect {
67 Expect_SoonerOrLater,
68 Expect_Later,
69 Expect_Sooner
70 };
71
73 static time_point now();
74 };
75
76
85 class QI_API Clock
86 {
87 public:
88 using rep = Duration::rep;
89 using period = Duration::period;
90 using duration = Duration;
91
96 using time_point = boost::chrono::time_point<Clock>;
97
102 BOOST_STATIC_CONSTEXPR bool is_steady = boost::chrono::steady_clock::is_steady;
103
104 public:
106 enum Expect {
107 Expect_SoonerOrLater,
108 Expect_Later,
109 Expect_Sooner
110 };
111
113 static time_point now();
114
123 static uint32_t toUint32ms(const time_point &t) throw();
132 static int32_t toInt32ms(const time_point &t) throw();
133
153 static time_point fromUint32ms(uint32_t t_ms, time_point guess,
154 Expect expect=Expect_SoonerOrLater) throw();
156 static time_point fromInt32ms(int32_t t_ms, time_point guess,
157 Expect expect=Expect_SoonerOrLater) throw();
158 };
159
167 class QI_API SystemClock
168 {
169 public:
170 using rep = Duration::rep;
171 using period = Duration::period;
172 using duration = Duration;
173
178 using time_point = boost::chrono::time_point<SystemClock>;
179
182 BOOST_STATIC_CONSTEXPR bool is_steady = false;
183
184 public:
185
186 QI_API_DEPRECATED
187 typedef time_point WallClockTimePoint;
188
190 static time_point now();
191
197 static std::time_t to_time_t(const time_point& t) throw();
198
199 // Converts std::time_t to a system clock time point
205 static time_point from_time_t(const std::time_t &t) throw();
206 };
207
208 QI_API_DEPRECATED
209 typedef SystemClock WallClock;
210
211 using SteadyClockTimePoint = SteadyClock::time_point;
212 using ClockTimePoint = Clock::time_point;
213 using SystemClockTimePoint = SystemClock::time_point;
214
215 QI_API_DEPRECATED
216 typedef SystemClockTimePoint WallClockTimePoint;
217
219 QI_API_DEPRECATED
220 inline QI_API SteadyClockTimePoint steadyClockNow() {
221 return SteadyClock::now();
222 }
223
225 QI_API_DEPRECATED
226 inline QI_API SystemClockTimePoint wallClockNow() {
227 return SystemClock::now();
228 }
229
232 QI_API void sleepFor(const qi::Duration& d);
233 template <class Rep, class Period>
234 inline void sleepFor(const DurationType<Rep, Period>& d);
236
241 QI_API void sleepUntil(const SteadyClockTimePoint &t);
242 template <class Duration>
243 inline void sleepUntil(const boost::chrono::time_point<SteadyClock, Duration>& t);
245
248 QI_API void sleepUntil(const ClockTimePoint &t);
249 template <class Duration>
250 inline void sleepUntil(const boost::chrono::time_point<Clock, Duration>& t);
252
259 QI_API void sleepUntil(const SystemClockTimePoint& t);
260 template <class Duration>
261 inline void sleepUntil(const boost::chrono::time_point<SystemClock, Duration>& t);
263
272 QI_API std::string toISO8601String(const SystemClockTimePoint &t);
274
277 template <class DurationTo, class TimePointFrom>
278 inline DurationTo durationSince(const TimePointFrom& t);
280
281 template <class R, class P>
282 inline std::string to_string(const DurationType<R, P> &d);
283
284 template <class C, class D>
285 inline std::string to_string(const boost::chrono::time_point<C, D> &t);
286 }
287
288 # ifdef __APPLE__
289 // export template instanciation for RTTI issues across libraries. (mostly for OSX)
290 template class QI_API boost::chrono::duration<int64_t, boost::nano>;
291 template class QI_API boost::chrono::duration<int64_t, boost::micro>;
292 template class QI_API boost::chrono::duration<int64_t, boost::milli>;
293 template class QI_API boost::chrono::duration<int64_t>;
294 template class QI_API boost::chrono::duration<int64_t, boost::ratio<60> >;
295 template class QI_API boost::chrono::duration<int64_t, boost::ratio<3600> >;
296 template class QI_API boost::chrono::time_point<qi::SteadyClock>;
297 template class QI_API boost::chrono::time_point<qi::SystemClock>;
298 # endif
299
300 # include <qi/detail/clock.hxx>
301
302 #endif // _QI_OS_HPP_
qi::durationSince
DurationTo durationSince(const TimePointFrom &t)
}@
Definition: clock.hxx:41
qi::MicroSeconds
DurationType< int64_t, boost::micro > MicroSeconds
Definition: clock.hpp:26
qi::Clock::rep
Duration::rep rep
The representation type of the duration and time_point.
Definition: clock.hpp:88
QI_API
#define QI_API
Definition: api.hpp:33
qi::uint32_t
uint32_t uint32_t
Definition: types.hpp:65
qi::Clock::Expect_Later
Result is expected to be later than user-provided reference.
Definition: clock.hpp:108
qi::Clock::period
Duration::period period
The tick period of the clock in nanoseconds.
Definition: clock.hpp:89
qi::SteadyClockTimePoint
SteadyClock::time_point SteadyClockTimePoint
Steady clock time point.
Definition: clock.hpp:211
qi::SystemClock::duration
Duration duration
The duration type of the clock.
Definition: clock.hpp:172
qi::sleepFor
void sleepFor(const qi::Duration &d)
qi::SystemClock
The SystemClock class represents the system-wide real time wall clock. It may not be monotonic: on mo...
Definition: clock.hpp:167
qi::SteadyClock::time_point
TimePoint< SteadyClock > time_point
Definition: clock.hpp:53
qi::SteadyClock::duration
Duration duration
The duration type of the clock.
Definition: clock.hpp:47
qi::Clock::Expect
Expect
Enum expected argument.
Definition: clock.hpp:106
qi::Hours
DurationType< int64_t, boost::ratio< 3600 >> Hours
Definition: clock.hpp:30
qi::to_string
std::string to_string(const DurationType< R, P > &d)
qi::SteadyClock::rep
Duration::rep rep
The representation type of the duration and time_point.
Definition: clock.hpp:45
qi::Minutes
DurationType< int64_t, boost::ratio< 60 >> Minutes
Definition: clock.hpp:29
api.hpp
dll import/export and compiler message
types.hpp
qi::SteadyClock::Expect_Later
Result is expected to be later than user-provided reference.
Definition: clock.hpp:68
qi::toISO8601String
std::string toISO8601String(const SystemClockTimePoint &t)
Return the date and time as a string in ISO 8601 format. The time is given up to millisecond precisio...
qi::Clock::duration
Duration duration
The duration type of the clock.
Definition: clock.hpp:90
qi::Duration
NanoSeconds Duration
Definition: clock.hpp:32
qi::NanoSeconds
DurationType< int64_t, boost::nano > NanoSeconds
Definition: clock.hpp:25
qi::WallClock
QI_API_DEPRECATED typedef SystemClock WallClock
Definition: clock.hpp:209
qi::SystemClockTimePoint
SystemClock::time_point SystemClockTimePoint
System clock time point.
Definition: clock.hpp:213
qi::SteadyClock
The SteadyClock class represents a monotonic clock. <includename>qi/clock.hpp</includename> ...
Definition: clock.hpp:42
qi::MilliSeconds
DurationType< int64_t, boost::milli > MilliSeconds
Definition: clock.hpp:27
qi::wallClockNow
QI_API_DEPRECATED SystemClockTimePoint wallClockNow()
Returns a time_point representing the current value of the clock.
Definition: clock.hpp:226
qi::steadyClockNow
QI_API_DEPRECATED SteadyClockTimePoint steadyClockNow()
Returns a time_point representing the current value of the clock.
Definition: clock.hpp:220
qi::SystemClock::rep
Duration::rep rep
The representation type of the duration and time_point.
Definition: clock.hpp:170
qi::Clock::Expect_SoonerOrLater
Pick the nearest result to user-provided reference.
Definition: clock.hpp:107
qi::int32_t
int32_t int32_t
Definition: types.hpp:60
qi::SystemClock::WallClockTimePoint
QI_API_DEPRECATED typedef time_point WallClockTimePoint
Definition: clock.hpp:187
qi::SystemClock::period
Duration::period period
The tick period of the clock in nanoseconds.
Definition: clock.hpp:171
qi::SteadyClock::period
Duration::period period
The tick period of the clock in nanoseconds.
Definition: clock.hpp:46
qi::ClockTimePoint
Clock::time_point ClockTimePoint
qi::Clock time point.
Definition: clock.hpp:212
qi::WallClockTimePoint
QI_API_DEPRECATED typedef SystemClockTimePoint WallClockTimePoint
System clock time point.
Definition: clock.hpp:216
qi::SteadyClock::Expect
Expect
Enum expected argument.
Definition: clock.hpp:66
qi::SteadyClock::now
static time_point now()
Returns a time_point representing the current value of the clock.
qi::SteadyClock::SteadyClockTimePoint
QI_API_DEPRECATED typedef time_point SteadyClockTimePoint
Definition: clock.hpp:63
qi::sleepUntil
void sleepUntil(const SteadyClockTimePoint &t)
Blocks the execution of the current thread until t has been reached.
qi::Clock::time_point
boost::chrono::time_point< Clock > time_point
Definition: clock.hpp:96
qi::Seconds
DurationType< int64_t, boost::ratio< 1 >> Seconds
Definition: clock.hpp:28
qi::SystemClock::time_point
boost::chrono::time_point< SystemClock > time_point
Definition: clock.hpp:178
qi::TimePoint
boost::chrono::time_point< ClockType > TimePoint
Definition: clock.hpp:23
qi::SystemClock::now
static time_point now()
Returns a time_point representing the current value of the clock.
clock.hxx
QI_API_DEPRECATED
#define QI_API_DEPRECATED
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
Definition: macro.hpp:41
qi::DurationType
boost::chrono::duration< Rep, Ratio > DurationType
Convenience typedefs.
Definition: clock.hpp:20
qi::Clock
The Clock class represents a system-wide clock, best suitable for timestamping events. Typically monotonic and unaffected by the system clock adjustment, altough this is not guaranteed.
Definition: clock.hpp:85
qi::SteadyClock::Expect_SoonerOrLater
Pick the nearest result to user-provided reference.
Definition: clock.hpp:67