time_traits.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright Andrey Semashev 2007 - 2015.
  3. * Distributed under the Boost Software License, Version 1.0.
  4. * (See accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /*!
  8. * \file time_traits.hpp
  9. * \author Andrey Semashev
  10. * \date 01.12.2007
  11. *
  12. * The header contains implementation of time traits that are used in various parts of the
  13. * library to acquire current time.
  14. */
  15. #ifndef BOOST_LOG_ATTRIBUTES_TIME_TRAITS_HPP_INCLUDED_
  16. #define BOOST_LOG_ATTRIBUTES_TIME_TRAITS_HPP_INCLUDED_
  17. #include <boost/date_time/posix_time/posix_time_types.hpp>
  18. #include <boost/log/detail/config.hpp>
  19. #include <boost/log/detail/header.hpp>
  20. #ifdef BOOST_HAS_PRAGMA_ONCE
  21. #pragma once
  22. #endif
  23. namespace boost {
  24. BOOST_LOG_OPEN_NAMESPACE
  25. namespace attributes {
  26. //! Base class for time traits involving Boost.DateTime.
  27. struct basic_time_traits
  28. {
  29. //! Time type
  30. typedef posix_time::ptime time_type;
  31. //! Current time source
  32. #if defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
  33. typedef posix_time::microsec_clock clock_source;
  34. #else
  35. typedef posix_time::second_clock clock_source;
  36. #endif // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
  37. };
  38. //! Time traits that describes UTC time acquirement via Boost.DateTime facilities
  39. struct utc_time_traits :
  40. public basic_time_traits
  41. {
  42. /*!
  43. * \return Current time stamp
  44. */
  45. static time_type get_clock()
  46. {
  47. return clock_source::universal_time();
  48. }
  49. };
  50. //! Time traits that describes local time acquirement via Boost.DateTime facilities
  51. struct local_time_traits :
  52. public basic_time_traits
  53. {
  54. /*!
  55. * \return Current time stamp
  56. */
  57. static time_type get_clock()
  58. {
  59. return clock_source::local_time();
  60. }
  61. };
  62. } // namespace attributes
  63. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  64. } // namespace boost
  65. #include <boost/log/detail/footer.hpp>
  66. #endif // BOOST_LOG_ATTRIBUTES_TIME_TRAITS_HPP_INCLUDED_