Chris@16
|
1 /*
|
Chris@16
|
2 * Copyright Andrey Semashev 2007 - 2013.
|
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 unary_function_terminal.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 21.07.2012
|
Chris@16
|
11 *
|
Chris@16
|
12 * The header contains attribute value extractor adapter for constructing expression template terminals.
|
Chris@16
|
13 */
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_LOG_DETAIL_UNARY_FUNCTION_TERMINAL_HPP_INCLUDED_
|
Chris@16
|
16 #define BOOST_LOG_DETAIL_UNARY_FUNCTION_TERMINAL_HPP_INCLUDED_
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/mpl/bool.hpp>
|
Chris@16
|
19 #include <boost/utility/result_of.hpp>
|
Chris@16
|
20 #include <boost/fusion/sequence/intrinsic/at_c.hpp>
|
Chris@16
|
21 #include <boost/phoenix/core/is_nullary.hpp>
|
Chris@16
|
22 #include <boost/phoenix/core/environment.hpp>
|
Chris@16
|
23 #include <boost/type_traits/remove_cv.hpp>
|
Chris@16
|
24 #include <boost/type_traits/remove_reference.hpp>
|
Chris@16
|
25 #include <boost/log/detail/config.hpp>
|
Chris@16
|
26 #include <boost/log/detail/custom_terminal_spec.hpp>
|
Chris@16
|
27 #include <boost/log/detail/header.hpp>
|
Chris@16
|
28
|
Chris@16
|
29 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
30 #pragma once
|
Chris@16
|
31 #endif
|
Chris@16
|
32
|
Chris@16
|
33 namespace boost {
|
Chris@16
|
34
|
Chris@16
|
35 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
36
|
Chris@16
|
37 namespace expressions {
|
Chris@16
|
38
|
Chris@16
|
39 namespace aux {
|
Chris@16
|
40
|
Chris@16
|
41 /*!
|
Chris@16
|
42 * \brief An adapter for a unary function to be used as a terminal in a Boost.Phoenix expression
|
Chris@16
|
43 *
|
Chris@16
|
44 * This class is an adapter between Boost.Phoenix expression invocation protocol and
|
Chris@16
|
45 * a unary function. It forwards the call to the base function, passing only the first argument
|
Chris@16
|
46 * from the original call. This allows to embed value extractors in template expressions.
|
Chris@16
|
47 */
|
Chris@16
|
48 template< typename FunT >
|
Chris@16
|
49 class unary_function_terminal
|
Chris@16
|
50 {
|
Chris@16
|
51 private:
|
Chris@16
|
52 //! Adopted function type
|
Chris@16
|
53 typedef FunT function_type;
|
Chris@16
|
54 //! Self type
|
Chris@16
|
55 typedef unary_function_terminal< function_type > this_type;
|
Chris@16
|
56
|
Chris@16
|
57 public:
|
Chris@16
|
58 //! Internal typedef for type categorization
|
Chris@16
|
59 typedef void _is_boost_log_terminal;
|
Chris@16
|
60
|
Chris@16
|
61 //! Function result type
|
Chris@16
|
62 template< typename >
|
Chris@16
|
63 struct result;
|
Chris@16
|
64
|
Chris@16
|
65 template< typename ContextT >
|
Chris@16
|
66 struct result< this_type(ContextT) >
|
Chris@16
|
67 {
|
Chris@16
|
68 typedef typename remove_cv<
|
Chris@16
|
69 typename remove_reference< typename phoenix::result_of::env< ContextT >::type >::type
|
Chris@16
|
70 >::type env_type;
|
Chris@16
|
71 typedef typename env_type::args_type args_type;
|
Chris@16
|
72
|
Chris@16
|
73 typedef typename boost::result_of< function_type(typename fusion::result_of::at_c< args_type, 0 >::type) >::type type;
|
Chris@16
|
74 };
|
Chris@16
|
75
|
Chris@16
|
76 template< typename ContextT >
|
Chris@16
|
77 struct result< const this_type(ContextT) >
|
Chris@16
|
78 {
|
Chris@16
|
79 typedef typename remove_cv<
|
Chris@16
|
80 typename remove_reference< typename phoenix::result_of::env< ContextT >::type >::type
|
Chris@16
|
81 >::type env_type;
|
Chris@16
|
82 typedef typename env_type::args_type args_type;
|
Chris@16
|
83
|
Chris@16
|
84 typedef typename boost::result_of< const function_type(typename fusion::result_of::at_c< args_type, 0 >::type) >::type type;
|
Chris@16
|
85 };
|
Chris@16
|
86
|
Chris@16
|
87 private:
|
Chris@16
|
88 //! Adopted function
|
Chris@16
|
89 function_type m_fun;
|
Chris@16
|
90
|
Chris@16
|
91 public:
|
Chris@16
|
92 //! Default constructor
|
Chris@16
|
93 BOOST_DEFAULTED_FUNCTION(unary_function_terminal(), {})
|
Chris@16
|
94 //! Copy constructor
|
Chris@16
|
95 unary_function_terminal(unary_function_terminal const& that) : m_fun(that.m_fun) {}
|
Chris@16
|
96 //! Initializing constructor
|
Chris@16
|
97 template< typename ArgT1 >
|
Chris@16
|
98 explicit unary_function_terminal(ArgT1 const& arg1) : m_fun(arg1) {}
|
Chris@16
|
99 //! Initializing constructor
|
Chris@16
|
100 template< typename ArgT1, typename ArgT2 >
|
Chris@16
|
101 unary_function_terminal(ArgT1 const& arg1, ArgT2 const& arg2) : m_fun(arg1, arg2) {}
|
Chris@16
|
102 //! Initializing constructor
|
Chris@16
|
103 template< typename ArgT1, typename ArgT2, typename ArgT3 >
|
Chris@16
|
104 unary_function_terminal(ArgT1 const& arg1, ArgT2 const& arg2, ArgT3 const& arg3) : m_fun(arg1, arg2, arg3) {}
|
Chris@16
|
105
|
Chris@16
|
106 //! The operator forwards the call to the base function
|
Chris@16
|
107 template< typename ContextT >
|
Chris@16
|
108 typename result< this_type(ContextT const&) >::type
|
Chris@16
|
109 operator() (ContextT const& ctx)
|
Chris@16
|
110 {
|
Chris@16
|
111 return m_fun(fusion::at_c< 0 >(phoenix::env(ctx).args()));
|
Chris@16
|
112 }
|
Chris@16
|
113
|
Chris@16
|
114 //! The operator forwards the call to the base function
|
Chris@16
|
115 template< typename ContextT >
|
Chris@16
|
116 typename result< const this_type(ContextT const&) >::type
|
Chris@16
|
117 operator() (ContextT const& ctx) const
|
Chris@16
|
118 {
|
Chris@16
|
119 return m_fun(fusion::at_c< 0 >(phoenix::env(ctx).args()));
|
Chris@16
|
120 }
|
Chris@16
|
121 };
|
Chris@16
|
122
|
Chris@16
|
123 } // namespace aux
|
Chris@16
|
124
|
Chris@16
|
125 } // namespace expressions
|
Chris@16
|
126
|
Chris@16
|
127 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
128
|
Chris@16
|
129 #ifndef BOOST_LOG_DOXYGEN_PASS
|
Chris@16
|
130
|
Chris@16
|
131 namespace phoenix {
|
Chris@16
|
132
|
Chris@16
|
133 namespace result_of {
|
Chris@16
|
134
|
Chris@16
|
135 template< typename FunT >
|
Chris@16
|
136 struct is_nullary< custom_terminal< boost::log::expressions::aux::unary_function_terminal< FunT > > > :
|
Chris@16
|
137 public mpl::false_
|
Chris@16
|
138 {
|
Chris@16
|
139 };
|
Chris@16
|
140
|
Chris@16
|
141 } // namespace result_of
|
Chris@16
|
142
|
Chris@16
|
143 } // namespace phoenix
|
Chris@16
|
144
|
Chris@16
|
145 #endif // BOOST_LOG_DOXYGEN_PASS
|
Chris@16
|
146
|
Chris@16
|
147 } // namespace boost
|
Chris@16
|
148
|
Chris@16
|
149 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
150
|
Chris@16
|
151 #endif // BOOST_LOG_DETAIL_UNARY_FUNCTION_TERMINAL_HPP_INCLUDED_
|