]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/log/utility/manipulators/auto_newline.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / log / utility / manipulators / auto_newline.hpp
1 /*
2 * Copyright Andrey Semashev 2019.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * https://www.boost.org/LICENSE_1_0.txt)
6 */
7 /*!
8 * \file utility/manipulators/auto_newline.hpp
9 * \author Andrey Semashev
10 * \date 23.06.2019
11 *
12 * The header contains implementation of a stream manipulator for inserting a newline, unless there is already one inserted.
13 */
14
15 #ifndef BOOST_LOG_UTILITY_MANIPULATORS_AUTO_NEWLINE_HPP_INCLUDED_
16 #define BOOST_LOG_UTILITY_MANIPULATORS_AUTO_NEWLINE_HPP_INCLUDED_
17
18 #include <boost/log/detail/config.hpp>
19 #include <boost/log/utility/formatting_ostream_fwd.hpp>
20 #include <boost/log/detail/header.hpp>
21
22 #ifdef BOOST_HAS_PRAGMA_ONCE
23 #pragma once
24 #endif
25
26 namespace boost {
27
28 BOOST_LOG_OPEN_NAMESPACE
29
30 /*!
31 * Stream manipulator for inserting a newline character, unless the last character
32 * inserted into the stream is already a newline.
33 */
34 struct auto_newline_manip {}
35 BOOST_INLINE_VARIABLE const auto_newline = {};
36
37 /*!
38 * Stream output operator for the \c auto_newline manipulator
39 */
40 template< typename CharT, typename TraitsT, typename AllocatorT >
41 inline basic_formatting_ostream< CharT, TraitsT, AllocatorT >& operator<< (basic_formatting_ostream< CharT, TraitsT, AllocatorT >& strm, auto_newline_manip)
42 {
43 typedef basic_formatting_ostream< CharT, TraitsT, AllocatorT > stream_type;
44 typedef typename stream_type::char_type char_type;
45 typedef typename stream_type::string_type string_type;
46 if (BOOST_LIKELY(strm.good()))
47 {
48 string_type* str = strm.rdbuf()->storage();
49 if (BOOST_LIKELY(!!str))
50 {
51 strm.rdbuf()->pubsync();
52 if (str->empty() || *str->rbegin() != static_cast< char_type >('\n'))
53 strm.rdbuf()->push_back(static_cast< char_type >('\n'));
54 }
55 }
56
57 return strm;
58 }
59
60 BOOST_LOG_CLOSE_NAMESPACE // namespace log
61
62 } // namespace boost
63
64 #include <boost/log/detail/footer.hpp>
65
66 #endif // BOOST_LOG_UTILITY_MANIPULATORS_AUTO_NEWLINE_HPP_INCLUDED_