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