32#ifndef MYSQL_BUFFER_RW_BUFFER_SEQUENCE_H_
33#define MYSQL_BUFFER_RW_BUFFER_SEQUENCE_H_
103template <
class Char_tp =
unsigned char,
104 template <
class Element_tp,
class Allocator_tp>
class Container_tp =
135 assert(begin_arg->data() ==
nullptr);
136 assert(begin_arg->size() == 0);
137 for (
auto it = std::next(begin_arg); it !=
end_arg; ++it) {
138 assert(it->data() !=
nullptr);
139 assert(it->size() != 0);
239 [[maybe_unused]]
int indent)
const {
246 sep = std::string(
",\n") +
247 std::string(
static_cast<std::string::size_type
>(indent * 2),
' ');
250 int next_indent = (indent != 0) ? indent + 1 : 0;
252 ss <<
"Rw_buffer_sequence(ptr=" << (
const void *)
this
254 << sep <<
"read_part="
256 << sep <<
"between_r_and_w="
259 .debug_string(show_contents)
260 << sep <<
"write_part="
273 std::string
debug_string([[maybe_unused]]
bool show_contents =
false)
const {
306 new_position = std::min(new_position,
capacity);
310 assert(position >= 0);
313 while (position > new_position)
321 while (position < new_position) {
323 left, right, new_position - position);
325 assert(position == new_position);
357 auto [write_begin, write_end, write_size] =
get_boundaries(right);
358 if (read_end == write_begin) {
359 auto delta = write_begin->size();
360 auto before_read_end = read_end;
363 before_read_end->size() + delta);
399 auto [write_begin, write_end, write_size] =
get_boundaries(right);
400 assert(read_end != write_begin);
401 assert(read_end->data() ==
nullptr);
402 assert(read_end != read_begin);
405 *write_begin = *read_end;
407 auto delta = write_begin->size();
428 auto [write_begin, write_end, write_size] =
get_boundaries(right);
429 assert(read_end != write_begin);
430 assert(read_end->data() ==
nullptr);
431 if (write_begin->size() <= limit) {
441 auto delta = write_begin->size();
442 *read_end = *write_begin;
463 Buffer_view_t(write_begin->data() + limit, write_begin->size() - limit);
478 return std::make_tuple(buffer_sequence_view.
begin(),
479 buffer_sequence_view.
end(),
480 buffer_sequence_view.
size());
Container class that provides a sequence of buffers to the caller.
Class that groups a pointer+size as one object, without managing the memory for it.
Sequence of memory buffers.
Definition: buffer_sequence_view.h:72
Buffer_view< Char_t > Buffer_view_t
Definition: buffer_sequence_view.h:76
Container_tp< Buffer_view_t, Buffer_allocator_t > Container_t
Definition: buffer_sequence_view.h:78
mysqlns::resource::Allocator< Buffer_view_t > Buffer_allocator_t
Definition: buffer_sequence_view.h:77
Iterator_t end()
Iterator to the last buffer.
Definition: buffer_sequence_view.h:119
Iterator_t begin()
Iterator to the first buffer.
Definition: buffer_sequence_view.h:116
std::size_t Size_t
Definition: buffer_sequence_view.h:75
typename std::conditional< const_tp, Const_iterator_t, typename Container_t::iterator >::type Iterator_t
Definition: buffer_sequence_view.h:82
typename Container_t::const_iterator Const_iterator_t
Definition: buffer_sequence_view.h:79
std::string debug_string(bool show_contents=false, int indent=0) const
In debug mode, return a string that describes the internal structure of this object,...
Definition: buffer_sequence_view.h:184
Size_t size() const
Return the total size of all buffers.
Definition: buffer_sequence_view.h:163
Char_tp Char_t
Definition: buffer_sequence_view.h:74
Non-owning manager for a fixed sequence of memory buffers, which is split into a read part and a writ...
Definition: rw_buffer_sequence.h:106
std::ptrdiff_t Difference_t
Definition: rw_buffer_sequence.h:111
const Buffer_sequence_view_t & write_part() const
Return a const reference to the write part.
Definition: rw_buffer_sequence.h:224
Rw_buffer_sequence(Rw_buffer_sequence &)=delete
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.
Definition: rw_buffer_sequence.h:396
typename Buffer_sequence_view_t::Container_t Container_t
Definition: rw_buffer_sequence.h:115
void set_position(Size_t new_position)
Set the specified absolute position.
Definition: rw_buffer_sequence.h:167
typename Buffer_sequence_view_t::Buffer_view_t Buffer_view_t
Definition: rw_buffer_sequence.h:112
void increase_position(Size_t delta)
Move the position right, relative to the current position.
Definition: rw_buffer_sequence.h:186
Rw_buffer_sequence(Iterator_t begin_arg, Iterator_t end_arg)
Construct a new Rw_buffer_sequence from given endpoint iterators, with position 0.
Definition: rw_buffer_sequence.h:130
std::string debug_string(bool show_contents=false) const
In debug mode, return a string that describes the internal structure of this object,...
Definition: rw_buffer_sequence.h:273
Rw_buffer_sequence & operator=(Rw_buffer_sequence &)=delete
virtual ~Rw_buffer_sequence()=default
Buffer_sequence_view< Char_tp, Container_tp, true > Const_buffer_sequence_view_t
Definition: rw_buffer_sequence.h:119
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 the...
Definition: rw_buffer_sequence.h:354
Buffer_sequence_view_t & write_part()
Return a non-const reference to the write part.
Definition: rw_buffer_sequence.h:227
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...
Definition: rw_buffer_sequence.h:424
typename Buffer_sequence_view_t::Buffer_allocator_t Buffer_allocator_t
Definition: rw_buffer_sequence.h:114
typename Buffer_sequence_view_t::Iterator_t Iterator_t
Definition: rw_buffer_sequence.h:116
Rw_buffer_sequence(Rw_buffer_sequence &&)=delete
const Buffer_sequence_view_t & read_part() const
Return a const reference to the read part.
Definition: rw_buffer_sequence.h:218
Size_t capacity() const
Return the current size, i.e., total size of all buffers.
Definition: rw_buffer_sequence.h:215
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.
Definition: rw_buffer_sequence.h:299
static std::tuple< Iterator_t, Iterator_t, Size_t > get_boundaries(Buffer_sequence_view_t &buffer_sequence_view)
Return the beginning, end, and size of the read and write parts.
Definition: rw_buffer_sequence.h:476
Buffer_sequence_view_t m_read_part
buffer_sequence_view for the (leading) read segment.
Definition: rw_buffer_sequence.h:485
Buffer_sequence_view< Char_tp, Container_tp > Buffer_sequence_view_t
Definition: rw_buffer_sequence.h:108
Buffer_sequence_view_t & read_part()
Return a non-const reference to the read part.
Definition: rw_buffer_sequence.h:221
void move_position(Difference_t delta)
Move the position left or right, relative to the current position.
Definition: rw_buffer_sequence.h:206
typename Buffer_sequence_view_t::Const_iterator_t Const_iterator_t
Definition: rw_buffer_sequence.h:117
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,...
Definition: rw_buffer_sequence.h:238
typename Buffer_sequence_view_t::Char_t Char_t
Definition: rw_buffer_sequence.h:109
Buffer_sequence_view_t m_write_part
buffer_sequence_view for the (trailing) write segment.
Definition: rw_buffer_sequence.h:487
typename Buffer_sequence_view_t::Size_t Size_t
Definition: rw_buffer_sequence.h:110
Rw_buffer_sequence & operator=(Rw_buffer_sequence &&)=delete
Allocator class that uses a polymorphic Memory_resource to allocate memory.
Definition: buffer_sequence_view.h:51
Definition: gcs_xcom_synode.h:64
std::basic_ostringstream< char, std::char_traits< char >, ut::allocator< char > > ostringstream
Specialization of basic_ostringstream which uses ut::allocator.
Definition: ut0new.h:2870
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2874
static task_arg end_arg()
Definition: task.h:207
Contains wrapper functions for memory allocation and deallocation.
#define BAPI_TRACE
Definition: wrapper_functions.h:66