2 // Copyright (c) 2013-2017 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)
8 #ifndef BEAST_IMPL_CONSUMING_BUFFERS_IPP
9 #define BEAST_IMPL_CONSUMING_BUFFERS_IPP
11 #include <beast/core/buffer_concepts.hpp>
12 #include <boost/asio/buffer.hpp>
16 #include <type_traits>
21 template<class BufferSequence>
22 class consuming_buffers<BufferSequence>::const_iterator
24 friend class consuming_buffers<BufferSequence>;
27 typename BufferSequence::const_iterator;
30 consuming_buffers const* b_ = nullptr;
33 using value_type = typename std::conditional<
34 std::is_convertible<typename
35 std::iterator_traits<iter_type>::value_type,
36 boost::asio::mutable_buffer>::value,
37 boost::asio::mutable_buffer,
38 boost::asio::const_buffer>::type;
39 using pointer = value_type const*;
40 using reference = value_type;
41 using difference_type = std::ptrdiff_t;
42 using iterator_category =
43 std::bidirectional_iterator_tag;
45 const_iterator() = default;
46 const_iterator(const_iterator&& other) = default;
47 const_iterator(const_iterator const& other) = default;
48 const_iterator& operator=(const_iterator&& other) = default;
49 const_iterator& operator=(const_iterator const& other) = default;
52 operator==(const_iterator const& other) const
54 return b_ == other.b_ && it_ == other.it_;
58 operator!=(const_iterator const& other) const
60 return !(*this == other);
66 return it_ == b_->begin_
67 ? value_type{*it_} + b_->skip_
72 operator->() const = delete;
105 const_iterator(consuming_buffers const& b,
113 template<class BufferSequence>
114 consuming_buffers<BufferSequence>::
115 consuming_buffers(consuming_buffers&& other)
116 : consuming_buffers(std::move(other),
117 std::distance<iter_type>(
118 other.bs_.begin(), other.begin_))
122 template<class BufferSequence>
123 consuming_buffers<BufferSequence>::
124 consuming_buffers(consuming_buffers const& other)
125 : consuming_buffers(other,
126 std::distance<iter_type>(
127 other.bs_.begin(), other.begin_))
131 template<class BufferSequence>
133 consuming_buffers<BufferSequence>::
134 operator=(consuming_buffers&& other) ->
137 auto const nbegin = std::distance<iter_type>(
138 other.bs_.begin(), other.begin_);
139 bs_ = std::move(other.bs_);
140 begin_ = std::next(bs_.begin(), nbegin);
145 template<class BufferSequence>
147 consuming_buffers<BufferSequence>::
148 operator=(consuming_buffers const& other) ->
151 auto const nbegin = std::distance<iter_type>(
152 other.bs_.begin(), other.begin_);
154 begin_ = std::next(bs_.begin(), nbegin);
159 template<class BufferSequence>
160 consuming_buffers<BufferSequence>::
161 consuming_buffers(BufferSequence const& bs)
163 , begin_(bs_.begin())
166 is_BufferSequence<BufferSequence, value_type>::value,
167 "BufferSequence requirements not met");
170 template<class BufferSequence>
173 consuming_buffers<BufferSequence>::
177 return const_iterator{*this, begin_};
180 template<class BufferSequence>
183 consuming_buffers<BufferSequence>::
187 return const_iterator{*this, bs_.end()};
190 template<class BufferSequence>
192 consuming_buffers<BufferSequence>::
193 consume(std::size_t n)
195 using boost::asio::buffer_size;
196 for(;n > 0 && begin_ != bs_.end(); ++begin_)
199 buffer_size(*begin_) - skip_;