libqi-api
2.0.6.8
|
00001 /* 00002 * Copyright (c) 2013 Aldebaran Robotics. All rights reserved. 00003 * Use of this source code is governed by a BSD-style license that can be 00004 * found in the COPYING file. 00005 */ 00006 00007 #pragma once 00008 #ifndef _QI_CLOCK_HXX_ 00009 #define _QI_CLOCK_HXX_ 00010 00011 #include <boost/chrono/ceil.hpp> 00012 00013 namespace qi { 00014 00015 template <class Rep, class Period> 00016 void sleepFor(const boost::chrono::duration<Rep, Period>& d) 00017 { 00018 sleepFor(boost::chrono::ceil<SteadyClock::duration>(d)); 00019 } 00020 00021 template <class Duration> 00022 void sleepUntil(const boost::chrono::time_point<SteadyClock, Duration>& t) 00023 { 00024 sleepFor(t - SteadyClock::now()); 00025 } 00026 00027 template <class Duration> 00028 void sleepUntil(const boost::chrono::time_point<WallClock, Duration>& t) 00029 { 00030 sleepFor(t - WallClock::now()); 00031 } 00032 00033 } 00034 00035 namespace boost 00036 { 00037 namespace chrono 00038 { 00039 template <class CharT> 00040 struct clock_string<qi::SteadyClock, CharT> 00041 { 00042 static std::basic_string<CharT> name() {return "qi::steady_clock";} 00043 static std::basic_string<CharT> since() { 00044 return clock_string<boost::chrono::steady_clock, CharT>::since(); 00045 } 00046 }; 00047 00048 template <class CharT> 00049 struct clock_string<qi::WallClock, CharT> 00050 { 00051 static std::basic_string<CharT> name() {return "qi::system_clock";} 00052 static std::basic_string<CharT> since() { 00053 return clock_string<boost::chrono::system_clock, CharT>::since(); 00054 } 00055 }; 00056 } 00057 } 00058 00059 #endif // _QI_CLOCK_HXX_