Chris@16
|
1 //
|
Chris@16
|
2 // time_traits.hpp
|
Chris@16
|
3 // ~~~~~~~~~~~~~~~
|
Chris@16
|
4 //
|
Chris@16
|
5 // Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
Chris@16
|
6 //
|
Chris@16
|
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 //
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_ASIO_TIME_TRAITS_HPP
|
Chris@16
|
12 #define BOOST_ASIO_TIME_TRAITS_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
15 # pragma once
|
Chris@16
|
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/asio/detail/socket_types.hpp> // Must come before posix_time.
|
Chris@16
|
19
|
Chris@16
|
20 #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) \
|
Chris@16
|
21 || defined(GENERATING_DOCUMENTATION)
|
Chris@16
|
22
|
Chris@16
|
23 #include <boost/asio/detail/push_options.hpp>
|
Chris@16
|
24 #include <boost/date_time/posix_time/posix_time_types.hpp>
|
Chris@16
|
25 #include <boost/asio/detail/pop_options.hpp>
|
Chris@16
|
26
|
Chris@16
|
27 #include <boost/asio/detail/push_options.hpp>
|
Chris@16
|
28
|
Chris@16
|
29 namespace boost {
|
Chris@16
|
30 namespace asio {
|
Chris@16
|
31
|
Chris@16
|
32 /// Time traits suitable for use with the deadline timer.
|
Chris@16
|
33 template <typename Time>
|
Chris@16
|
34 struct time_traits;
|
Chris@16
|
35
|
Chris@16
|
36 /// Time traits specialised for posix_time.
|
Chris@16
|
37 template <>
|
Chris@16
|
38 struct time_traits<boost::posix_time::ptime>
|
Chris@16
|
39 {
|
Chris@16
|
40 /// The time type.
|
Chris@16
|
41 typedef boost::posix_time::ptime time_type;
|
Chris@16
|
42
|
Chris@16
|
43 /// The duration type.
|
Chris@16
|
44 typedef boost::posix_time::time_duration duration_type;
|
Chris@16
|
45
|
Chris@16
|
46 /// Get the current time.
|
Chris@16
|
47 static time_type now()
|
Chris@16
|
48 {
|
Chris@16
|
49 #if defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
|
Chris@16
|
50 return boost::posix_time::microsec_clock::universal_time();
|
Chris@16
|
51 #else // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
|
Chris@16
|
52 return boost::posix_time::second_clock::universal_time();
|
Chris@16
|
53 #endif // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
|
Chris@16
|
54 }
|
Chris@16
|
55
|
Chris@16
|
56 /// Add a duration to a time.
|
Chris@16
|
57 static time_type add(const time_type& t, const duration_type& d)
|
Chris@16
|
58 {
|
Chris@16
|
59 return t + d;
|
Chris@16
|
60 }
|
Chris@16
|
61
|
Chris@16
|
62 /// Subtract one time from another.
|
Chris@16
|
63 static duration_type subtract(const time_type& t1, const time_type& t2)
|
Chris@16
|
64 {
|
Chris@16
|
65 return t1 - t2;
|
Chris@16
|
66 }
|
Chris@16
|
67
|
Chris@16
|
68 /// Test whether one time is less than another.
|
Chris@16
|
69 static bool less_than(const time_type& t1, const time_type& t2)
|
Chris@16
|
70 {
|
Chris@16
|
71 return t1 < t2;
|
Chris@16
|
72 }
|
Chris@16
|
73
|
Chris@16
|
74 /// Convert to POSIX duration type.
|
Chris@16
|
75 static boost::posix_time::time_duration to_posix_duration(
|
Chris@16
|
76 const duration_type& d)
|
Chris@16
|
77 {
|
Chris@16
|
78 return d;
|
Chris@16
|
79 }
|
Chris@16
|
80 };
|
Chris@16
|
81
|
Chris@16
|
82 } // namespace asio
|
Chris@16
|
83 } // namespace boost
|
Chris@16
|
84
|
Chris@16
|
85 #include <boost/asio/detail/pop_options.hpp>
|
Chris@16
|
86
|
Chris@16
|
87 #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
|
Chris@16
|
88 // || defined(GENERATING_DOCUMENTATION)
|
Chris@16
|
89
|
Chris@16
|
90 #endif // BOOST_ASIO_TIME_TRAITS_HPP
|