Asio Extensions
Additional functionality built on top of (Boost.)Asio
asioext::dynamic_linear_buffer< Allocator > Class Template Reference

Adapt a basic_linear_buffer to the DynamicBuffer requirements. More...

#include <asioext/linear_buffer.hpp>

Public Types

typedef asio::const_buffers_1 const_buffers_type
 The type used to represent the input sequence as a list of buffers. More...
 
typedef asio::mutable_buffers_1 mutable_buffers_type
 The type used to represent the output sequence as a list of buffers. More...
 

Public Member Functions

 dynamic_linear_buffer (basic_linear_buffer< Allocator > &b, std::size_t maximum_size=(std::numeric_limits< std::size_t >::max)()) noexcept
 Construct a dynamic buffer from a basic_linear_buffer. More...
 
std::size_t size () const noexcept
 Get the size of the input sequence. More...
 
std::size_t max_size () const noexcept
 Get the maximum size of the dynamic buffer. More...
 
std::size_t capacity () const noexcept
 Get the current capacity of the dynamic buffer. More...
 
mutable_buffers_type data () noexcept
 
const_buffers_type data () const noexcept
 
mutable_buffers_type prepare (std::size_t n)
 Get a list of buffers that represents the output sequence, with the given size. More...
 
mutable_buffers_type prepare (std::size_t n, error_code &ec)
 Get a list of buffers that represents the output sequence, with the given size. More...
 
void commit (std::size_t n)
 
void consume (std::size_t n)
 Remove characters from the input sequence. More...
 

Detailed Description

template<typename Allocator>
class asioext::dynamic_linear_buffer< Allocator >

Adapt a basic_linear_buffer to the DynamicBuffer requirements.

Member Typedef Documentation

◆ const_buffers_type

template<typename Allocator >
typedef asio::const_buffers_1 asioext::dynamic_linear_buffer< Allocator >::const_buffers_type

The type used to represent the input sequence as a list of buffers.

◆ mutable_buffers_type

template<typename Allocator >
typedef asio::mutable_buffers_1 asioext::dynamic_linear_buffer< Allocator >::mutable_buffers_type

The type used to represent the output sequence as a list of buffers.

Constructor & Destructor Documentation

◆ dynamic_linear_buffer()

template<typename Allocator >
asioext::dynamic_linear_buffer< Allocator >::dynamic_linear_buffer ( basic_linear_buffer< Allocator > &  b,
std::size_t  maximum_size = (std::numeric_limits<std::size_t>::max)() 
)
inlineexplicitnoexcept

Construct a dynamic buffer from a basic_linear_buffer.

Parameters
bThe basic_linear_buffer to be used as backing storage for the dynamic buffer. Any existing data in the buffer is treated as the dynamic buffer's input sequence. The object stores a reference to the buffer and the user is responsible for ensuring that the buffer object remains valid until the dynamic_linear_buffer object is destroyed.
maximum_sizeSpecifies a maximum size for the buffer, in bytes.

Member Function Documentation

◆ capacity()

template<typename Allocator >
std::size_t asioext::dynamic_linear_buffer< Allocator >::capacity ( ) const
inlinenoexcept

Get the current capacity of the dynamic buffer.

Returns
The current total capacity of the buffer, i.e. for both the input sequence and output sequence.

◆ commit()

template<typename Allocator >
void asioext::dynamic_linear_buffer< Allocator >::commit ( std::size_t  n)
inline

Move bytes from the output sequence to the input sequence.

Parameters
nThe number of bytes to append from the start of the output sequence to the end of the input sequence. The remainder of the output sequence is discarded.

Requires a preceding call prepare(x) where x >= n, and no intervening operations that modify the input or output sequence.

Note
If 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.

◆ consume()

template<typename Allocator >
void asioext::dynamic_linear_buffer< Allocator >::consume ( std::size_t  n)
inline

Remove characters from the input sequence.

Removes n characters from the beginning of the input sequence.

Note
If n is greater than the size of the input sequence, the entire input sequence is consumed and no error is issued.

◆ data() [1/2]

template<typename Allocator >
mutable_buffers_type asioext::dynamic_linear_buffer< Allocator >::data ( )
inlinenoexcept

Get a list of buffers that represents the input sequence.

Returns
An object of type mutable_buffers_type that satisfies ConstBufferSequence requirements, representing the memory in the input sequence.
Note
The returned object is invalidated by any dynamic_linear_buffer member function that modifies the input sequence or output sequence.

◆ data() [2/2]

template<typename Allocator >
const_buffers_type asioext::dynamic_linear_buffer< Allocator >::data ( ) const
inlinenoexcept

Get a list of buffers that represents the input sequence.

Returns
An object of type const_buffers_type that satisfies ConstBufferSequence requirements, representing the memory in the input sequence.
Note
The returned object is invalidated by any dynamic_linear_buffer member function that modifies the input sequence or output sequence.

◆ max_size()

template<typename Allocator >
std::size_t asioext::dynamic_linear_buffer< Allocator >::max_size ( ) const
inlinenoexcept

Get the maximum size of the dynamic buffer.

Returns
The allowed maximum of the sum of the sizes of the input sequence and output sequence.

◆ prepare() [1/2]

template<typename Allocator >
mutable_buffers_type asioext::dynamic_linear_buffer< Allocator >::prepare ( std::size_t  n)

Get a list of buffers that represents the output sequence, with the given size.

Ensures that the output sequence can accommodate n bytes, resizing the storage object as necessary.

Parameters
nTotal number of bytes the output sequence has to accomodate.
Returns
An object of type mutable_buffers_type that satisfies MutableBufferSequence requirements, representing memory at the start of the output sequence of size n.
Exceptions
std::length_errorIf size() + n > max_size().
Note
The returned object is invalidated by any basic_linear_buffer member function that modifies the input sequence or output sequence.

◆ prepare() [2/2]

template<typename Allocator >
mutable_buffers_type asioext::dynamic_linear_buffer< Allocator >::prepare ( std::size_t  n,
error_code ec 
)

Get a list of buffers that represents the output sequence, with the given size.

Ensures that the output sequence can accommodate n bytes, resizing the storage object as necessary.

Parameters
nTotal number of bytes the output sequence has to accomodate.
ecSet to indicate what error occurred. If no error occurred, the object is reset.
Returns
An object of type mutable_buffers_type that satisfies MutableBufferSequence requirements, representing memory at the start of the output sequence of size n.
Note
The returned object is invalidated by any basic_linear_buffer member function that modifies the input sequence or output sequence.
This function is not part of the DynamicBuffer requirements.

◆ size()

template<typename Allocator >
std::size_t asioext::dynamic_linear_buffer< Allocator >::size ( ) const
inlinenoexcept

Get the size of the input sequence.