comparison DEPENDENCIES/generic/include/boost/asio/time_traits.hpp @ 16:2665513ce2d3

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