time_traits.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // time_traits.hpp
  3. // ~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2008 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. #ifndef BOOST_ASIO_TIME_TRAITS_HPP
  11. #define BOOST_ASIO_TIME_TRAITS_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/push_options.hpp>
  16. #include <boost/asio/detail/socket_types.hpp> // Must come before posix_time.
  17. #include <boost/asio/detail/push_options.hpp>
  18. #include <boost/date_time/posix_time/posix_time_types.hpp>
  19. #include <boost/asio/detail/pop_options.hpp>
  20. namespace boost {
  21. namespace asio {
  22. /// Time traits suitable for use with the deadline timer.
  23. template <typename Time>
  24. struct time_traits;
  25. /// Time traits specialised for posix_time.
  26. template <>
  27. struct time_traits<boost::posix_time::ptime>
  28. {
  29. /// The time type.
  30. typedef boost::posix_time::ptime time_type;
  31. /// The duration type.
  32. typedef boost::posix_time::time_duration duration_type;
  33. /// Get the current time.
  34. static time_type now()
  35. {
  36. return boost::posix_time::microsec_clock::universal_time();
  37. }
  38. /// Add a duration to a time.
  39. static time_type add(const time_type& t, const duration_type& d)
  40. {
  41. return t + d;
  42. }
  43. /// Subtract one time from another.
  44. static duration_type subtract(const time_type& t1, const time_type& t2)
  45. {
  46. return t1 - t2;
  47. }
  48. /// Test whether one time is less than another.
  49. static bool less_than(const time_type& t1, const time_type& t2)
  50. {
  51. return t1 < t2;
  52. }
  53. /// Convert to POSIX duration type.
  54. static boost::posix_time::time_duration to_posix_duration(
  55. const duration_type& d)
  56. {
  57. return d;
  58. }
  59. };
  60. } // namespace asio
  61. } // namespace boost
  62. #include <boost/asio/detail/pop_options.hpp>
  63. #endif // BOOST_ASIO_TIME_TRAITS_HPP