as_action.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #ifndef BOOST_LOG_UTILITY_FUNCTIONAL_AS_ACTION_HPP_INCLUDED_
  15. #define BOOST_LOG_UTILITY_FUNCTIONAL_AS_ACTION_HPP_INCLUDED_
  16. #include <boost/log/detail/config.hpp>
  17. #include <boost/log/detail/header.hpp>
  18. #ifdef BOOST_HAS_PRAGMA_ONCE
  19. #pragma once
  20. #endif
  21. namespace boost {
  22. BOOST_LOG_OPEN_NAMESPACE
  23. //! Function object adapter for Boost.Spirit actions
  24. template< typename FunT >
  25. struct as_action_adapter
  26. {
  27. typedef typename FunT::result_type result_type;
  28. BOOST_DEFAULTED_FUNCTION(as_action_adapter(), {})
  29. explicit as_action_adapter(FunT const& fun) : m_fun(fun) {}
  30. template< typename AttributeT, typename ContextT >
  31. result_type operator() (AttributeT const& attr, ContextT const& ctx, bool& pass) const
  32. {
  33. return m_fun(attr);
  34. }
  35. private:
  36. FunT m_fun;
  37. };
  38. template< typename FunT >
  39. BOOST_FORCEINLINE as_action_adapter< FunT > as_action(FunT const& fun)
  40. {
  41. return as_action_adapter< FunT >(fun);
  42. }
  43. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  44. } // namespace boost
  45. #include <boost/log/detail/footer.hpp>
  46. #endif // BOOST_LOG_UTILITY_FUNCTIONAL_AS_ACTION_HPP_INCLUDED_