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 as_action.hpp 9 * \author Andrey Semashev 10 * \date 30.03.2008 11 * 12 * This header contains function object adapter for compatibility with Boost.Spirit actions interface requirements. 13 */ 14 15 #ifndef BOOST_LOG_UTILITY_FUNCTIONAL_AS_ACTION_HPP_INCLUDED_ 16 #define BOOST_LOG_UTILITY_FUNCTIONAL_AS_ACTION_HPP_INCLUDED_ 17 18 #include <boost/log/detail/config.hpp> 19 #include <boost/log/detail/header.hpp> 20 21 #ifdef BOOST_HAS_PRAGMA_ONCE 22 #pragma once 23 #endif 24 25 namespace boost { 26 27 BOOST_LOG_OPEN_NAMESPACE 28 29 //! Function object adapter for Boost.Spirit actions 30 template< typename FunT > 31 struct as_action_adapter 32 { 33 typedef typename FunT::result_type result_type; 34 as_action_adapterboost::as_action_adapter35 BOOST_DEFAULTED_FUNCTION(as_action_adapter(), {}) 36 explicit as_action_adapter(FunT const& fun) : m_fun(fun) {} 37 38 template< typename AttributeT, typename ContextT > operator ()boost::as_action_adapter39 result_type operator() (AttributeT const& attr, ContextT const& ctx, bool& pass) const 40 { 41 return m_fun(attr); 42 } 43 44 private: 45 FunT m_fun; 46 }; 47 48 template< typename FunT > as_action(FunT const & fun)49BOOST_FORCEINLINE as_action_adapter< FunT > as_action(FunT const& fun) 50 { 51 return as_action_adapter< FunT >(fun); 52 } 53 54 BOOST_LOG_CLOSE_NAMESPACE // namespace log 55 56 } // namespace boost 57 58 #include <boost/log/detail/footer.hpp> 59 60 #endif // BOOST_LOG_UTILITY_FUNCTIONAL_AS_ACTION_HPP_INCLUDED_ 61