Back to home page

EIC code displayed by LXR

 
 

    


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

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   text_ostream_backend.hpp
0009  * \author Andrey Semashev
0010  * \date   22.04.2007
0011  *
0012  * The header contains implementation of a text output stream sink backend.
0013  */
0014 
0015 #ifndef BOOST_LOG_SINKS_TEXT_OSTREAM_BACKEND_HPP_INCLUDED_
0016 #define BOOST_LOG_SINKS_TEXT_OSTREAM_BACKEND_HPP_INCLUDED_
0017 
0018 #include <ostream>
0019 #include <boost/smart_ptr/shared_ptr.hpp>
0020 #include <boost/log/detail/config.hpp>
0021 #include <boost/log/detail/parameter_tools.hpp>
0022 #include <boost/log/keywords/auto_flush.hpp>
0023 #include <boost/log/keywords/auto_newline_mode.hpp>
0024 #include <boost/log/sinks/auto_newline_mode.hpp>
0025 #include <boost/log/sinks/basic_sink_backend.hpp>
0026 #include <boost/log/sinks/frontend_requirements.hpp>
0027 #include <boost/log/detail/header.hpp>
0028 
0029 #ifdef BOOST_HAS_PRAGMA_ONCE
0030 #pragma once
0031 #endif
0032 
0033 namespace boost {
0034 
0035 BOOST_LOG_OPEN_NAMESPACE
0036 
0037 namespace sinks {
0038 
0039 /*!
0040  * \brief An implementation of a text output stream logging sink backend
0041  *
0042  * The sink backend puts formatted log records to one or more text streams.
0043  */
0044 template< typename CharT >
0045 class basic_text_ostream_backend :
0046     public basic_formatted_sink_backend<
0047         CharT,
0048         combine_requirements< synchronized_feeding, flushing >::type
0049     >
0050 {
0051     //! Base type
0052     typedef basic_formatted_sink_backend<
0053         CharT,
0054         combine_requirements< synchronized_feeding, flushing >::type
0055     > base_type;
0056 
0057 public:
0058     //! Character type
0059     typedef typename base_type::char_type char_type;
0060     //! String type to be used as a message text holder
0061     typedef typename base_type::string_type string_type;
0062     //! Output stream type
0063     typedef std::basic_ostream< char_type > stream_type;
0064 
0065 private:
0066     //! \cond
0067 
0068     struct implementation;
0069     implementation* m_pImpl;
0070 
0071     //! \endcond
0072 
0073 public:
0074     /*!
0075      * Constructor. No streams attached to the constructed backend, auto flush feature disabled.
0076      */
0077     BOOST_LOG_API basic_text_ostream_backend();
0078 
0079     /*!
0080      * Constructor. Creates a sink backend with the specified named parameters.
0081      * The following named parameters are supported:
0082      *
0083      * \li \c auto_flush - Specifies a flag, whether or not to automatically flush the attached streams after each
0084      *                     written log record. By default, is \c false.
0085      * \li \c auto_newline_mode - Specifies automatic trailing newline insertion mode. Must be a value of
0086      *                            the \c auto_newline_mode enum. By default, is <tt>auto_newline_mode::insert_if_missing</tt>.
0087      */
0088 #ifndef BOOST_LOG_DOXYGEN_PASS
0089     BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_CALL(basic_text_ostream_backend, construct)
0090 #else
0091     template< typename... ArgsT >
0092     explicit basic_text_ostream_backend(ArgsT... const& args);
0093 #endif
0094 
0095     /*!
0096      * Destructor
0097      */
0098     BOOST_LOG_API ~basic_text_ostream_backend();
0099 
0100     /*!
0101      * The method adds a new stream to the sink.
0102      *
0103      * \param strm Pointer to the stream. Must not be NULL.
0104      */
0105     BOOST_LOG_API void add_stream(shared_ptr< stream_type > const& strm);
0106     /*!
0107      * The method removes a stream from the sink. If the stream is not attached to the sink,
0108      * the method has no effect.
0109      *
0110      * \param strm Pointer to the stream. Must not be NULL.
0111      */
0112     BOOST_LOG_API void remove_stream(shared_ptr< stream_type > const& strm);
0113 
0114     /*!
0115      * Sets the flag to automatically flush buffers of all attached streams after each log record.
0116      *
0117      * \param enable The flag indicates whether the automatic buffer flush should be performed.
0118      */
0119     BOOST_LOG_API void auto_flush(bool enable = true);
0120 
0121     /*!
0122      * Selects whether a trailing newline should be automatically inserted after every log record. See
0123      * \c auto_newline_mode description for the possible modes of operation.
0124      *
0125      * \param mode The trailing newline insertion mode.
0126      */
0127     BOOST_LOG_API void set_auto_newline_mode(auto_newline_mode mode);
0128 
0129     /*!
0130      * The method writes the message to the sink.
0131      */
0132     BOOST_LOG_API void consume(record_view const& rec, string_type const& formatted_message);
0133 
0134     /*!
0135      * The method flushes all attached streams.
0136      */
0137     BOOST_LOG_API void flush();
0138 
0139 private:
0140 #ifndef BOOST_LOG_DOXYGEN_PASS
0141     //! Constructor implementation
0142     template< typename ArgsT >
0143     void construct(ArgsT const& args)
0144     {
0145         construct(
0146             args[keywords::auto_newline_mode | insert_if_missing],
0147             args[keywords::auto_flush | false]);
0148     }
0149     //! Constructor implementation
0150     BOOST_LOG_API void construct(auto_newline_mode auto_newline, bool auto_flush);
0151 #endif // BOOST_LOG_DOXYGEN_PASS
0152 };
0153 
0154 #ifdef BOOST_LOG_USE_CHAR
0155 typedef basic_text_ostream_backend< char > text_ostream_backend;        //!< Convenience typedef for narrow-character logging
0156 #endif
0157 #ifdef BOOST_LOG_USE_WCHAR_T
0158 typedef basic_text_ostream_backend< wchar_t > wtext_ostream_backend;    //!< Convenience typedef for wide-character logging
0159 #endif
0160 
0161 } // namespace sinks
0162 
0163 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0164 
0165 } // namespace boost
0166 
0167 #include <boost/log/detail/footer.hpp>
0168 
0169 #endif // BOOST_LOG_SINKS_TEXT_OSTREAM_BACKEND_HPP_INCLUDED_