Skip to content

Commit

Permalink
Meet DynamicBuffer requirements for static_streambuf
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Oct 30, 2016
1 parent 8bd8670 commit 9f15d8d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
19 changes: 10 additions & 9 deletions include/beast/core/impl/static_streambuf.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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
auto
static_streambuf::prepare(std::size_t n) ->
Expand All @@ -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<std::size_t>(out_ - in_)};
}

} // beast

#endif
35 changes: 22 additions & 13 deletions include/beast/core/static_streambuf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand All @@ -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.
Expand All @@ -93,13 +108,6 @@ class static_streambuf
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.
void
consume(std::size_t n)
Expand All @@ -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;
Expand Down

0 comments on commit 9f15d8d

Please sign in to comment.