Chris@16: /* Chris@101: * Copyright Andrey Semashev 2007 - 2015. Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: /*! Chris@16: * \file unary_function_terminal.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 21.07.2012 Chris@16: * Chris@16: * The header contains attribute value extractor adapter for constructing expression template terminals. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_DETAIL_UNARY_FUNCTION_TERMINAL_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_DETAIL_UNARY_FUNCTION_TERMINAL_HPP_INCLUDED_ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: BOOST_LOG_OPEN_NAMESPACE Chris@16: Chris@16: namespace expressions { Chris@16: Chris@16: namespace aux { Chris@16: Chris@16: /*! Chris@16: * \brief An adapter for a unary function to be used as a terminal in a Boost.Phoenix expression Chris@16: * Chris@16: * This class is an adapter between Boost.Phoenix expression invocation protocol and Chris@16: * a unary function. It forwards the call to the base function, passing only the first argument Chris@16: * from the original call. This allows to embed value extractors in template expressions. Chris@16: */ Chris@16: template< typename FunT > Chris@16: class unary_function_terminal Chris@16: { Chris@16: private: Chris@16: //! Adopted function type Chris@16: typedef FunT function_type; Chris@16: //! Self type Chris@16: typedef unary_function_terminal< function_type > this_type; Chris@16: Chris@16: public: Chris@16: //! Internal typedef for type categorization Chris@16: typedef void _is_boost_log_terminal; Chris@16: Chris@16: //! Function result type Chris@16: template< typename > Chris@16: struct result; Chris@16: Chris@101: template< typename ThisT, typename ContextT > Chris@101: struct result< ThisT(ContextT) > Chris@16: { Chris@16: typedef typename remove_cv< Chris@16: typename remove_reference< typename phoenix::result_of::env< ContextT >::type >::type Chris@16: >::type env_type; Chris@16: typedef typename env_type::args_type args_type; Chris@101: typedef typename boost::log::aux::copy_cv< ThisT, function_type >::type cv_function_type; Chris@16: Chris@101: typedef typename boost::result_of< cv_function_type(typename fusion::result_of::at_c< args_type, 0 >::type) >::type type; Chris@16: }; Chris@16: Chris@16: private: Chris@16: //! Adopted function Chris@16: function_type m_fun; Chris@16: Chris@16: public: Chris@16: //! Default constructor Chris@16: BOOST_DEFAULTED_FUNCTION(unary_function_terminal(), {}) Chris@16: //! Copy constructor Chris@16: unary_function_terminal(unary_function_terminal const& that) : m_fun(that.m_fun) {} Chris@16: //! Initializing constructor Chris@16: template< typename ArgT1 > Chris@16: explicit unary_function_terminal(ArgT1 const& arg1) : m_fun(arg1) {} Chris@16: //! Initializing constructor Chris@16: template< typename ArgT1, typename ArgT2 > Chris@16: unary_function_terminal(ArgT1 const& arg1, ArgT2 const& arg2) : m_fun(arg1, arg2) {} Chris@16: //! Initializing constructor Chris@16: template< typename ArgT1, typename ArgT2, typename ArgT3 > Chris@16: unary_function_terminal(ArgT1 const& arg1, ArgT2 const& arg2, ArgT3 const& arg3) : m_fun(arg1, arg2, arg3) {} Chris@16: Chris@16: //! The operator forwards the call to the base function Chris@16: template< typename ContextT > Chris@16: typename result< this_type(ContextT const&) >::type Chris@16: operator() (ContextT const& ctx) Chris@16: { Chris@16: return m_fun(fusion::at_c< 0 >(phoenix::env(ctx).args())); Chris@16: } Chris@16: Chris@16: //! The operator forwards the call to the base function Chris@16: template< typename ContextT > Chris@16: typename result< const this_type(ContextT const&) >::type Chris@16: operator() (ContextT const& ctx) const Chris@16: { Chris@16: return m_fun(fusion::at_c< 0 >(phoenix::env(ctx).args())); Chris@16: } Chris@16: }; Chris@16: Chris@16: } // namespace aux Chris@16: Chris@16: } // namespace expressions Chris@16: Chris@16: BOOST_LOG_CLOSE_NAMESPACE // namespace log Chris@16: Chris@16: #ifndef BOOST_LOG_DOXYGEN_PASS Chris@16: Chris@16: namespace phoenix { Chris@16: Chris@16: namespace result_of { Chris@16: Chris@16: template< typename FunT > Chris@16: struct is_nullary< custom_terminal< boost::log::expressions::aux::unary_function_terminal< FunT > > > : Chris@16: public mpl::false_ Chris@16: { Chris@16: }; Chris@16: Chris@16: } // namespace result_of Chris@16: Chris@16: } // namespace phoenix Chris@16: Chris@16: #endif // BOOST_LOG_DOXYGEN_PASS Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_LOG_DETAIL_UNARY_FUNCTION_TERMINAL_HPP_INCLUDED_