]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/beast/core/ostream.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / beast / core / ostream.hpp
1 //
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9
10 #ifndef BOOST_BEAST_WRITE_OSTREAM_HPP
11 #define BOOST_BEAST_WRITE_OSTREAM_HPP
12
13 #include <boost/beast/core/detail/config.hpp>
14 #include <boost/beast/core/type_traits.hpp>
15 #include <boost/beast/core/detail/ostream.hpp>
16 #include <type_traits>
17 #include <streambuf>
18 #include <utility>
19
20 namespace boost {
21 namespace beast {
22
23 /** Return an object representing a @b ConstBufferSequence.
24
25 This function wraps a reference to a buffer sequence and permits
26 the following operation:
27
28 @li `operator<<` to `std::ostream`. No character translation is
29 performed; unprintable and null characters will be transferred
30 as-is to the output stream.
31
32 @par Example
33 @code
34 multi_buffer b;
35 ...
36 std::cout << buffers(b.data()) << std::endl;
37 @endcode
38
39 @param b An object meeting the requirements of @b ConstBufferSequence
40 to be streamed. The implementation will make a copy of this object.
41 Ownership of the underlying memory is not transferred, the application
42 is still responsible for managing its lifetime.
43 */
44 template<class ConstBufferSequence>
45 #if BOOST_BEAST_DOXYGEN
46 implementation_defined
47 #else
48 detail::buffers_helper<ConstBufferSequence>
49 #endif
50 buffers(ConstBufferSequence const& b)
51 {
52 static_assert(boost::asio::is_const_buffer_sequence<
53 ConstBufferSequence>::value,
54 "ConstBufferSequence requirements not met");
55 return detail::buffers_helper<
56 ConstBufferSequence>{b};
57 }
58
59 /** Return an output stream that formats values into a @b DynamicBuffer.
60
61 This function wraps the caller provided @b DynamicBuffer into
62 a `std::ostream` derived class, to allow `operator<<` stream style
63 formatting operations.
64
65 @par Example
66 @code
67 ostream(buffer) << "Hello, world!" << std::endl;
68 @endcode
69
70 @note Calling members of the underlying buffer before the output
71 stream is destroyed results in undefined behavior.
72
73 @param buffer An object meeting the requirements of @b DynamicBuffer
74 into which the formatted output will be placed.
75
76 @return An object derived from `std::ostream` which redirects output
77 The wrapped dynamic buffer is not modified, a copy is made instead.
78 Ownership of the underlying memory is not transferred, the application
79 is still responsible for managing its lifetime. The caller is
80 responsible for ensuring the dynamic buffer is not destroyed for the
81 lifetime of the output stream.
82 */
83 template<class DynamicBuffer>
84 #if BOOST_BEAST_DOXYGEN
85 implementation_defined
86 #else
87 detail::ostream_helper<
88 DynamicBuffer, char, std::char_traits<char>,
89 detail::basic_streambuf_movable::value>
90 #endif
91 ostream(DynamicBuffer& buffer)
92 {
93 static_assert(
94 boost::asio::is_dynamic_buffer<DynamicBuffer>::value,
95 "DynamicBuffer requirements not met");
96 return detail::ostream_helper<
97 DynamicBuffer, char, std::char_traits<char>,
98 detail::basic_streambuf_movable::value>{buffer};
99 }
100
101 } // beast
102 } // boost
103
104 #endif