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_STATIC_STREAMBUF_IPP
9 #define BEAST_IMPL_STATIC_STREAMBUF_IPP
11 #include <beast/core/detail/type_traits.hpp>
12 #include <boost/asio/buffer.hpp>
20 class static_streambuf::const_buffers_type
23 std::uint8_t const* p_;
26 using value_type = boost::asio::const_buffer;
30 const_buffers_type() = delete;
32 const_buffers_type const&) = default;
33 const_buffers_type& operator=(
34 const_buffers_type const&) = default;
43 friend class static_streambuf;
46 std::uint8_t const* p, std::size_t n)
53 class static_streambuf::const_buffers_type::const_iterator
56 std::uint8_t const* p_ = nullptr;
59 using value_type = boost::asio::const_buffer;
60 using pointer = value_type const*;
61 using reference = value_type;
62 using difference_type = std::ptrdiff_t;
63 using iterator_category =
64 std::bidirectional_iterator_tag;
66 const_iterator() = default;
67 const_iterator(const_iterator&& other) = default;
68 const_iterator(const_iterator const& other) = default;
69 const_iterator& operator=(const_iterator&& other) = default;
70 const_iterator& operator=(const_iterator const& other) = default;
73 operator==(const_iterator const& other) const
75 return p_ == other.p_;
79 operator!=(const_iterator const& other) const
81 return !(*this == other);
87 return value_type{p_, n_};
91 operator->() const = delete;
124 friend class const_buffers_type;
127 std::uint8_t const* p, std::size_t n)
136 static_streambuf::const_buffers_type::begin() const ->
139 return const_iterator{p_, n_};
144 static_streambuf::const_buffers_type::end() const ->
147 return const_iterator{p_ + n_, n_};
150 //------------------------------------------------------------------------------
152 class static_streambuf::mutable_buffers_type
158 using value_type = boost::asio::mutable_buffer;
160 class const_iterator;
162 mutable_buffers_type() = delete;
163 mutable_buffers_type(
164 mutable_buffers_type const&) = default;
165 mutable_buffers_type& operator=(
166 mutable_buffers_type const&) = default;
175 friend class static_streambuf;
177 mutable_buffers_type(
178 std::uint8_t* p, std::size_t n)
185 class static_streambuf::mutable_buffers_type::const_iterator
188 std::uint8_t* p_ = nullptr;
191 using value_type = boost::asio::mutable_buffer;
192 using pointer = value_type const*;
193 using reference = value_type;
194 using difference_type = std::ptrdiff_t;
195 using iterator_category =
196 std::bidirectional_iterator_tag;
198 const_iterator() = default;
199 const_iterator(const_iterator&& other) = default;
200 const_iterator(const_iterator const& other) = default;
201 const_iterator& operator=(const_iterator&& other) = default;
202 const_iterator& operator=(const_iterator const& other) = default;
205 operator==(const_iterator const& other) const
207 return p_ == other.p_;
211 operator!=(const_iterator const& other) const
213 return !(*this == other);
219 return value_type{p_, n_};
223 operator->() const = delete;
256 friend class mutable_buffers_type;
258 const_iterator(std::uint8_t* p, std::size_t n)
267 static_streambuf::mutable_buffers_type::begin() const ->
270 return const_iterator{p_, n_};
275 static_streambuf::mutable_buffers_type::end() const ->
278 return const_iterator{p_ + n_, n_};
281 //------------------------------------------------------------------------------
286 static_streambuf::data() const ->
289 return const_buffers_type{in_,
290 static_cast<std::size_t>(out_ - in_)};
295 static_streambuf::prepare(std::size_t n) ->
298 if(n > static_cast<std::size_t>(end_ - out_))
299 throw detail::make_exception<std::length_error>(
300 "no space in streambuf", __FILE__, __LINE__);
302 return mutable_buffers_type{out_, n};