attr_output_terminal.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 attribute_output_terminal.hpp
  9. * \author Andrey Semashev
  10. * \date 06.11.2012
  11. *
  12. * The header contains implementation of a generic output manipulator in template expressions.
  13. */
  14. #ifndef BOOST_LOG_DETAIL_ATTR_OUTPUT_TERMINAL_HPP_INCLUDED_
  15. #define BOOST_LOG_DETAIL_ATTR_OUTPUT_TERMINAL_HPP_INCLUDED_
  16. #include <boost/mpl/bool.hpp>
  17. #include <boost/phoenix/core/actor.hpp>
  18. #include <boost/phoenix/core/meta_grammar.hpp>
  19. #include <boost/phoenix/core/environment.hpp>
  20. #include <boost/phoenix/core/terminal_fwd.hpp>
  21. #include <boost/phoenix/core/is_nullary.hpp>
  22. #include <boost/type_traits/remove_cv.hpp>
  23. #include <boost/type_traits/remove_reference.hpp>
  24. #include <boost/fusion/sequence/intrinsic/at.hpp>
  25. #include <boost/log/detail/config.hpp>
  26. #include <boost/log/detail/custom_terminal_spec.hpp>
  27. #include <boost/log/attributes/attribute_name.hpp>
  28. #include <boost/log/attributes/value_visitation.hpp>
  29. #include <boost/log/utility/functional/bind.hpp>
  30. #include <boost/log/detail/header.hpp>
  31. #ifdef BOOST_HAS_PRAGMA_ONCE
  32. #pragma once
  33. #endif
  34. namespace boost {
  35. BOOST_LOG_OPEN_NAMESPACE
  36. namespace expressions {
  37. namespace aux {
  38. //! Attribute stream output expression
  39. template< typename LeftT, typename T, typename FallbackPolicyT, typename ImplT >
  40. class attribute_output_terminal
  41. {
  42. private:
  43. //! Self type
  44. typedef attribute_output_terminal< LeftT, T, FallbackPolicyT, ImplT > this_type;
  45. //! Attribute value visitor invoker
  46. typedef value_visitor_invoker< T, FallbackPolicyT > visitor_invoker_type;
  47. //! Manipulator implementation
  48. typedef ImplT impl_type;
  49. public:
  50. //! Internal typedef for type categorization
  51. typedef void _is_boost_log_terminal;
  52. //! Result type definition
  53. template< typename >
  54. struct result;
  55. template< typename ThisT, typename ContextT >
  56. struct result< ThisT(ContextT) >
  57. {
  58. typedef typename remove_cv< typename remove_reference< ContextT >::type >::type context_type;
  59. typedef typename phoenix::evaluator::impl<
  60. typename LeftT::proto_base_expr&,
  61. context_type,
  62. phoenix::unused
  63. >::result_type type;
  64. };
  65. private:
  66. //! Left argument actor
  67. LeftT m_left;
  68. //! Attribute name
  69. const attribute_name m_name;
  70. //! Attribute value visitor invoker
  71. visitor_invoker_type m_visitor_invoker;
  72. //! Manipulator implementation
  73. impl_type m_impl;
  74. public:
  75. //! Initializing constructor
  76. attribute_output_terminal(LeftT const& left, attribute_name const& name) : m_left(left), m_name(name)
  77. {
  78. }
  79. //! Initializing constructor
  80. attribute_output_terminal(LeftT const& left, attribute_name const& name, impl_type const& impl) : m_left(left), m_name(name), m_impl(impl)
  81. {
  82. }
  83. //! Initializing constructor
  84. template< typename U >
  85. attribute_output_terminal(LeftT const& left, attribute_name const& name, impl_type const& impl, U const& arg) :
  86. m_left(left), m_name(name), m_visitor_invoker(arg), m_impl(impl)
  87. {
  88. }
  89. //! Copy constructor
  90. attribute_output_terminal(attribute_output_terminal const& that) :
  91. m_left(that.m_left), m_name(that.m_name), m_visitor_invoker(that.m_visitor_invoker), m_impl(that.m_impl)
  92. {
  93. }
  94. //! Invokation operator
  95. template< typename ContextT >
  96. typename result< this_type(ContextT const&) >::type operator() (ContextT const& ctx)
  97. {
  98. typedef typename result< this_type(ContextT const&) >::type result_type;
  99. result_type strm = phoenix::eval(m_left, ctx);
  100. m_visitor_invoker(m_name, fusion::at_c< 0 >(phoenix::env(ctx).args()), binder1st< impl_type&, result_type >(m_impl, strm));
  101. return strm;
  102. }
  103. //! Invokation operator
  104. template< typename ContextT >
  105. typename result< const this_type(ContextT const&) >::type operator() (ContextT const& ctx) const
  106. {
  107. typedef typename result< const this_type(ContextT const&) >::type result_type;
  108. result_type strm = phoenix::eval(m_left, ctx);
  109. m_visitor_invoker(m_name, fusion::at_c< 0 >(phoenix::env(ctx).args()), binder1st< impl_type const&, result_type >(m_impl, strm));
  110. return strm;
  111. }
  112. BOOST_DELETED_FUNCTION(attribute_output_terminal())
  113. };
  114. } // namespace aux
  115. } // namespace expressions
  116. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  117. #ifndef BOOST_LOG_DOXYGEN_PASS
  118. namespace phoenix {
  119. namespace result_of {
  120. template< typename LeftT, typename T, typename FallbackPolicyT, typename ImplT >
  121. struct is_nullary< custom_terminal< boost::log::expressions::aux::attribute_output_terminal< LeftT, T, FallbackPolicyT, ImplT > > > :
  122. public mpl::false_
  123. {
  124. };
  125. } // namespace result_of
  126. } // namespace phoenix
  127. #endif // !defined(BOOST_LOG_DOXYGEN_PASS)
  128. } // namespace boost
  129. #include <boost/log/detail/footer.hpp>
  130. #endif // BOOST_LOG_DETAIL_ATTR_OUTPUT_TERMINAL_HPP_INCLUDED_