1 // errored_clock.hpp --------------------------------------------------------------// 2 3 // Copyright 2010 Vicente J. Botet Escriba 4 5 // Distributed under the Boost Software License, Version 1.0. 6 // See http://www.boost.org/LICENSE_1_0.txt 7 8 #ifndef BOOST_CHRONO_ERRORED_CLOCKS_HPP 9 #define BOOST_CHRONO_ERRORED_CLOCKS_HPP 10 11 #include <boost/chrono/config.hpp> 12 #include <boost/chrono/duration.hpp> 13 #include <boost/chrono/time_point.hpp> 14 #include <boost/system/error_code.hpp> 15 #include <boost/system/system_error.hpp> 16 #include <boost/throw_exception.hpp> 17 #include <boost/chrono/detail/system.hpp> 18 19 class errored_clock 20 { 21 public: 22 typedef boost::chrono::nanoseconds duration; 23 typedef duration::rep rep; 24 typedef duration::period period; 25 typedef boost::chrono::time_point<errored_clock> time_point; 26 static const bool is_steady = true; 27 static int errno_; 28 set_errno(int err)29 static void set_errno(int err) { 30 errno_=err; 31 } 32 33 // throws on error now()34 static time_point now() { 35 boost::throw_exception( 36 boost::system::system_error( 37 errno_, 38 ::boost::system::system_category(), 39 "errored_clock" 40 ) 41 ); 42 return time_point(); 43 } 44 // never throws and set ec now(boost::system::error_code & ec)45 static time_point now(boost::system::error_code & ec) { 46 if (::boost::chrono::is_throws(ec)) 47 { 48 boost::throw_exception( 49 boost::system::system_error( 50 errno_, 51 ::boost::system::system_category(), 52 "errored_clock" 53 ) 54 ); 55 } 56 ec.assign( errno_, ::boost::system::system_category() ); 57 return time_point(); 58 }; 59 }; 60 int errored_clock::errno_; 61 62 #endif 63