Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:30:00

0001 //
0002 // time_traits.hpp
0003 // ~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2025 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_NO_DEPRECATED)
0021 
0022 #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) \
0023   || defined(GENERATING_DOCUMENTATION)
0024 
0025 #include <boost/date_time/posix_time/posix_time_types.hpp>
0026 
0027 #include <boost/asio/detail/push_options.hpp>
0028 
0029 namespace boost {
0030 namespace asio {
0031 
0032 /// (Deprecated) Time traits suitable for use with the deadline timer.
0033 template <typename Time>
0034 struct time_traits;
0035 
0036 /// (Deprecated) Time traits specialised for posix_time.
0037 template <>
0038 struct time_traits<boost::posix_time::ptime>
0039 {
0040   /// The time type.
0041   typedef boost::posix_time::ptime time_type;
0042 
0043   /// The duration type.
0044   typedef boost::posix_time::time_duration duration_type;
0045 
0046   /// Get the current time.
0047   static time_type now()
0048   {
0049 #if defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
0050     return boost::posix_time::microsec_clock::universal_time();
0051 #else // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
0052     return boost::posix_time::second_clock::universal_time();
0053 #endif // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
0054   }
0055 
0056   /// Add a duration to a time.
0057   static time_type add(const time_type& t, const duration_type& d)
0058   {
0059     return t + d;
0060   }
0061 
0062   /// Subtract one time from another.
0063   static duration_type subtract(const time_type& t1, const time_type& t2)
0064   {
0065     return t1 - t2;
0066   }
0067 
0068   /// Test whether one time is less than another.
0069   static bool less_than(const time_type& t1, const time_type& t2)
0070   {
0071     return t1 < t2;
0072   }
0073 
0074   /// Convert to POSIX duration type.
0075   static boost::posix_time::time_duration to_posix_duration(
0076       const duration_type& d)
0077   {
0078     return d;
0079   }
0080 };
0081 
0082 } // namespace asio
0083 } // namespace boost
0084 
0085 #include <boost/asio/detail/pop_options.hpp>
0086 
0087 #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
0088        // || defined(GENERATING_DOCUMENTATION)
0089 
0090 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
0091 
0092 #endif // BOOST_ASIO_TIME_TRAITS_HPP