Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*
0002  *             Copyright Andrey Semashev 2019.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          https://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   utility/manipulators/auto_newline.hpp
0009  * \author Andrey Semashev
0010  * \date   23.06.2019
0011  *
0012  * The header contains implementation of a stream manipulator for inserting a newline, unless there is already one inserted.
0013  */
0014 
0015 #ifndef BOOST_LOG_UTILITY_MANIPULATORS_AUTO_NEWLINE_HPP_INCLUDED_
0016 #define BOOST_LOG_UTILITY_MANIPULATORS_AUTO_NEWLINE_HPP_INCLUDED_
0017 
0018 #include <boost/log/detail/config.hpp>
0019 #include <boost/log/utility/formatting_ostream_fwd.hpp>
0020 #include <boost/log/detail/header.hpp>
0021 
0022 #ifdef BOOST_HAS_PRAGMA_ONCE
0023 #pragma once
0024 #endif
0025 
0026 namespace boost {
0027 
0028 BOOST_LOG_OPEN_NAMESPACE
0029 
0030 /*!
0031  * Stream manipulator for inserting a newline character, unless the last character
0032  * inserted into the stream is already a newline.
0033  */
0034 struct auto_newline_manip {}
0035 BOOST_INLINE_VARIABLE const auto_newline = {};
0036 
0037 /*!
0038  * Stream output operator for the \c auto_newline manipulator
0039  */
0040 template< typename CharT, typename TraitsT, typename AllocatorT >
0041 inline basic_formatting_ostream< CharT, TraitsT, AllocatorT >& operator<< (basic_formatting_ostream< CharT, TraitsT, AllocatorT >& strm, auto_newline_manip)
0042 {
0043     typedef basic_formatting_ostream< CharT, TraitsT, AllocatorT > stream_type;
0044     typedef typename stream_type::char_type char_type;
0045     typedef typename stream_type::string_type string_type;
0046     if (BOOST_LIKELY(strm.good()))
0047     {
0048         string_type* str = strm.rdbuf()->storage();
0049         if (BOOST_LIKELY(!!str))
0050         {
0051             strm.rdbuf()->pubsync();
0052             if (str->empty() || *str->rbegin() != static_cast< char_type >('\n'))
0053                 strm.rdbuf()->push_back(static_cast< char_type >('\n'));
0054         }
0055     }
0056 
0057     return strm;
0058 }
0059 
0060 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0061 
0062 } // namespace boost
0063 
0064 #include <boost/log/detail/footer.hpp>
0065 
0066 #endif // BOOST_LOG_UTILITY_MANIPULATORS_AUTO_NEWLINE_HPP_INCLUDED_