]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/beast/core/buffers_suffix.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / beast / core / buffers_suffix.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_BUFFERS_SUFFIX_HPP
11 #define BOOST_BEAST_BUFFERS_SUFFIX_HPP
12
13 #include <boost/beast/core/detail/config.hpp>
14 #include <boost/beast/core/detail/in_place_init.hpp>
15 #include <boost/beast/core/detail/type_traits.hpp>
16 #include <boost/asio/buffer.hpp>
17 #include <boost/optional.hpp>
18 #include <cstdint>
19 #include <iterator>
20 #include <utility>
21
22 namespace boost {
23 namespace beast {
24
25 /** Adapter to trim the front of a `BufferSequence`.
26
27 This adapter wraps a buffer sequence to create a new sequence
28 which may be incrementally consumed. Bytes consumed are removed
29 from the front of the buffer. The underlying memory is not changed,
30 instead the adapter efficiently iterates through a subset of
31 the buffers wrapped.
32
33 The wrapped buffer is not modified, a copy is made instead.
34 Ownership of the underlying memory is not transferred, the application
35 is still responsible for managing its lifetime.
36
37 @tparam BufferSequence The buffer sequence to wrap.
38
39 @par Example
40
41 This function writes the entire contents of a buffer sequence
42 to the specified stream.
43
44 @code
45 template<class SyncWriteStream, class ConstBufferSequence>
46 void send(SyncWriteStream& stream, ConstBufferSequence const& buffers)
47 {
48 buffers_suffix<ConstBufferSequence> bs{buffers};
49 while(boost::asio::buffer_size(bs) > 0)
50 bs.consume(stream.write_some(bs));
51 }
52 @endcode
53 */
54 template<class BufferSequence>
55 class buffers_suffix
56 {
57 using buffers_type =
58 typename std::decay<BufferSequence>::type;
59
60 using iter_type = typename
61 detail::buffer_sequence_iterator<buffers_type>::type;
62
63 BufferSequence bs_;
64 iter_type begin_;
65 std::size_t skip_ = 0;
66
67 template<class Deduced>
68 buffers_suffix(Deduced&& other, std::size_t dist)
69 : bs_(std::forward<Deduced>(other).bs_)
70 , begin_(std::next(
71 boost::asio::buffer_sequence_begin(bs_),
72 dist))
73 , skip_(other.skip_)
74 {
75 }
76
77 public:
78 /** The type for each element in the list of buffers.
79
80 If the buffers in the underlying sequence are convertible to
81 `boost::asio::mutable_buffer`, then this type will be
82 `boost::asio::mutable_buffer`, else this type will be
83 `boost::asio::const_buffer`.
84 */
85 #if BOOST_BEAST_DOXYGEN
86 using value_type = implementation_defined;
87 #else
88 using value_type = typename std::conditional<
89 std::is_convertible<typename
90 std::iterator_traits<iter_type>::value_type,
91 boost::asio::mutable_buffer>::value,
92 boost::asio::mutable_buffer,
93 boost::asio::const_buffer>::type;
94 #endif
95
96 #if BOOST_BEAST_DOXYGEN
97 /// A bidirectional iterator type that may be used to read elements.
98 using const_iterator = implementation_defined;
99
100 #else
101 class const_iterator;
102
103 #endif
104
105 /// Constructor
106 buffers_suffix();
107
108 /// Constructor
109 buffers_suffix(buffers_suffix&&);
110
111 /// Constructor
112 buffers_suffix(buffers_suffix const&);
113
114 /** Constructor
115
116 A copy of the buffer sequence is made. Ownership of the
117 underlying memory is not transferred or copied.
118 */
119 explicit
120 buffers_suffix(BufferSequence const& buffers);
121
122 /** Constructor
123
124 This constructs the buffer sequence in-place from
125 a list of arguments.
126
127 @param args Arguments forwarded to the buffers constructor.
128 */
129 template<class... Args>
130 buffers_suffix(boost::in_place_init_t, Args&&... args);
131
132 /// Assignment
133 buffers_suffix& operator=(buffers_suffix&&);
134
135 /// Assignment
136 buffers_suffix& operator=(buffers_suffix const&);
137
138 /// Get a bidirectional iterator to the first element.
139 const_iterator
140 begin() const;
141
142 /// Get a bidirectional iterator to one past the last element.
143 const_iterator
144 end() const;
145
146 /** Remove bytes from the beginning of the sequence.
147
148 @param amount The number of bytes to remove. If this is
149 larger than the number of bytes remaining, all the
150 bytes remaining are removed.
151 */
152 void
153 consume(std::size_t amount);
154 };
155
156 } // beast
157 } // boost
158
159 #include <boost/beast/core/impl/buffers_suffix.ipp>
160
161 #endif