Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:12

0001 //
0002 // time_traits.hpp
0003 // ~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_TIME_TRAITS_HPP
0012 #define BOOST_ASIO_TIME_TRAITS_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/socket_types.hpp> // Must come before posix_time.
0019 
0020 #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) \
0021   || defined(GENERATING_DOCUMENTATION)
0022 
0023 #include <boost/date_time/posix_time/posix_time_types.hpp>
0024 
0025 #include <boost/asio/detail/push_options.hpp>
0026 
0027 namespace boost {
0028 namespace asio {
0029 
0030 /// Time traits suitable for use with the deadline timer.
0031 template <typename Time>
0032 struct time_traits;
0033 
0034 /// Time traits specialised for posix_time.
0035 template <>
0036 struct time_traits<boost::posix_time::ptime>
0037 {
0038   /// The time type.
0039   typedef boost::posix_time::ptime time_type;
0040 
0041   /// The duration type.
0042   typedef boost::posix_time::time_duration duration_type;
0043 
0044   /// Get the current time.
0045   static time_type now()
0046   {
0047 #if defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
0048     return boost::posix_time::microsec_clock::universal_time();
0049 #else // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
0050     return boost::posix_time::second_clock::universal_time();
0051 #endif // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
0052   }
0053 
0054   /// Add a duration to a time.
0055   static time_type add(const time_type& t, const duration_type& d)
0056   {
0057     return t + d;
0058   }
0059 
0060   /// Subtract one time from another.
0061   static duration_type subtract(const time_type& t1, const time_type& t2)
0062   {
0063     return t1 - t2;
0064   }
0065 
0066   /// Test whether one time is less than another.
0067   static bool less_than(const time_type& t1, const time_type& t2)
0068   {
0069     return t1 < t2;
0070   }
0071 
0072   /// Convert to POSIX duration type.
0073   static boost::posix_time::time_duration to_posix_duration(
0074       const duration_type& d)
0075   {
0076     return d;
0077   }
0078 };
0079 
0080 } // namespace asio
0081 } // namespace boost
0082 
0083 #include <boost/asio/detail/pop_options.hpp>
0084 
0085 #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
0086        // || defined(GENERATING_DOCUMENTATION)
0087 
0088 #endif // BOOST_ASIO_TIME_TRAITS_HPP