MySQL 8.0.39
Source Code Documentation
mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp > Class Template Reference

Non-owning manager for a fixed sequence of memory buffers, which is split into a read part and a write part, with a movable split position. More...

#include <rw_buffer_sequence.h>

Public Types

using Buffer_sequence_view_t = Buffer_sequence_view< Char_tp, Container_tp >
 
using Char_t = typename Buffer_sequence_view_t::Char_t
 
using Size_t = typename Buffer_sequence_view_t::Size_t
 
using Difference_t = std::ptrdiff_t
 
using Buffer_view_t = typename Buffer_sequence_view_t::Buffer_view_t
 
using Buffer_allocator_t = typename Buffer_sequence_view_t::Buffer_allocator_t
 
using Container_t = typename Buffer_sequence_view_t::Container_t
 
using Iterator_t = typename Buffer_sequence_view_t::Iterator_t
 
using Const_iterator_t = typename Buffer_sequence_view_t::Const_iterator_t
 
using Const_buffer_sequence_view_t = Buffer_sequence_view< Char_tp, Container_tp, true >
 

Public Member Functions

 Rw_buffer_sequence (Iterator_t begin_arg, Iterator_t end_arg)
 Construct a new Rw_buffer_sequence from given endpoint iterators, with position 0. More...
 
 Rw_buffer_sequence (Rw_buffer_sequence &)=delete
 
 Rw_buffer_sequence (Rw_buffer_sequence &&)=delete
 
Rw_buffer_sequenceoperator= (Rw_buffer_sequence &)=delete
 
Rw_buffer_sequenceoperator= (Rw_buffer_sequence &&)=delete
 
virtual ~Rw_buffer_sequence ()=default
 
void set_position (Size_t new_position)
 Set the specified absolute position. More...
 
void increase_position (Size_t delta)
 Move the position right, relative to the current position. More...
 
void move_position (Difference_t delta)
 Move the position left or right, relative to the current position. More...
 
Size_t capacity () const
 Return the current size, i.e., total size of all buffers. More...
 
const Buffer_sequence_view_tread_part () const
 Return a const reference to the read part. More...
 
Buffer_sequence_view_tread_part ()
 Return a non-const reference to the read part. More...
 
const Buffer_sequence_view_twrite_part () const
 Return a const reference to the write part. More...
 
Buffer_sequence_view_twrite_part ()
 Return a non-const reference to the write part. More...
 
virtual std::string debug_string (bool show_contents, int indent) const
 In debug mode, return a string that describes the internal structure of this object, to use for debugging. More...
 
std::string debug_string (bool show_contents=false) const
 In debug mode, return a string that describes the internal structure of this object, to use for debugging. More...
 

Static Protected Member Functions

static void set_position (Size_t new_position, Buffer_sequence_view_t &left, Buffer_sequence_view_t &right)
 Move the position to the given, absolute position. More...
 
static Size_t merge_if_split (Buffer_sequence_view_t &left, Buffer_sequence_view_t &right)
 If a buffer is split between the read and write parts, glue the pieces together again and include them in the read part. More...
 
static Size_t move_position_one_buffer_left (Buffer_sequence_view_t &left, Buffer_sequence_view_t &right)
 Move the position exactly one buffer left, assuming no buffer is split. More...
 
static Size_t move_position_at_most_one_buffer_right (Buffer_sequence_view_t &left, Buffer_sequence_view_t &right, Size_t limit)
 Move the position right by whatever is smaller: the given number, or one buffer; splits the buffer if the number is smaller than the buffer. More...
 
static std::tuple< Iterator_t, Iterator_t, Size_tget_boundaries (Buffer_sequence_view_t &buffer_sequence_view)
 Return the beginning, end, and size of the read and write parts. More...
 

Private Attributes

Buffer_sequence_view_t m_read_part
 buffer_sequence_view for the (leading) read segment. More...
 
Buffer_sequence_view_t m_write_part
 buffer_sequence_view for the (trailing) write segment. More...
 

Detailed Description

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
class mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >

Non-owning manager for a fixed sequence of memory buffers, which is split into a read part and a write part, with a movable split position.

This has a read/write position (which Buffer_sequence does not have). It does not have functionailty to grow the buffer sequence (as Managed_buffer_sequence has).

Objects have one internal contiguous container (vector or list), which is split into two parts, each of which is a Buffer_sequence_view: the first part is the read part and the second part is the write part. API clients typically write to the write part and then move the position forwards: this will increase the read part so that API clients can read what was just written, and decrease the write part so that next write will happen after the position that was just written.

The position that defines the end of the read part and the beginning of the write part has byte granularity. Therefore, it does not have to be at a buffer boundary. When it is not on a buffer boundary, a buffer has to be split. When a buffer is split, the sequence needs one more element than the actual number of (contiguous) buffers. When the position is moved from a buffer boundary to a non-boundary, the number of used elements increases by one. To avoid having to shift all the buffers for the write part one step right when the container is a vector, there is always one more element than the actual number of contiguous buffers. So when the position is at a buffer boundary, an unused "null buffer" is stored between the read part and the write part. In other words, the buffer sequence has one of the following forms:

Position at buffer boundary:
Here, there are N buffers where the first R ones are read buffers.
[b_1, ..., b_R, null, b_{R+1}, ..., b_N]
Position not at buffer boundary:
Here there are N buffers where the first R-1 ones are read buffers,
and the R'th one is split into a read part and a write part.
[b_1, ..., b_R[0..x], b_R[x..], b_{R+1}, ..., b_N]
static char * where
Definition: mysqldump.cc:140
std::atomic< Type > N
Definition: ut0counter.h:225
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:420
std::enable_if_t< is_mutable_buffer_sequence< MutableBufferSequence >::value, stdx::expected< size_t, std::error_code > > read(SyncReadStream &stream, const MutableBufferSequence &buffers)
Definition: buffer.h:838
Template Parameters
Char_tpthe type of elements stored in the buffer: typically unsigned char.
Container_tpthe type of container: either std::vector or std::list.

Member Typedef Documentation

◆ Buffer_allocator_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::Buffer_allocator_t = typename Buffer_sequence_view_t::Buffer_allocator_t

◆ Buffer_sequence_view_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::Buffer_sequence_view_t = Buffer_sequence_view<Char_tp, Container_tp>

◆ Buffer_view_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::Buffer_view_t = typename Buffer_sequence_view_t::Buffer_view_t

◆ Char_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::Char_t = typename Buffer_sequence_view_t::Char_t

◆ Const_buffer_sequence_view_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::Const_buffer_sequence_view_t = Buffer_sequence_view<Char_tp, Container_tp, true>

◆ Const_iterator_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::Const_iterator_t = typename Buffer_sequence_view_t::Const_iterator_t

◆ Container_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::Container_t = typename Buffer_sequence_view_t::Container_t

◆ Difference_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::Difference_t = std::ptrdiff_t

◆ Iterator_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::Iterator_t = typename Buffer_sequence_view_t::Iterator_t

◆ Size_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::Size_t = typename Buffer_sequence_view_t::Size_t

Constructor & Destructor Documentation

◆ Rw_buffer_sequence() [1/3]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::Rw_buffer_sequence ( Iterator_t  begin_arg,
Iterator_t  end_arg 
)
inline

Construct a new Rw_buffer_sequence from given endpoint iterators, with position 0.

The provided sequence of buffers must start with one null buffer, followed by zero or more non-null buffers.

Parameters
begin_argIterator to the beginning of the sequence.
end_argIterator to one-past-the-end of the sequence.

◆ Rw_buffer_sequence() [2/3]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::Rw_buffer_sequence ( Rw_buffer_sequence< Char_tp, Container_tp > &  )
delete

◆ Rw_buffer_sequence() [3/3]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::Rw_buffer_sequence ( Rw_buffer_sequence< Char_tp, Container_tp > &&  )
delete

◆ ~Rw_buffer_sequence()

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
virtual mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::~Rw_buffer_sequence ( )
virtualdefault

Member Function Documentation

◆ capacity()

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
Size_t mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::capacity ( ) const
inline

Return the current size, i.e., total size of all buffers.

◆ debug_string() [1/2]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
virtual std::string mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::debug_string ( bool  show_contents,
int  indent 
) const
inlinevirtual

In debug mode, return a string that describes the internal structure of this object, to use for debugging.

Parameters
show_contentsIf true, includes the buffer contents. Otherwise, just pointers and sizes.
indentIf 0, put all info on one line. Otherwise, put each field on its own line and indent the given number of two-space levels.

Reimplemented in mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >.

◆ debug_string() [2/2]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
std::string mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::debug_string ( bool  show_contents = false) const
inline

In debug mode, return a string that describes the internal structure of this object, to use for debugging.

Parameters
show_contentsIf true, includes the buffer contents. Otherwise, just pointers and sizes.

◆ get_boundaries()

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
static std::tuple< Iterator_t, Iterator_t, Size_t > mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::get_boundaries ( Buffer_sequence_view_t buffer_sequence_view)
inlinestaticprotected

Return the beginning, end, and size of the read and write parts.

Parameters
buffer_sequence_viewThe buffer sequence view.
Returns
3-tuple containing the beginning, size, and end of the given buffer_sequence_view.

◆ increase_position()

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
void mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::increase_position ( Size_t  delta)
inline

Move the position right, relative to the current position.

"Position" is a synonym for "size of the read part".

Note
This may alter the end iterator of the read part, the begin iterator of the write part, as well as the begin/end iterators of buffers between the current position and the new position. The beginning of the read part, the end of the write part, and buffers outside the range between the new and old position remain unchanged.
Parameters
deltaThe number of bytes to add to the position. The resulting size must be within bounds; otherwise an assertion is raised in debug build, or the position forced to the beginning/end in non-debug build.

◆ merge_if_split()

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
static Size_t mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::merge_if_split ( Buffer_sequence_view_t left,
Buffer_sequence_view_t right 
)
inlinestaticprotected

If a buffer is split between the read and write parts, glue the pieces together again and include them in the read part.

If no buffer is split (the position is at a buffer boundary), does nothing.

Graphically, the operation is as follows:

+-----------------+-----------------+
| b1[0..split] | b1[split..] |
+-----------------+-----------------+
^ read_end
^ write_begin
-->
+-----------------+-----------------+
| b1 | null |
+-----------------+-----------------+
^ read_end ^ write_begin
Parameters
leftThe left buffer sequence.
rightThe right buffer sequence.
Returns
The number of bytes that the position was moved left.

◆ move_position()

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
void mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::move_position ( Difference_t  delta)
inline

Move the position left or right, relative to the current position.

"Position" is a synonym for "size of the read part".

Note
This may alter the end iterator of the read part, the begin iterator of the write part, as well as the begin/end iterators of buffers between the current position and the new position. The beginning of the read part, the end of the write part, and buffers outside the range between the new and old position remain unchanged.
Parameters
deltaThe number of bytes to add to the position. The resulting size must be within bounds; otherwise an assertion is raised in debug build, or the position forced to the beginning/end in non-debug build.

◆ move_position_at_most_one_buffer_right()

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
static Size_t mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::move_position_at_most_one_buffer_right ( Buffer_sequence_view_t left,
Buffer_sequence_view_t right,
Size_t  limit 
)
inlinestaticprotected

Move the position right by whatever is smaller: the given number, or one buffer; splits the buffer if the number is smaller than the buffer.

Parameters
leftThe left buffer sequence.
rightThe right buffer sequence.
limitMove the position at most this number of bytes right.
Returns
The number of bytes that the position was moved right.

◆ move_position_one_buffer_left()

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
static Size_t mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::move_position_one_buffer_left ( Buffer_sequence_view_t left,
Buffer_sequence_view_t right 
)
inlinestaticprotected

Move the position exactly one buffer left, assuming no buffer is split.

Graphically, the operation is as follows:

+-----------------+-----------------+
| b1 | null |
+-----------------+-----------------+
^ read_end ^ write_begin
-->
+-----------------+-----------------+
| null | b1 |
+-----------------+-----------------+
^ read_end ^ write_begin
Parameters
leftThe left buffer sequence.
rightThe right buffer sequence.
Returns
The number of bytes that the position was moved left.

◆ operator=() [1/2]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
Rw_buffer_sequence & mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::operator= ( Rw_buffer_sequence< Char_tp, Container_tp > &&  )
delete

◆ operator=() [2/2]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
Rw_buffer_sequence & mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::operator= ( Rw_buffer_sequence< Char_tp, Container_tp > &  )
delete

◆ read_part() [1/2]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
Buffer_sequence_view_t & mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::read_part ( )
inline

Return a non-const reference to the read part.

◆ read_part() [2/2]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
const Buffer_sequence_view_t & mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::read_part ( ) const
inline

Return a const reference to the read part.

◆ set_position() [1/2]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
void mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::set_position ( Size_t  new_position)
inline

Set the specified absolute position.

"Position" is a synonym for "size of the read part".

Note
This may alter the end iterator of the read part, the begin iterator of the write part, as well as the begin/end iterators of buffers between the current position and the new position. The beginning of the read part, the end of the write part, and buffers outside the range between the new and old position remain unchanged.
Parameters
new_positionThe new size of the read part. This must be within bounds; otherwise an assertion is raised in debug build, or the position forced to the end in non-debug build.

◆ set_position() [2/2]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
static void mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::set_position ( Size_t  new_position,
Buffer_sequence_view_t left,
Buffer_sequence_view_t right 
)
inlinestaticprotected

Move the position to the given, absolute position.

Note
This may alter the end iterator of the left part, the begin iterator of the right part, as well as the begin/end iterators of buffers between the current position and the new position. The beginning of the left part, the end of the right part, and buffers outside the range between the new and old position remain unchanged.
Parameters
new_positionThe new position. This must be within bounds. Otherwise an assertion is raised in debug build; in non-debug build, the position is forced to the end.
leftThe left buffer sequence.
rightThe right buffer sequence.
Note
One of the following must hold: (1) the container has one element between the left part and the right part, and that element is a null buffer; (2) left.end()==right.begin() && left.end().end()==right.begin().begin().

◆ write_part() [1/2]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
Buffer_sequence_view_t & mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::write_part ( )
inline

Return a non-const reference to the write part.

◆ write_part() [2/2]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
const Buffer_sequence_view_t & mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::write_part ( ) const
inline

Return a const reference to the write part.

Member Data Documentation

◆ m_read_part

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
Buffer_sequence_view_t mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::m_read_part
private

buffer_sequence_view for the (leading) read segment.

◆ m_write_part

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
Buffer_sequence_view_t mysqlns::buffer::Rw_buffer_sequence< Char_tp, Container_tp >::m_write_part
private

buffer_sequence_view for the (trailing) write segment.


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