Chris@16: // Chris@16: // time_traits.hpp Chris@16: // ~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_TIME_TRAITS_HPP Chris@16: #define BOOST_ASIO_TIME_TRAITS_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include // Must come before posix_time. Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) \ Chris@16: || defined(GENERATING_DOCUMENTATION) Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: Chris@16: /// Time traits suitable for use with the deadline timer. Chris@16: template Chris@16: struct time_traits; Chris@16: Chris@16: /// Time traits specialised for posix_time. Chris@16: template <> Chris@16: struct time_traits Chris@16: { Chris@16: /// The time type. Chris@16: typedef boost::posix_time::ptime time_type; Chris@16: Chris@16: /// The duration type. Chris@16: typedef boost::posix_time::time_duration duration_type; Chris@16: Chris@16: /// Get the current time. Chris@16: static time_type now() Chris@16: { Chris@16: #if defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK) Chris@16: return boost::posix_time::microsec_clock::universal_time(); Chris@16: #else // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK) Chris@16: return boost::posix_time::second_clock::universal_time(); Chris@16: #endif // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK) Chris@16: } Chris@16: Chris@16: /// Add a duration to a time. Chris@16: static time_type add(const time_type& t, const duration_type& d) Chris@16: { Chris@16: return t + d; Chris@16: } Chris@16: Chris@16: /// Subtract one time from another. Chris@16: static duration_type subtract(const time_type& t1, const time_type& t2) Chris@16: { Chris@16: return t1 - t2; Chris@16: } Chris@16: Chris@16: /// Test whether one time is less than another. Chris@16: static bool less_than(const time_type& t1, const time_type& t2) Chris@16: { Chris@16: return t1 < t2; Chris@16: } Chris@16: Chris@16: /// Convert to POSIX duration type. Chris@16: static boost::posix_time::time_duration to_posix_duration( Chris@16: const duration_type& d) Chris@16: { Chris@16: return d; Chris@16: } Chris@16: }; Chris@16: Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) Chris@16: // || defined(GENERATING_DOCUMENTATION) Chris@16: Chris@16: #endif // BOOST_ASIO_TIME_TRAITS_HPP