attr_output_impl.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 attr_output_impl.hpp
  9. * \author Andrey Semashev
  10. * \date 12.08.2012
  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.
  14. */
  15. #ifndef BOOST_LOG_DETAIL_ATTR_OUTPUT_IMPL_HPP_INCLUDED_
  16. #define BOOST_LOG_DETAIL_ATTR_OUTPUT_IMPL_HPP_INCLUDED_
  17. #include <boost/mpl/is_sequence.hpp>
  18. #include <boost/phoenix/core/actor.hpp>
  19. #include <boost/log/detail/config.hpp>
  20. #include <boost/log/expressions/attr.hpp>
  21. #include <boost/log/utility/functional/bind_to_log.hpp>
  22. #include <boost/log/detail/attr_output_terminal.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 expressions {
  30. namespace aux {
  31. template< typename LeftT, typename T, typename FallbackPolicyT, typename TagT >
  32. struct make_output_expression
  33. {
  34. //! Resulting expression
  35. typedef attribute_output_terminal< LeftT, T, FallbackPolicyT, to_log_fun< TagT > > type;
  36. //! Creates the output expression
  37. template< typename RightT >
  38. static BOOST_FORCEINLINE type make(LeftT const& left, RightT const& right)
  39. {
  40. return type(left, right.get_name(), to_log_fun< TagT >(), right.get_fallback_policy());
  41. }
  42. };
  43. template< typename LeftT, typename RightT, typename ValueT = typename RightT::value_type, bool IsSequenceV = mpl::is_sequence< ValueT >::value >
  44. struct make_output_actor;
  45. template< template< typename > class ActorT, typename LeftExprT, typename RightT, typename ValueT >
  46. struct make_output_actor< ActorT< LeftExprT >, RightT, ValueT, false >
  47. {
  48. typedef make_output_expression<
  49. ActorT< LeftExprT >,
  50. ValueT,
  51. typename RightT::fallback_policy,
  52. typename RightT::tag_type
  53. > make_expression;
  54. typedef ActorT< typename make_expression::type > type;
  55. static BOOST_FORCEINLINE type make(ActorT< LeftExprT > const& left, RightT const& right)
  56. {
  57. type res = {{ make_expression::make(left, right) }};
  58. return res;
  59. }
  60. };
  61. template< template< typename > class ActorT, typename LeftExprT, typename RightT, typename ValueT >
  62. struct make_output_actor< ActorT< LeftExprT >, RightT, ValueT, true >
  63. {
  64. typedef attribute_output_terminal< ActorT< LeftExprT >, ValueT, typename RightT::fallback_policy, to_log_fun< typename RightT::tag_type > > expression_type;
  65. typedef ActorT< expression_type > type;
  66. static BOOST_FORCEINLINE type make(ActorT< LeftExprT > const& left, RightT const& right)
  67. {
  68. type res = {{ expression_type(left, right.get_name(), to_log_fun< typename RightT::tag_type >(), right.get_fallback_policy()) }};
  69. return res;
  70. }
  71. };
  72. } // namespace aux
  73. #define BOOST_LOG_AUX_OVERLOAD(left_ref, right_ref)\
  74. template< typename LeftExprT, typename T, typename FallbackPolicyT, typename TagT >\
  75. BOOST_FORCEINLINE typename aux::make_output_actor< phoenix::actor< LeftExprT >, attribute_actor< T, FallbackPolicyT, TagT, phoenix::actor > >::type\
  76. operator<< (phoenix::actor< LeftExprT > left_ref left, attribute_actor< T, FallbackPolicyT, TagT, phoenix::actor > right_ref right)\
  77. {\
  78. return aux::make_output_actor< phoenix::actor< LeftExprT >, attribute_actor< T, FallbackPolicyT, TagT, phoenix::actor > >::make(left, right);\
  79. }
  80. #include <boost/log/detail/generate_overloads.hpp>
  81. #undef BOOST_LOG_AUX_OVERLOAD
  82. } // namespace expressions
  83. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  84. } // namespace boost
  85. #include <boost/log/detail/footer.hpp>
  86. #endif // BOOST_LOG_DETAIL_ATTR_OUTPUT_IMPL_HPP_INCLUDED_