Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:22

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   formatters/format.hpp
0009  * \author Andrey Semashev
0010  * \date   15.11.2012
0011  *
0012  * The header contains a generic log record formatter function.
0013  */
0014 
0015 #ifndef BOOST_LOG_EXPRESSIONS_FORMATTERS_FORMAT_HPP_INCLUDED_
0016 #define BOOST_LOG_EXPRESSIONS_FORMATTERS_FORMAT_HPP_INCLUDED_
0017 
0018 #include <string>
0019 #include <boost/mpl/bool.hpp>
0020 #include <boost/phoenix/core/actor.hpp>
0021 #include <boost/phoenix/core/terminal_fwd.hpp>
0022 #include <boost/phoenix/core/is_nullary.hpp>
0023 #include <boost/phoenix/core/environment.hpp>
0024 #include <boost/fusion/sequence/intrinsic/at_c.hpp>
0025 #include <boost/log/detail/config.hpp>
0026 #include <boost/log/detail/format.hpp>
0027 #include <boost/log/detail/custom_terminal_spec.hpp>
0028 #include <boost/log/detail/header.hpp>
0029 
0030 #ifdef BOOST_HAS_PRAGMA_ONCE
0031 #pragma once
0032 #endif
0033 
0034 namespace boost {
0035 
0036 BOOST_LOG_OPEN_NAMESPACE
0037 
0038 namespace expressions {
0039 
0040 /*!
0041  * \brief Template expressions terminal node with Boost.Format-like formatter
0042  */
0043 template< typename CharT >
0044 class format_terminal
0045 {
0046 public:
0047 #ifndef BOOST_LOG_DOXYGEN_PASS
0048     //! Internal typedef for type categorization
0049     typedef void _is_boost_log_terminal;
0050 #endif
0051 
0052     //! Character type
0053     typedef CharT char_type;
0054     //! Boost.Format formatter type
0055     typedef boost::log::aux::basic_format< char_type > format_type;
0056     //! String type
0057     typedef std::basic_string< char_type > string_type;
0058 
0059     //! Terminal result type
0060     typedef typename format_type::pump result_type;
0061 
0062 private:
0063     //! Formatter object
0064     mutable format_type m_format;
0065 
0066 public:
0067     //! Initializing constructor
0068     explicit format_terminal(const char_type* format) : m_format(format) {}
0069 
0070     //! Invokation operator
0071     template< typename ContextT >
0072     result_type operator() (ContextT const& ctx) const
0073     {
0074         return m_format.make_pump(fusion::at_c< 1 >(phoenix::env(ctx).args()));
0075     }
0076 
0077     BOOST_DELETED_FUNCTION(format_terminal())
0078 };
0079 
0080 /*!
0081  * The function generates a terminal node in a template expression. The node will perform log record formatting
0082  * according to the provided format string.
0083  */
0084 template< typename CharT >
0085 BOOST_FORCEINLINE phoenix::actor< format_terminal< CharT > > format(const CharT* fmt)
0086 {
0087     typedef format_terminal< CharT > terminal_type;
0088     phoenix::actor< terminal_type > act = {{ terminal_type(fmt) }};
0089     return act;
0090 }
0091 
0092 /*!
0093  * The function generates a terminal node in a template expression. The node will perform log record formatting
0094  * according to the provided format string.
0095  */
0096 template< typename CharT, typename TraitsT, typename AllocatorT >
0097 BOOST_FORCEINLINE phoenix::actor< format_terminal< CharT > > format(std::basic_string< CharT, TraitsT, AllocatorT > const& fmt)
0098 {
0099     typedef format_terminal< CharT > terminal_type;
0100     phoenix::actor< terminal_type > act = {{ terminal_type(fmt.c_str()) }};
0101     return act;
0102 }
0103 
0104 } // namespace expressions
0105 
0106 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0107 
0108 #ifndef BOOST_LOG_DOXYGEN_PASS
0109 
0110 namespace phoenix {
0111 
0112 namespace result_of {
0113 
0114 template< typename CharT >
0115 struct is_nullary< custom_terminal< boost::log::expressions::format_terminal< CharT > > > :
0116     public mpl::false_
0117 {
0118 };
0119 
0120 } // namespace result_of
0121 
0122 } // namespace phoenix
0123 
0124 #endif
0125 
0126 } // namespace boost
0127 
0128 #include <boost/log/detail/footer.hpp>
0129 
0130 #endif // BOOST_LOG_EXPRESSIONS_FORMATTERS_FORMAT_HPP_INCLUDED_