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