Asio Extensions
Additional functionality built on top of (Boost.)Asio
|
A dynamically sized contiguously stored buffer. More...
#include <asioext/linear_buffer.hpp>
Public Types | |
typedef Allocator | allocator_type |
typedef std::allocator_traits< allocator_type > | allocator_traits_type |
typedef uint8_t * | iterator |
The type used to represent an iterator for the buffer's data. More... | |
typedef const uint8_t * | const_iterator |
typedef uint8_t & | reference |
The type used to represent a reference to a single byte inside the buffer. More... | |
typedef const uint8_t & | const_reference |
Public Member Functions | |
basic_linear_buffer () noexcept | |
Default-construct a basic_linear_buffer. More... | |
basic_linear_buffer (const Allocator &a) noexcept | |
Construct a dynamic buffer from an allocator. More... | |
basic_linear_buffer (std::size_t initial_size, std::size_t maximum_size=(std::numeric_limits< std::size_t >::max)()) | |
Construct a dynamic buffer. More... | |
basic_linear_buffer (const Allocator &a, std::size_t initial_size, std::size_t maximum_size=(std::numeric_limits< std::size_t >::max)()) | |
Construct a dynamic buffer from an allocator. More... | |
basic_linear_buffer (basic_linear_buffer &&other) noexcept | |
Move-construct a dynamic buffer. More... | |
~basic_linear_buffer () | |
Destroy the basic_linear_buffer. More... | |
basic_linear_buffer & | operator= (basic_linear_buffer &&other) noexcept |
Move-assign a dynamic 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... | |
iterator | begin () noexcept |
Get an iterator pointing at the buffer data beginning. More... | |
iterator | end () noexcept |
Get an iterator pointing at the buffer data end. More... | |
const_iterator | begin () const noexcept |
Get an iterator pointing at the buffer data beginning. More... | |
const_iterator | end () const noexcept |
Get an iterator pointing at the buffer data end. More... | |
uint8_t * | data () noexcept |
Get a pointer to the buffer data beginning. More... | |
const uint8_t * | data () const noexcept |
Get a pointer to the buffer data beginning. More... | |
reference | operator[] (std::size_t i) noexcept |
Get a reference to a specific byte inside the buffer. More... | |
const_reference | operator[] (std::size_t i) const noexcept |
Get a reference to a specific byte inside the buffer. More... | |
void | append (const void *data, std::size_t n) |
Append the given data to the buffer. More... | |
void | insert (const_iterator before_this, const void *data, std::size_t n) |
Insert the given data before the specified position. More... | |
void | insert (std::size_t before_this, const void *data, std::size_t n) |
Insert the given data before the specified position. More... | |
void | erase (const_iterator pos) |
Erase the single byte at the specified position. More... | |
void | erase (const_iterator first, const_iterator last) |
Erase the bytes in the range [first, last) . More... | |
void | erase (std::size_t pos) |
Erase the single byte at the specified position. More... | |
void | erase (std::size_t first, std::size_t last) |
Erase the bytes in the range [first, last) . More... | |
void | resize (std::size_t new_size) |
Resize the buffer. More... | |
void | clear () noexcept |
Clear the buffer. More... | |
A dynamically sized contiguously stored buffer.
This class owns and manages a contiguous buffer that is divided into an input and output sequence.
DynamicBuffer
this class owns the buffer it manages. Unless you are not interested in the data read/written and the buffer object can be destroyed once the operation finishes, it's not recommended to use this class with the DynamicBuffer functions provided by Asio. typedef std::allocator_traits<allocator_type> asioext::basic_linear_buffer< Allocator >::allocator_traits_type |
typedef Allocator asioext::basic_linear_buffer< Allocator >::allocator_type |
typedef const uint8_t* asioext::basic_linear_buffer< Allocator >::const_iterator |
The type used to represent an iterator for a constant view of the buffer's data.
typedef const uint8_t& asioext::basic_linear_buffer< Allocator >::const_reference |
The type used to represent a const. reference to a single byte inside the buffer.
typedef uint8_t* asioext::basic_linear_buffer< Allocator >::iterator |
The type used to represent an iterator for the buffer's data.
typedef uint8_t& asioext::basic_linear_buffer< Allocator >::reference |
The type used to represent a reference to a single byte inside the buffer.
|
inlinenoexcept |
Default-construct a basic_linear_buffer.
The constructed basic_linear_buffer is empty and doesn't have any allocated memory.
|
inlineexplicitnoexcept |
Construct a dynamic buffer from an allocator.
The constructed basic_linear_buffer is empty and doesn't have any allocated memory.
a | The allocator that shall be used to allocate the buffer's storage. |
|
inline |
Construct a dynamic buffer.
initial_size | The initial size that the buffer starts with. |
maximum_size | Specifies a maximum size for the buffer, in bytes. |
|
inline |
Construct a dynamic buffer from an allocator.
a | The allocator that shall be used to allocate the buffer's storage. |
initial_size | The initial size that the buffer starts with. |
maximum_size | Specifies a maximum size for the buffer, in bytes. |
|
inlinenoexcept |
Move-construct a dynamic buffer.
After the move, other
is an empty buffer with no allocated memory (as-if just default-constructed).
|
inline |
Destroy the basic_linear_buffer.
Deallocates all owned data.
void asioext::basic_linear_buffer< Allocator >::append | ( | const void * | data, |
std::size_t | n | ||
) |
Append the given data to the buffer.
This function appends the given raw data to the buffer, resizing it as necessary.
If the buffer is resized, all iterators and references (including the end()
iterator) are invalidated. Otherwise only the end()
iterator is invalidated.
data | The raw bytes to append. |
n | Number of raw bytes to append. |
std::length_error | If size() + n > max_size() . |
|
inlinenoexcept |
Get an iterator pointing at the buffer data beginning.
|
inlinenoexcept |
Get an iterator pointing at the buffer data beginning.
|
inlinenoexcept |
Get the current capacity of the dynamic buffer.
|
inlinenoexcept |
Clear the buffer.
Clears the buffer and resets it to zero size, without deallocating the memory.
|
inlinenoexcept |
Get a pointer to the buffer data beginning.
|
inlinenoexcept |
Get a pointer to the buffer data beginning.
|
inlinenoexcept |
Get an iterator pointing at the buffer data end.
|
inlinenoexcept |
Get an iterator pointing at the buffer data end.
|
inline |
Erase the single byte at the specified position.
This function erases the single byte at the given position.
All iterators and references after the erased byte are invalidated.
pos | Iterator to the byte to remove. Passing a pseudo-iterator such as end() is not allowed. |
|
inline |
Erase the bytes in the range [first, last)
.
This function erases the bytes in the range [first, last)
.
All iterators and references after the first erased byte are invalidated.
first | Iterator to the first byte to remove. |
last | Iterator to one past the last byte to remove. |
void asioext::basic_linear_buffer< Allocator >::erase | ( | std::size_t | pos | ) |
Erase the single byte at the specified position.
This function erases the single byte at the given position.
All iterators and references after the erased byte are invalidated.
pos | Position of the byte to remove. Must be in [0, size()) . |
void asioext::basic_linear_buffer< Allocator >::erase | ( | std::size_t | first, |
std::size_t | last | ||
) |
Erase the bytes in the range [first, last)
.
This function erases the bytes in the range [first, last)
.
All iterators and references after the first erased byte are invalidated.
first | Position of the first byte to remove. |
last | Position of one past the last byte to remove. |
|
inline |
Insert the given data before the specified position.
This function inserts the given raw data before the buffer position pointed at by before_this
. If the new buffer size would exceed the buffer's capacity, it is resized.
If the buffer is resized, all iterators and references (including the end()
iterator) are invalidated. Otherwise only the iterators [before_this, end()]
as well as their corresponding references are invalidated.
void asioext::basic_linear_buffer< Allocator >::insert | ( | std::size_t | before_this, |
const void * | data, | ||
std::size_t | n | ||
) |
Insert the given data before the specified position.
This function inserts the given raw data before the buffer position pointed at by before_this
. If the new buffer size would exceed the buffer's capacity, it is resized.
If the buffer is resized, all iterators and references (including the end()
iterator) are invalidated. Otherwise only the iterators [before_this, end()]
as well as their corresponding references are invalidated.
before_this | Position before which the content will be inserted. before_this may be 0 or the size() . |
data | The raw bytes to insert. |
n | Number of raw bytes to insert. |
|
inlinenoexcept |
Get the maximum size of the dynamic buffer.
|
noexcept |
Move-assign a dynamic buffer.
After the move, other
is an empty buffer with no allocated memory (as-if just default-constructed).
|
inlinenoexcept |
Get a reference to a specific byte inside the buffer.
i | Offset of the wanted byte. |
|
inlinenoexcept |
Get a reference to a specific byte inside the buffer.
i | Offset of the wanted byte. |
void asioext::basic_linear_buffer< Allocator >::resize | ( | std::size_t | new_size | ) |
Resize the buffer.
This function changes the buffer's size to new_size
.
If the buffer is resized, all iterators and references (including the end()
iterator) are invalidated.
|
inlinenoexcept |
Get the size of the input sequence.