enqueued_record.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 enqueued_record.hpp
  9. * \author Andrey Semashev
  10. * \date 01.04.2014
  11. *
  12. * \brief This header is the Boost.Log library implementation, see the library documentation
  13. * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html. In this file
  14. * internal configuration macros are defined.
  15. */
  16. #ifndef BOOST_LOG_DETAIL_ENQUEUED_RECORD_HPP_INCLUDED_
  17. #define BOOST_LOG_DETAIL_ENQUEUED_RECORD_HPP_INCLUDED_
  18. #include <boost/move/core.hpp>
  19. #include <boost/move/utility_core.hpp>
  20. #include <boost/log/detail/config.hpp>
  21. #include <boost/log/detail/timestamp.hpp>
  22. #include <boost/log/core/record_view.hpp>
  23. #include <boost/log/detail/header.hpp>
  24. #ifdef BOOST_HAS_PRAGMA_ONCE
  25. #pragma once
  26. #endif
  27. namespace boost {
  28. BOOST_LOG_OPEN_NAMESPACE
  29. namespace sinks {
  30. namespace aux {
  31. //! Log record with enqueueing timestamp
  32. class enqueued_record
  33. {
  34. BOOST_COPYABLE_AND_MOVABLE(enqueued_record)
  35. public:
  36. //! Ordering predicate
  37. template< typename OrderT >
  38. struct order :
  39. public OrderT
  40. {
  41. typedef typename OrderT::result_type result_type;
  42. order() {}
  43. order(order const& that) : OrderT(static_cast< OrderT const& >(that)) {}
  44. order(OrderT const& that) : OrderT(that) {}
  45. result_type operator() (enqueued_record const& left, enqueued_record const& right) const
  46. {
  47. // std::priority_queue requires ordering with semantics of std::greater, so we swap arguments
  48. return OrderT::operator() (right.m_record, left.m_record);
  49. }
  50. };
  51. boost::log::aux::timestamp m_timestamp;
  52. record_view m_record;
  53. enqueued_record(enqueued_record const& that) : m_timestamp(that.m_timestamp), m_record(that.m_record)
  54. {
  55. }
  56. enqueued_record(BOOST_RV_REF(enqueued_record) that) :
  57. m_timestamp(that.m_timestamp),
  58. m_record(boost::move(that.m_record))
  59. {
  60. }
  61. explicit enqueued_record(record_view const& rec) :
  62. m_timestamp(boost::log::aux::get_timestamp()),
  63. m_record(rec)
  64. {
  65. }
  66. enqueued_record& operator= (BOOST_COPY_ASSIGN_REF(enqueued_record) that)
  67. {
  68. m_timestamp = that.m_timestamp;
  69. m_record = that.m_record;
  70. return *this;
  71. }
  72. enqueued_record& operator= (BOOST_RV_REF(enqueued_record) that)
  73. {
  74. m_timestamp = that.m_timestamp;
  75. m_record = boost::move(that.m_record);
  76. return *this;
  77. }
  78. };
  79. } // namespace aux
  80. } // namespace sinks
  81. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  82. } // namespace boost
  83. #include <boost/log/detail/footer.hpp>
  84. #endif // BOOST_LOG_DETAIL_ENQUEUED_RECORD_HPP_INCLUDED_