Automatically resizable buffer class based on std::streambuf. More...
#include <basic_streambuf_fwd.hpp>
Public Types | |
typedef boost::asio::const_buffers_1 | const_buffers_type |
typedef boost::asio::mutable_buffers_1 | mutable_buffers_type |
Public Member Functions | |
basic_streambuf (std::size_t maximum_size=(std::numeric_limits< std::size_t >::max)(), const Allocator &allocator=Allocator()) | |
Construct a basic_streambuf object. More... | |
std::size_t | size () const |
Get the size of the input sequence. More... | |
std::size_t | max_size () const |
Get the maximum size of the basic_streambuf. More... | |
const_buffers_type | data () const |
Get a list of buffers that represents the input sequence. More... | |
mutable_buffers_type | prepare (std::size_t n) |
Get a list of buffers that represents the output sequence, with the given size. More... | |
void | commit (std::size_t n) |
Move characters from the output sequence to the input sequence. More... | |
void | consume (std::size_t n) |
Remove characters from the input sequence. More... | |
Protected Types | |
enum | { buffer_delta = 128 } |
Protected Member Functions | |
int_type | underflow () |
Override std::streambuf behaviour. More... | |
int_type | overflow (int_type c) |
Override std::streambuf behaviour. More... | |
void | reserve (std::size_t n) |
Friends | |
std::size_t | read_size_helper (basic_streambuf &sb, std::size_t max_size) |
Automatically resizable buffer class based on std::streambuf.
The basic_streambuf
class is derived from std::streambuf
to associate the streambuf's input and output sequences with one or more character arrays. These character arrays are internal to the basic_streambuf
object, but direct access to the array elements is provided to permit them to be used efficiently with I/O operations. Characters written to the output sequence of a basic_streambuf
object are appended to the input sequence of the same object.
The basic_streambuf
class's public interface is intended to permit the following implementation strategies:
The constructor for basic_streambuf accepts a size_t
argument specifying the maximum of the sum of the sizes of the input sequence and output sequence. During the lifetime of the basic_streambuf
object, the following invariant holds:
Any member function that would, if successful, cause the invariant to be violated shall throw an exception of class std::length_error
.
The constructor for basic_streambuf
takes an Allocator argument. A copy of this argument is used for any memory allocation performed, by the constructor and by all member functions, during the lifetime of each basic_streambuf
object.
Reading from a socket directly into a streambuf:
typedef boost::asio::const_buffers_1 boost::asio::basic_streambuf< Allocator >::const_buffers_type |
typedef boost::asio::mutable_buffers_1 boost::asio::basic_streambuf< Allocator >::mutable_buffers_type |
|
inlineexplicit |
Construct a basic_streambuf object.
Constructs a streambuf with the specified maximum size. The initial size of the streambuf's input sequence is 0.
References boost::asio::basic_streambuf< Allocator >::buffer_delta.
|
inline |
Move characters from the output sequence to the input sequence.
Appends n
characters from the start of the output sequence to the input sequence. The beginning of the output sequence is advanced by n
characters.
Requires a preceding call prepare(x)
where x >= n
, and no intervening operations that modify the input or output sequence.
n
is greater than the size of the output sequence, the entire output sequence is moved to the input sequence and no error is issued.
|
inline |
Remove characters from the input sequence.
Removes n
characters from the beginning of the input sequence.
n
is greater than the size of the input sequence, the entire input sequence is consumed and no error is issued.
|
inline |
Get a list of buffers that represents the input sequence.
const_buffers_type
that satisfies ConstBufferSequence requirements, representing all character arrays in the input sequence.basic_streambuf
member function that modifies the input sequence or output sequence. References boost::asio::buffer().
|
inline |
Get the maximum size of the basic_streambuf.
Referenced by boost::asio::read_size_helper().
|
inlineprotected |
Override std::streambuf behaviour.
Behaves according to the specification of std::streambuf::overflow()
, with the specialisation that std::length_error
is thrown if appending the character to the input sequence would require the condition size() > max_size()
to be true.
References boost::asio::basic_streambuf< Allocator >::buffer_delta, boost::asio::buffer_size(), boost::multiprecision::backends::c, boost::asio::error::eof, and boost::asio::basic_streambuf< Allocator >::reserve().
|
inline |
Get a list of buffers that represents the output sequence, with the given size.
Ensures that the output sequence can accommodate n
characters, reallocating character array objects as necessary.
mutable_buffers_type
that satisfies MutableBufferSequence requirements, representing character array objects at the start of the output sequence such that the sum of the buffer sizes is n
.std::length_error | If size() + n > max_size() . |
basic_streambuf
member function that modifies the input sequence or output sequence. References boost::asio::buffer(), and boost::asio::basic_streambuf< Allocator >::reserve().
|
inlineprotected |
References boost::n, and boost::lambda::throw_exception().
Referenced by boost::asio::basic_streambuf< Allocator >::overflow(), and boost::asio::basic_streambuf< Allocator >::prepare().
|
inline |
Get the size of the input sequence.
s
in the following code: Referenced by boost::asio::read_size_helper().
|
inlineprotected |
Override std::streambuf behaviour.
Behaves according to the specification of std::streambuf::underflow()
.
References boost::asio::error::eof.
|
friend |