libqi-api  2.4.3.28
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
clock.hxx
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_HXX_
9 #define _QI_CLOCK_HXX_
10 
11 #include <boost/chrono/ceil.hpp>
12 
13 namespace qi {
14 
15  template <class Rep, class Period>
16  void sleepFor(const boost::chrono::duration<Rep, Period>& d)
17  {
18  sleepFor(boost::chrono::ceil<SteadyClock::duration>(d));
19  }
20 
21  template <class Duration>
22  void sleepUntil(const boost::chrono::time_point<SteadyClock, Duration>& t)
23  {
25  }
26 
27  template <class Duration>
28  void sleepUntil(const boost::chrono::time_point<Clock, Duration>& t)
29  {
30  sleepFor(t - Clock::now());
31  }
32 
33  template <class Duration>
34  void sleepUntil(const boost::chrono::time_point<SystemClock, Duration>& t)
35  {
37  }
38 
39  template <class DurationTo, class TimePointFrom>
40  DurationTo durationSince(const TimePointFrom& t)
41  {
42  typedef typename TimePointFrom::clock ClockFrom;
43  return boost::chrono::duration_cast<DurationTo>(ClockFrom::now() - t);
44  }
45 }
46 
47 namespace boost
48 {
49  namespace chrono
50  {
51  template <class CharT>
52  struct clock_string<qi::SteadyClock, CharT>
53  {
54  static std::basic_string<CharT> name() {
55  static const CharT a[] = {'q', 'i', ':', ':', 'S', 't', 'e', 'a', 'd', 'y', 'C', 'l', 'o', 'c', 'k'};
56  return std::basic_string<CharT>(a, a + sizeof(a)/sizeof(a[0]));
57  }
58  static std::basic_string<CharT> since() {
59  static const CharT a[] = {' ', 's', 'i', 'n', 'c', 'e', ' ', 'p', 'r', 'o', 'g', 'r', 'a', 'm', ' ', 's', 't', 'a', 'r', 't'};
60  return std::basic_string<CharT>(a, a + sizeof(a)/sizeof(a[0]));
61  }
62  };
63 
64  template <class CharT>
65  struct clock_string<qi::Clock, CharT>
66  {
67  static std::basic_string<CharT> name() {
68  static const CharT a[] = {'q', 'i', ':', ':', 'C', 'l', 'o', 'c', 'k'};
69  return std::basic_string<CharT>(a, a + sizeof(a)/sizeof(a[0]));
70  }
71  static std::basic_string<CharT> since() {
72  return clock_string<boost::chrono::steady_clock, CharT>::since();
73  }
74  };
75 
76  template <class CharT>
77  struct clock_string<qi::SystemClock, CharT>
78  {
79  static std::basic_string<CharT> name() {
80  static const CharT a[] = {'q', 'i', ':', ':', 'S', 'y', 's', 't', 'e', 'm', 'C', 'l', 'o', 'c', 'k'};
81  return std::basic_string<CharT>(a, a + sizeof(a)/sizeof(a[0]));
82  }
83  static std::basic_string<CharT> since() {
84  return clock_string<boost::chrono::system_clock, CharT>::since();
85  }
86  };
87  }
88 }
89 
90 #endif // _QI_CLOCK_HXX_
DurationTo durationSince(const TimePointFrom &t)
}@
Definition: clock.hxx:40
void sleepFor(const qi::Duration &d)
static time_point now()
Returns a time_point representing the current value of the clock.
static time_point now()
Returns a time_point representing the current value of the clock.
void sleepUntil(const SteadyClockTimePoint &t)
Blocks the execution of the current thread until t has been reached.
static time_point now()
Returns a time_point representing the current value of the clock.