Meet DynamicBuffer requirements for static_streambuf

This commit is contained in:
Vinnie Falco
2016-10-29 09:42:48 -04:00
parent 4e25e0f99e
commit 74e77682c7
3 changed files with 39 additions and 25 deletions

View File

@ -7,6 +7,10 @@ HTTP
* Check invariants in parse_op: * Check invariants in parse_op:
* Clean up message docs * Clean up message docs
Core
* Meet DynamicBuffer requirements for static_streambuf
Extras Extras
* unit_test::suite fixes: * unit_test::suite fixes:

View File

@ -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<std::size_t>(out_ - in_)};
}
inline inline
auto auto
static_streambuf::prepare(std::size_t n) -> static_streambuf::prepare(std::size_t n) ->
@ -290,15 +300,6 @@ static_streambuf::prepare(std::size_t n) ->
return mutable_buffers_type{out_, n}; return mutable_buffers_type{out_, n};
} }
inline
auto
static_streambuf::data() const ->
const_buffers_type
{
return const_buffers_type{in_,
static_cast<std::size_t>(out_ - in_)};
}
} // beast } // beast
#endif #endif

View File

@ -32,6 +32,7 @@ private:
#else #else
protected: protected:
#endif #endif
std::uint8_t* begin_;
std::uint8_t* in_; std::uint8_t* in_;
std::uint8_t* out_; std::uint8_t* out_;
std::uint8_t* last_; std::uint8_t* last_;
@ -57,21 +58,35 @@ public:
#endif #endif
/// Returns the largest size output sequence possible. /// Return the size of the input sequence.
std::size_t
max_size() const
{
return end_ - in_;
}
/// Get the size of the input sequence.
std::size_t std::size_t
size() const size() const
{ {
return out_ - in_; return out_ - in_;
} }
/** Get a list of buffers that represents the output sequence, with the given size. /// Return the maximum sum of the input and output sequence sizes.
std::size_t
max_size() const
{
return end_ - begin_;
}
/// Return the maximum sum of input and output sizes that can be held without an allocation.
std::size_t
capacity() const
{
return end_ - in_;
}
/** 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 @throws std::length_error if the size would exceed the limit
imposed by the underlying mutable buffer sequence. imposed by the underlying mutable buffer sequence.
@ -93,13 +108,6 @@ public:
out_ += std::min<std::size_t>(n, last_ - out_); out_ += std::min<std::size_t>(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. /// Remove bytes from the input sequence.
void void
consume(std::size_t n) consume(std::size_t n)
@ -120,6 +128,7 @@ protected:
void void
reset(std::uint8_t* p, std::size_t n) reset(std::uint8_t* p, std::size_t n)
{ {
begin_ = p;
in_ = p; in_ = p;
out_ = p; out_ = p;
last_ = p; last_ = p;