Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:22

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   unary_function_terminal.hpp
0009  * \author Andrey Semashev
0010  * \date   21.07.2012
0011  *
0012  * The header contains attribute value extractor adapter for constructing expression template terminals.
0013  */
0014 
0015 #ifndef BOOST_LOG_DETAIL_UNARY_FUNCTION_TERMINAL_HPP_INCLUDED_
0016 #define BOOST_LOG_DETAIL_UNARY_FUNCTION_TERMINAL_HPP_INCLUDED_
0017 
0018 #include <boost/mpl/bool.hpp>
0019 #include <boost/utility/result_of.hpp>
0020 #include <boost/fusion/sequence/intrinsic/at_c.hpp>
0021 #include <boost/phoenix/core/is_nullary.hpp>
0022 #include <boost/phoenix/core/environment.hpp>
0023 #include <boost/type_traits/remove_cv.hpp>
0024 #include <boost/type_traits/remove_reference.hpp>
0025 #include <boost/log/detail/config.hpp>
0026 #include <boost/log/detail/copy_cv.hpp>
0027 #include <boost/log/detail/custom_terminal_spec.hpp>
0028 #include <boost/log/detail/header.hpp>
0029 
0030 #ifdef BOOST_HAS_PRAGMA_ONCE
0031 #pragma once
0032 #endif
0033 
0034 namespace boost {
0035 
0036 BOOST_LOG_OPEN_NAMESPACE
0037 
0038 namespace expressions {
0039 
0040 namespace aux {
0041 
0042 /*!
0043  * \brief An adapter for a unary function to be used as a terminal in a Boost.Phoenix expression
0044  *
0045  * This class is an adapter between Boost.Phoenix expression invocation protocol and
0046  * a unary function. It forwards the call to the base function, passing only the first argument
0047  * from the original call. This allows to embed value extractors in template expressions.
0048  */
0049 template< typename FunT >
0050 class unary_function_terminal
0051 {
0052 private:
0053     //! Adopted function type
0054     typedef FunT function_type;
0055     //! Self type
0056     typedef unary_function_terminal< function_type > this_type;
0057 
0058 public:
0059     //! Internal typedef for type categorization
0060     typedef void _is_boost_log_terminal;
0061 
0062     //! Function result type
0063     template< typename >
0064     struct result;
0065 
0066     template< typename ThisT, typename ContextT >
0067     struct result< ThisT(ContextT) >
0068     {
0069         typedef typename remove_cv<
0070             typename remove_reference< typename phoenix::result_of::env< ContextT >::type >::type
0071         >::type env_type;
0072         typedef typename env_type::args_type args_type;
0073         typedef typename boost::log::aux::copy_cv< ThisT, function_type >::type cv_function_type;
0074 
0075         typedef typename boost::result_of< cv_function_type(typename fusion::result_of::at_c< args_type, 0 >::type) >::type type;
0076     };
0077 
0078 private:
0079     //! Adopted function
0080     function_type m_fun;
0081 
0082 public:
0083     //! Default constructor
0084     BOOST_DEFAULTED_FUNCTION(unary_function_terminal(), {})
0085     //! Copy constructor
0086     unary_function_terminal(unary_function_terminal const& that) : m_fun(that.m_fun) {}
0087     //! Initializing constructor
0088     template< typename ArgT1 >
0089     explicit unary_function_terminal(ArgT1 const& arg1) : m_fun(arg1) {}
0090     //! Initializing constructor
0091     template< typename ArgT1, typename ArgT2 >
0092     unary_function_terminal(ArgT1 const& arg1, ArgT2 const& arg2) : m_fun(arg1, arg2) {}
0093     //! Initializing constructor
0094     template< typename ArgT1, typename ArgT2, typename ArgT3 >
0095     unary_function_terminal(ArgT1 const& arg1, ArgT2 const& arg2, ArgT3 const& arg3) : m_fun(arg1, arg2, arg3) {}
0096 
0097     //! The operator forwards the call to the base function
0098     template< typename ContextT >
0099     typename result< this_type(ContextT const&) >::type
0100     operator() (ContextT const& ctx)
0101     {
0102         return m_fun(fusion::at_c< 0 >(phoenix::env(ctx).args()));
0103     }
0104 
0105     //! The operator forwards the call to the base function
0106     template< typename ContextT >
0107     typename result< const this_type(ContextT const&) >::type
0108     operator() (ContextT const& ctx) const
0109     {
0110         return m_fun(fusion::at_c< 0 >(phoenix::env(ctx).args()));
0111     }
0112 };
0113 
0114 } // namespace aux
0115 
0116 } // namespace expressions
0117 
0118 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0119 
0120 #ifndef BOOST_LOG_DOXYGEN_PASS
0121 
0122 namespace phoenix {
0123 
0124 namespace result_of {
0125 
0126 template< typename FunT >
0127 struct is_nullary< custom_terminal< boost::log::expressions::aux::unary_function_terminal< FunT > > > :
0128     public mpl::false_
0129 {
0130 };
0131 
0132 } // namespace result_of
0133 
0134 } // namespace phoenix
0135 
0136 #endif // BOOST_LOG_DOXYGEN_PASS
0137 
0138 } // namespace boost
0139 
0140 #include <boost/log/detail/footer.hpp>
0141 
0142 #endif // BOOST_LOG_DETAIL_UNARY_FUNCTION_TERMINAL_HPP_INCLUDED_