PageRenderTime 21ms CodeModel.GetById 16ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/asio/time_traits.hpp

http://hadesmem.googlecode.com/
C++ Header | 84 lines | 49 code | 17 blank | 18 comment | 1 complexity | 63fa4e6c05ff3e94ed149df6f28eafe5 MD5 | raw file
 1//
 2// time_traits.hpp
 3// ~~~~~~~~~~~~~~~
 4//
 5// Copyright (c) 2003-2011 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#include <boost/asio/detail/push_options.hpp>
21#include <boost/date_time/posix_time/posix_time_types.hpp>
22#include <boost/asio/detail/pop_options.hpp>
23
24#include <boost/asio/detail/push_options.hpp>
25
26namespace boost {
27namespace asio {
28
29/// Time traits suitable for use with the deadline timer.
30template <typename Time>
31struct time_traits;
32
33/// Time traits specialised for posix_time.
34template <>
35struct time_traits<boost::posix_time::ptime>
36{
37  /// The time type.
38  typedef boost::posix_time::ptime time_type;
39
40  /// The duration type.
41  typedef boost::posix_time::time_duration duration_type;
42
43  /// Get the current time.
44  static time_type now()
45  {
46#if defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
47    return boost::posix_time::microsec_clock::universal_time();
48#else // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
49    return boost::posix_time::second_clock::universal_time();
50#endif // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
51  }
52
53  /// Add a duration to a time.
54  static time_type add(const time_type& t, const duration_type& d)
55  {
56    return t + d;
57  }
58
59  /// Subtract one time from another.
60  static duration_type subtract(const time_type& t1, const time_type& t2)
61  {
62    return t1 - t2;
63  }
64
65  /// Test whether one time is less than another.
66  static bool less_than(const time_type& t1, const time_type& t2)
67  {
68    return t1 < t2;
69  }
70
71  /// Convert to POSIX duration type.
72  static boost::posix_time::time_duration to_posix_duration(
73      const duration_type& d)
74  {
75    return d;
76  }
77};
78
79} // namespace asio
80} // namespace boost
81
82#include <boost/asio/detail/pop_options.hpp>
83
84#endif // BOOST_ASIO_TIME_TRAITS_HPP