Clementine
Public Types | Public Member Functions | List of all members
asio::dynamic_vector_buffer< Elem, Allocator > Class Template Reference

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

#include <buffer.hpp>

Public Types

typedef ASIO_CONST_BUFFER const_buffers_type
 The type used to represent a sequence of constant buffers that refers to the underlying memory. More...
 
typedef ASIO_MUTABLE_BUFFER mutable_buffers_type
 The type used to represent a sequence of mutable buffers that refers to the underlying memory. More...
 

Public Member Functions

 dynamic_vector_buffer (std::vector< Elem, Allocator > &v, std::size_t maximum_size=(std::numeric_limits< std::size_t >::max)()) ASIO_NOEXCEPT
 Construct a dynamic buffer from a vector. More...
 
 dynamic_vector_buffer (const dynamic_vector_buffer &other) ASIO_NOEXCEPT
 DynamicBuffer_v2: Copy construct a dynamic buffer.
 
std::size_t size () const ASIO_NOEXCEPT
 DynamicBuffer_v1: Get the size of the input sequence. More...
 
std::size_t max_size () const ASIO_NOEXCEPT
 Get the maximum size of the dynamic buffer. More...
 
std::size_t capacity () const ASIO_NOEXCEPT
 Get the maximum size that the buffer may grow to without triggering reallocation. More...
 
const_buffers_type data () const ASIO_NOEXCEPT
 DynamicBuffer_v1: Get a list of buffers that represents the input sequence. More...
 
mutable_buffers_type data (std::size_t pos, std::size_t n) ASIO_NOEXCEPT
 DynamicBuffer_v2: Get a sequence of buffers that represents the underlying memory. More...
 
const_buffers_type data (std::size_t pos, std::size_t n) const ASIO_NOEXCEPT
 DynamicBuffer_v2: Get a sequence of buffers that represents the underlying memory. More...
 
mutable_buffers_type prepare (std::size_t n)
 DynamicBuffer_v1: Get a list of buffers that represents the output sequence, with the given size. More...
 
void commit (std::size_t n)
 DynamicBuffer_v1: Move bytes from the output sequence to the input sequence. More...
 
void grow (std::size_t n)
 DynamicBuffer_v2: Grow the underlying memory by the specified number of bytes. More...
 
void shrink (std::size_t n)
 DynamicBuffer_v2: Shrink the underlying memory by the specified number of bytes. More...
 
void consume (std::size_t n)
 DynamicBuffer_v1: Remove characters from the input sequence. More...
 

Detailed Description

template<typename Elem, typename Allocator>
class asio::dynamic_vector_buffer< Elem, Allocator >

Adapt a vector to the DynamicBuffer requirements.

Requires that sizeof(Elem) == 1.

Member Typedef Documentation

◆ const_buffers_type

template<typename Elem, typename Allocator>
typedef ASIO_CONST_BUFFER asio::dynamic_vector_buffer< Elem, Allocator >::const_buffers_type

The type used to represent a sequence of constant buffers that refers to the underlying memory.

◆ mutable_buffers_type

template<typename Elem, typename Allocator>
typedef ASIO_MUTABLE_BUFFER asio::dynamic_vector_buffer< Elem, Allocator >::mutable_buffers_type

The type used to represent a sequence of mutable buffers that refers to the underlying memory.

Constructor & Destructor Documentation

◆ dynamic_vector_buffer()

template<typename Elem, typename Allocator>
asio::dynamic_vector_buffer< Elem, Allocator >::dynamic_vector_buffer ( std::vector< Elem, Allocator > &  v,
std::size_t  maximum_size = (std::numeric_limits<std::size_t>::max)() 
)
inlineexplicit

Construct a dynamic buffer from a vector.

Parameters
vThe vector to be used as backing storage for the dynamic buffer. The object stores a reference to the vector and the user is responsible for ensuring that the vector object remains valid while the dynamic_vector_buffer object, and copies of the object, are in use.
maximum_sizeSpecifies a maximum size for the buffer, in bytes.

Member Function Documentation

◆ capacity()

template<typename Elem, typename Allocator>
std::size_t asio::dynamic_vector_buffer< Elem, Allocator >::capacity ( ) const
inline

Get the maximum size that the buffer may grow to without triggering reallocation.

Returns
DynamicBuffer_v1: The current total capacity of the buffer, i.e. for both the input sequence and output sequence. DynamicBuffer_v2: The current capacity of the underlying vector if less than max_size(). Otherwise returns max_size().

◆ commit()

template<typename Elem, typename Allocator>
void asio::dynamic_vector_buffer< Elem, Allocator >::commit ( std::size_t  n)
inline

DynamicBuffer_v1: 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 Elem, typename Allocator>
void asio::dynamic_vector_buffer< Elem, Allocator >::consume ( std::size_t  n)
inline

DynamicBuffer_v1: Remove characters from the input sequence.

DynamicBuffer_v2: Consume the specified number of bytes from the beginning of the underlying memory. DynamicBuffer_v1: 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.

DynamicBuffer_v2: Erases n bytes from the beginning of the vector. If n is greater than the current size of the vector, the vector is emptied.

◆ data() [1/3]

template<typename Elem, typename Allocator>
const_buffers_type asio::dynamic_vector_buffer< Elem, Allocator >::data ( ) const
inline

DynamicBuffer_v1: Get a list of buffers that represents the input sequence.

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

◆ data() [2/3]

template<typename Elem, typename Allocator>
mutable_buffers_type asio::dynamic_vector_buffer< Elem, Allocator >::data ( std::size_t  pos,
std::size_t  n 
)
inline

DynamicBuffer_v2: Get a sequence of buffers that represents the underlying memory.

Parameters
posPosition of the first byte to represent in the buffer sequence
nThe number of bytes to return in the buffer sequence. If the underlying memory is shorter, the buffer sequence represents as many bytes as are available.
Returns
An object of type mutable_buffers_type that satisfies MutableBufferSequence requirements, representing the vector memory.
Note
The returned object is invalidated by any dynamic_vector_buffer or vector member function that resizes or erases the vector.

◆ data() [3/3]

template<typename Elem, typename Allocator>
const_buffers_type asio::dynamic_vector_buffer< Elem, Allocator >::data ( std::size_t  pos,
std::size_t  n 
) const
inline

DynamicBuffer_v2: Get a sequence of buffers that represents the underlying memory.

Parameters
posPosition of the first byte to represent in the buffer sequence
nThe number of bytes to return in the buffer sequence. If the underlying memory is shorter, the buffer sequence represents as many bytes as are available.
Note
The returned object is invalidated by any dynamic_vector_buffer or vector member function that resizes or erases the vector.

◆ grow()

template<typename Elem, typename Allocator>
void asio::dynamic_vector_buffer< Elem, Allocator >::grow ( std::size_t  n)
inline

DynamicBuffer_v2: Grow the underlying memory by the specified number of bytes.

Resizes the vector to accommodate an additional n bytes at the end.

Exceptions
std::length_errorIf size() + n > max_size().

◆ max_size()

template<typename Elem, typename Allocator>
std::size_t asio::dynamic_vector_buffer< Elem, Allocator >::max_size ( ) const
inline

Get the maximum size of the dynamic buffer.

Returns
DynamicBuffer_v1: The allowed maximum of the sum of the sizes of the input sequence and output sequence. DynamicBuffer_v2: The allowed maximum size of the underlying memory.

◆ prepare()

template<typename Elem, typename Allocator>
mutable_buffers_type asio::dynamic_vector_buffer< Elem, Allocator >::prepare ( std::size_t  n)
inline

DynamicBuffer_v1: 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 vector object as necessary.

Returns
An object of type mutable_buffers_type that satisfies MutableBufferSequence requirements, representing vector 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 dynamic_vector_buffer or vector member function that modifies the input sequence or output sequence.

◆ shrink()

template<typename Elem, typename Allocator>
void asio::dynamic_vector_buffer< Elem, Allocator >::shrink ( std::size_t  n)
inline

DynamicBuffer_v2: Shrink the underlying memory by the specified number of bytes.

Erases n bytes from the end of the vector by resizing the vector object. If n is greater than the current size of the vector, the vector is emptied.

◆ size()

template<typename Elem, typename Allocator>
std::size_t asio::dynamic_vector_buffer< Elem, Allocator >::size ( ) const
inline

DynamicBuffer_v1: Get the size of the input sequence.

DynamicBuffer_v2: Get the current size of the underlying memory.

Returns
DynamicBuffer_v1 The current size of the input sequence. DynamicBuffer_v2: The current size of the underlying vector if less than max_size(). Otherwise returns max_size().

The documentation for this class was generated from the following file: