From 4218a3a97259ac01a53136a62e13ce5ca3dbceb1 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sun, 13 Aug 2017 06:48:24 -0700 Subject: [PATCH] Add flat_static_buffer::reset --- CHANGELOG.md | 1 + .../boost/beast/core/flat_static_buffer.hpp | 14 +++++++++++--- .../beast/core/impl/flat_static_buffer.ipp | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8be2e17f..35ec3e4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 106: * Dynamic buffer input areas are mutable +* Add flat_static_buffer::reset -------------------------------------------------------------------------------- diff --git a/include/boost/beast/core/flat_static_buffer.hpp b/include/boost/beast/core/flat_static_buffer.hpp index 54d670e0..b9194512 100644 --- a/include/boost/beast/core/flat_static_buffer.hpp +++ b/include/boost/beast/core/flat_static_buffer.hpp @@ -114,6 +114,10 @@ public: mutable_data_type mutable_data(); + /// Set the input and output sequences to size 0 + void + reset(); + /** 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 @@ -147,10 +151,10 @@ protected: /** Constructor The buffer will be in an undefined state. It is necessary - for the derived class to call @ref reset in order to - initialize the object. + for the derived class to call @ref reset with a pointer + and size in order to initialize the object. */ - flat_static_buffer_base(); + flat_static_buffer_base() = default; /** Reset the pointed-to buffer. @@ -175,6 +179,10 @@ private: return static_cast(last - first); } + template + void + reset_impl(); + template void reset_impl(void* p, std::size_t n); diff --git a/include/boost/beast/core/impl/flat_static_buffer.ipp b/include/boost/beast/core/impl/flat_static_buffer.ipp index e60e8dcd..f8654033 100644 --- a/include/boost/beast/core/impl/flat_static_buffer.ipp +++ b/include/boost/beast/core/impl/flat_static_buffer.ipp @@ -44,6 +44,14 @@ mutable_data() -> return {in_, dist(in_, out_)}; } +inline +void +flat_static_buffer_base:: +reset() +{ + reset_impl(); +} + inline auto flat_static_buffer_base:: @@ -61,6 +69,16 @@ reset(void* p, std::size_t n) reset_impl(p, n); } +template +void +flat_static_buffer_base:: +reset_impl() +{ + in_ = begin_; + out_ = begin_; + last_ = begin_; +} + template void flat_static_buffer_base::