Class template dynamic_string_buffer is an adaptor used to automatically grow or shrink a basic_string object, to reflect the data successfully transferred in an I/O operation.
namespace std {
namespace experimental {
namespace net {
inline namespace v1 {
template<class CharT, class Traits, class Allocator>
class dynamic_string_buffer
{
public:
// types:
using const_buffers_type = const_buffer;
using mutable_buffers_type = mutable_buffer;
// constructors:
explicit dynamic_string_buffer(basic_string<CharT, Traits, Allocator>& str) noexcept;
dynamic_string_buffer(basic_string<CharT, Traits, Allocator>& str,
size_t maximum_size) noexcept;
dynamic_string_buffer(dynamic_string_buffer&&) = default;
// members:
size_t size() const noexcept;
size_t max_size() const noexcept;
size_t capacity() const noexcept;
const_buffers_type data() const noexcept;
mutable_buffers_type prepare(size_t n);
void commit(size_t n) noexcept;
void consume(size_t n);
private:
basic_string<CharT, Traits, Allocator>& str_; // exposition only
size_t size_; // exposition only
const size_t max_size_; // exposition only
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
The dynamic_string_buffer class template meets the requirements of DynamicBuffer ([buffer.reqmts.dynamicbuffer]).
The dynamic_string_buffer class template requires that sizeof(CharT) == 1.
explicit dynamic_string_buffer(basic_string<CharT, Traits, Allocator>& str) noexcept;
Effects: Initializes str_ with str, size_ with str.size(), and max_size_ with str.max_size().
dynamic_string_buffer(basic_string<CharT, Traits, Allocator>& str,
size_t maximum_size) noexcept;
Requires: str.size() <= maximum_size.
Effects: Initializes str_ with str, size_ with str.size(), and max_size_ with maximum_size.
Returns: size_.
size_t max_size() const noexcept;
Returns: max_size_.
size_t capacity() const noexcept;
Returns: str_.capacity().
const_buffers_type data() const noexcept;
Returns: buffer(str_, size_).
mutable_buffers_type prepare(size_t n);
Effects: Performs str_.resize(size_ + n).
Returns: buffer(buffer(str_) + size_, n).
Remarks: length_error if size() + n exceeds max_size().
void commit(size_t n) noexcept;
Effects: Performs:
size_ += min(n, str_.size() - size_); str_.resize(size_);
Effects: Performs:
size_t m = min(n, size_); str_.erase(0, m); size_ -= m;