2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
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)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_BUFFERS_SUFFIX_HPP
11 #define BOOST_BEAST_BUFFERS_SUFFIX_HPP
13 #include <boost/beast/core/detail/config.hpp>
14 #include <boost/beast/core/buffer_traits.hpp>
15 #include <boost/optional.hpp>
23 /** Adaptor to progressively trim the front of a <em>BufferSequence</em>.
25 This adaptor wraps a buffer sequence to create a new sequence
26 which may be incrementally consumed. Bytes consumed are removed
27 from the front of the buffer. The underlying memory is not changed,
28 instead the adaptor efficiently iterates through a subset of
31 The wrapped buffer is not modified, a copy is made instead.
32 Ownership of the underlying memory is not transferred, the application
33 is still responsible for managing its lifetime.
35 @tparam BufferSequence The buffer sequence to wrap.
39 This function writes the entire contents of a buffer sequence
40 to the specified stream.
43 template<class SyncWriteStream, class ConstBufferSequence>
44 void send(SyncWriteStream& stream, ConstBufferSequence const& buffers)
46 buffers_suffix<ConstBufferSequence> bs{buffers};
47 while(buffer_bytes(bs) > 0)
48 bs.consume(stream.write_some(bs));
52 template<class BufferSequence>
56 buffers_iterator_type<BufferSequence>;
60 std::size_t skip_ = 0;
62 template<class Deduced>
63 buffers_suffix(Deduced&& other, std::size_t dist)
64 : bs_(std::forward<Deduced>(other).bs_)
66 net::buffer_sequence_begin(bs_),
73 /** The type for each element in the list of buffers.
75 If <em>BufferSequence</em> meets the requirements of
76 <em>MutableBufferSequence</em>, then this type will be
77 `net::mutable_buffer`, otherwise this type will be
80 #if BOOST_BEAST_DOXYGEN
81 using value_type = __see_below__;
83 using value_type = buffers_type<BufferSequence>;
86 #if BOOST_BEAST_DOXYGEN
87 /// A bidirectional iterator type that may be used to read elements.
88 using const_iterator = __implementation_defined__;
99 buffers_suffix(buffers_suffix const&);
103 A copy of the buffer sequence is made. Ownership of the
104 underlying memory is not transferred or copied.
107 buffers_suffix(BufferSequence const& buffers);
111 This constructs the buffer sequence in-place from
114 @param args Arguments forwarded to the buffers constructor.
116 template<class... Args>
118 buffers_suffix(boost::in_place_init_t, Args&&... args);
121 buffers_suffix& operator=(buffers_suffix const&);
123 /// Get a bidirectional iterator to the first element.
127 /// Get a bidirectional iterator to one past the last element.
131 /** Remove bytes from the beginning of the sequence.
133 @param amount The number of bytes to remove. If this is
134 larger than the number of bytes remaining, all the
135 bytes remaining are removed.
138 consume(std::size_t amount);
144 #include <boost/beast/core/impl/buffers_suffix.hpp>