11 #include <boost/chrono/ceil.hpp>
16 template <
class Rep,
class Period>
17 void sleepFor(
const boost::chrono::duration<Rep, Period>& d)
19 sleepFor(boost::chrono::ceil<SteadyClock::duration>(d));
22 template <
class Duration>
23 void sleepUntil(
const boost::chrono::time_point<SteadyClock, Duration>& t)
28 template <
class Duration>
29 void sleepUntil(
const boost::chrono::time_point<Clock, Duration>& t)
34 template <
class Duration>
35 void sleepUntil(
const boost::chrono::time_point<SystemClock, Duration>& t)
40 template <
class DurationTo,
class TimePo
intFrom>
43 using ClockFrom =
typename TimePointFrom::clock;
44 return boost::chrono::duration_cast<DurationTo>(ClockFrom::now() - t);
49 template <
class Period>
53 inline void write_duration_unit_long_name<boost::nano>(std::ostream &os) {
54 static const char a[] = {
'n',
'a',
'n',
'o',
's',
'e',
'c',
'o',
'n',
'd',
's'};
55 os.write(a,
sizeof(a)/
sizeof(
char));
59 inline void write_duration_unit_long_name<boost::micro>(std::ostream &os) {
60 static const char a[] = {
'm',
'i',
'c',
'r',
'o',
's',
'e',
'c',
'o',
'n',
'd',
's'};
61 os.write(a,
sizeof(a)/
sizeof(
char));
65 inline void write_duration_unit_long_name<boost::milli>(std::ostream &os) {
66 static const char a[] = {
'm',
'i',
'l',
'l',
'i',
's',
'e',
'c',
'o',
'n',
'd',
's'};
67 os.write(a,
sizeof(a)/
sizeof(
char));
71 inline void write_duration_unit_long_name<boost::ratio<1, 1>>(std::ostream &os) {
72 static const char a[] = {
's',
'e',
'c',
'o',
'n',
'd',
's'};
73 os.write(a,
sizeof(a)/
sizeof(
char));
77 inline void write_duration_unit_long_name<boost::ratio<60, 1>>(std::ostream &os) {
78 static const char a[] = {
'm',
'i',
'n',
'u',
't',
'e',
's'};
79 os.write(a,
sizeof(a)/
sizeof(
char));
83 inline void write_duration_unit_long_name<boost::ratio<3600, 1>>(std::ostream &os) {
84 static const char a[] = {
'h',
'o',
'u',
'r',
's'};
85 os.write(a,
sizeof(a)/
sizeof(
char));
89 template <
class R,
class P>
90 inline std::string
to_string(
const boost::chrono::duration<R, P> &d)
92 std::ostringstream os;
93 os << d.count() <<
' ';
94 detail::write_duration_unit_long_name<P>(os);
98 template <
class C,
class D>
99 inline std::string
to_string(
const boost::chrono::time_point<C, D> &t)
101 std::ostringstream os;
102 os << t.time_since_epoch().count() <<
' ';
103 detail::write_duration_unit_long_name<typename D::period>(os);
104 os << boost::chrono::clock_string<C, char>::since();
114 template <
class CharT>
115 struct clock_string<qi::SteadyClock, CharT>
117 static std::basic_string<CharT>
name() {
118 static const CharT a[] = {
'q',
'i',
':',
':',
'S',
't',
'e',
'a',
'd',
'y',
'C',
'l',
'o',
'c',
'k'};
119 return std::basic_string<CharT>(a, a +
sizeof(a)/
sizeof(a[0]));
121 static std::basic_string<CharT> since() {
122 static const CharT a[] = {
' ',
's',
'i',
'n',
'c',
'e',
' ',
'p',
'r',
'o',
'g',
'r',
'a',
'm',
' ',
's',
't',
'a',
'r',
't'};
123 return std::basic_string<CharT>(a, a +
sizeof(a)/
sizeof(a[0]));
127 template <
class CharT>
128 struct clock_string<qi::Clock, CharT>
130 static std::basic_string<CharT>
name() {
131 static const CharT a[] = {
'q',
'i',
':',
':',
'C',
'l',
'o',
'c',
'k'};
132 return std::basic_string<CharT>(a, a +
sizeof(a)/
sizeof(a[0]));
134 static std::basic_string<CharT> since() {
135 return clock_string<boost::chrono::steady_clock, CharT>::since();
139 template <
class CharT>
140 struct clock_string<qi::SystemClock, CharT>
142 static std::basic_string<CharT>
name() {
143 static const CharT a[] = {
'q',
'i',
':',
':',
'S',
'y',
's',
't',
'e',
'm',
'C',
'l',
'o',
'c',
'k'};
144 return std::basic_string<CharT>(a, a +
sizeof(a)/
sizeof(a[0]));
146 static std::basic_string<CharT> since() {
147 return clock_string<boost::chrono::system_clock, CharT>::since();
153 #endif // _QI_CLOCK_HXX_
DurationTo durationSince(const TimePointFrom &t)
}@
void sleepFor(const qi::Duration &d)
std::string to_string(const DurationType< R, P > &d)
static time_point now()
Returns a time_point representing the current value of the clock.
void write_duration_unit_long_name(std::ostream &os)
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.