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)
8 * \file formatters/format.hpp
9 * \author Andrey Semashev
12 * The header contains a generic log record formatter function.
15 #ifndef BOOST_LOG_EXPRESSIONS_FORMATTERS_FORMAT_HPP_INCLUDED_
16 #define BOOST_LOG_EXPRESSIONS_FORMATTERS_FORMAT_HPP_INCLUDED_
19 #include <boost/mpl/bool.hpp>
20 #include <boost/phoenix/core/actor.hpp>
21 #include <boost/phoenix/core/terminal_fwd.hpp>
22 #include <boost/phoenix/core/is_nullary.hpp>
23 #include <boost/phoenix/core/environment.hpp>
24 #include <boost/fusion/sequence/intrinsic/at_c.hpp>
25 #include <boost/log/detail/config.hpp>
26 #include <boost/log/detail/format.hpp>
27 #include <boost/log/detail/custom_terminal_spec.hpp>
28 #include <boost/log/detail/header.hpp>
30 #ifdef BOOST_HAS_PRAGMA_ONCE
36 BOOST_LOG_OPEN_NAMESPACE
38 namespace expressions {
41 * \brief Template expressions terminal node with Boost.Format-like formatter
43 template< typename CharT >
47 #ifndef BOOST_LOG_DOXYGEN_PASS
48 //! Internal typedef for type categorization
49 typedef void _is_boost_log_terminal;
53 typedef CharT char_type;
54 //! Boost.Format formatter type
55 typedef boost::log::aux::basic_format< char_type > format_type;
57 typedef std::basic_string< char_type > string_type;
59 //! Terminal result type
60 typedef typename format_type::pump result_type;
64 mutable format_type m_format;
67 //! Initializing constructor
68 explicit format_terminal(const char_type* format) : m_format(format) {}
70 //! Invokation operator
71 template< typename ContextT >
72 result_type operator() (ContextT const& ctx) const
74 return m_format.make_pump(fusion::at_c< 1 >(phoenix::env(ctx).args()));
77 BOOST_DELETED_FUNCTION(format_terminal())
81 * The function generates a terminal node in a template expression. The node will perform log record formatting
82 * according to the provided format string.
84 template< typename CharT >
85 BOOST_FORCEINLINE phoenix::actor< format_terminal< CharT > > format(const CharT* fmt)
87 typedef format_terminal< CharT > terminal_type;
88 phoenix::actor< terminal_type > act = {{ terminal_type(fmt) }};
93 * The function generates a terminal node in a template expression. The node will perform log record formatting
94 * according to the provided format string.
96 template< typename CharT, typename TraitsT, typename AllocatorT >
97 BOOST_FORCEINLINE phoenix::actor< format_terminal< CharT > > format(std::basic_string< CharT, TraitsT, AllocatorT > const& fmt)
99 typedef format_terminal< CharT > terminal_type;
100 phoenix::actor< terminal_type > act = {{ terminal_type(fmt.c_str()) }};
104 } // namespace expressions
106 BOOST_LOG_CLOSE_NAMESPACE // namespace log
108 #ifndef BOOST_LOG_DOXYGEN_PASS
112 namespace result_of {
114 template< typename CharT >
115 struct is_nullary< custom_terminal< boost::log::expressions::format_terminal< CharT > > > :
120 } // namespace result_of
122 } // namespace phoenix
128 #include <boost/log/detail/footer.hpp>
130 #endif // BOOST_LOG_EXPRESSIONS_FORMATTERS_FORMAT_HPP_INCLUDED_