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 formatters/format.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 15.11.2012 Chris@16: * Chris@16: * The header contains a generic log record formatter function. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_EXPRESSIONS_FORMATTERS_FORMAT_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_EXPRESSIONS_FORMATTERS_FORMAT_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@16: #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: /*! Chris@16: * \brief Template expressions terminal node with Boost.Format-like formatter Chris@16: */ Chris@16: template< typename CharT > Chris@16: class format_terminal Chris@16: { Chris@16: public: Chris@16: //! Internal typedef for type categorization Chris@16: typedef void _is_boost_log_terminal; Chris@16: Chris@16: //! Character type Chris@16: typedef CharT char_type; Chris@16: //! Boost.Format formatter type Chris@16: typedef boost::log::aux::basic_format< char_type > format_type; Chris@16: //! String type Chris@16: typedef std::basic_string< char_type > string_type; Chris@16: Chris@16: //! Terminal result type Chris@16: typedef typename format_type::pump result_type; Chris@16: Chris@16: private: Chris@16: //! Formatter object Chris@16: mutable format_type m_format; Chris@16: Chris@16: public: Chris@16: //! Initializing constructor Chris@16: explicit format_terminal(const char_type* format) : m_format(format) {} Chris@16: Chris@16: //! Invokation operator Chris@16: template< typename ContextT > Chris@16: result_type operator() (ContextT const& ctx) const Chris@16: { Chris@16: return m_format.make_pump(fusion::at_c< 1 >(phoenix::env(ctx).args())); Chris@16: } Chris@16: Chris@16: BOOST_DELETED_FUNCTION(format_terminal()) Chris@16: }; Chris@16: Chris@16: /*! Chris@16: * The function generates a terminal node in a template expression. The node will perform log record formatting Chris@16: * according to the provided format string. Chris@16: */ Chris@16: template< typename CharT > Chris@16: BOOST_FORCEINLINE phoenix::actor< format_terminal< CharT > > format(const CharT* fmt) Chris@16: { Chris@16: typedef format_terminal< CharT > terminal_type; Chris@16: phoenix::actor< terminal_type > act = {{ terminal_type(fmt) }}; Chris@16: return act; Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function generates a terminal node in a template expression. The node will perform log record formatting Chris@16: * according to the provided format string. Chris@16: */ Chris@16: template< typename CharT, typename TraitsT, typename AllocatorT > Chris@16: BOOST_FORCEINLINE phoenix::actor< format_terminal< CharT > > format(std::basic_string< CharT, TraitsT, AllocatorT > const& fmt) Chris@16: { Chris@16: typedef format_terminal< CharT > terminal_type; Chris@16: phoenix::actor< terminal_type > act = {{ terminal_type(fmt.c_str()) }}; Chris@16: return act; Chris@16: } 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 CharT > Chris@16: struct is_nullary< custom_terminal< boost::log::expressions::format_terminal< CharT > > > : 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 Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_LOG_EXPRESSIONS_FORMATTERS_FORMAT_HPP_INCLUDED_