From 9f15d8d85815c18021af820ac211f43cfb50cb93 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 29 Oct 2016 09:42:48 -0400 Subject: [PATCH] Meet DynamicBuffer requirements for static_streambuf --- include/beast/core/impl/static_streambuf.ipp | 19 ++++++----- include/beast/core/static_streambuf.hpp | 35 ++++++++++++-------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/include/beast/core/impl/static_streambuf.ipp b/include/beast/core/impl/static_streambuf.ipp index ab487fab5d..3f19cd7e10 100644 --- a/include/beast/core/impl/static_streambuf.ipp +++ b/include/beast/core/impl/static_streambuf.ipp @@ -279,6 +279,16 @@ static_streambuf::mutable_buffers_type::end() const -> //------------------------------------------------------------------------------ + +inline +auto +static_streambuf::data() const -> + const_buffers_type +{ + return const_buffers_type{in_, + static_cast(out_ - in_)}; +} + inline auto static_streambuf::prepare(std::size_t n) -> @@ -290,15 +300,6 @@ static_streambuf::prepare(std::size_t n) -> return mutable_buffers_type{out_, n}; } -inline -auto -static_streambuf::data() const -> - const_buffers_type -{ - return const_buffers_type{in_, - static_cast(out_ - in_)}; -} - } // beast #endif diff --git a/include/beast/core/static_streambuf.hpp b/include/beast/core/static_streambuf.hpp index eb1f6c9cc1..2323b3baa0 100644 --- a/include/beast/core/static_streambuf.hpp +++ b/include/beast/core/static_streambuf.hpp @@ -32,6 +32,7 @@ class static_streambuf #else protected: #endif + std::uint8_t* begin_; std::uint8_t* in_; std::uint8_t* out_; std::uint8_t* last_; @@ -57,21 +58,35 @@ class static_streambuf #endif - /// Returns the largest size output sequence possible. + /// Return the size of the input sequence. + std::size_t + size() const + { + return out_ - in_; + } + + /// Return the maximum sum of the input and output sequence sizes. std::size_t max_size() const { - return end_ - in_; + return end_ - begin_; } - /// Get the size of the input sequence. + /// Return the maximum sum of input and output sizes that can be held without an allocation. std::size_t - size() const + capacity() const { - return out_ - in_; + return end_ - in_; } - /** Get a list of buffers that represents the output sequence, with the given size. + /** Get a list of buffers that represent the input sequence. + + @note These buffers remain valid across subsequent calls to `prepare`. + */ + const_buffers_type + data() const; + + /** Get a list of buffers that represent the output sequence, with the given size. @throws std::length_error if the size would exceed the limit imposed by the underlying mutable buffer sequence. @@ -93,13 +108,6 @@ class static_streambuf out_ += std::min(n, last_ - out_); } - /** Get a list of buffers that represents the input sequence. - - @note These buffers remain valid across subsequent calls to `prepare`. - */ - const_buffers_type - data() const; - /// Remove bytes from the input sequence. void consume(std::size_t n) @@ -120,6 +128,7 @@ class static_streambuf void reset(std::uint8_t* p, std::size_t n) { + begin_ = p; in_ = p; out_ = p; last_ = p;