MySQL 8.0.40
Source Code Documentation
mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp > Class Template Reference

Owned, non-contiguous, growable memory buffer. More...

#include <managed_buffer_sequence.h>

Inheritance diagram for mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >:
[legend]

Public Types

using Rw_buffer_sequence_t = Rw_buffer_sequence< Char_tp, Container_tp >
 
using Buffer_sequence_view_t = Buffer_sequence_view< Char_tp, Container_tp >
 
using Grow_calculator_t = Grow_calculator
 
using Buffer_allocator_t = typename Buffer_sequence_view_t::Buffer_allocator_t
 
using Char_allocator_t = mysqlns::resource::Allocator< Char_t >
 
using Memory_resource_t = mysqlns::resource::Memory_resource
 
using Buffer_view_t = typename Buffer_sequence_view_t::Buffer_view_t
 
using Char_t = typename Buffer_sequence_view_t::Char_t
 
using Const_iterator_t = typename Buffer_sequence_view_t::Const_iterator_t
 
using Container_t = typename Buffer_sequence_view_t::Container_t
 
using Iterator_t = typename Buffer_sequence_view_t::Iterator_t
 
using Size_t = typename Buffer_sequence_view_t::Size_t
 
- Public Types inherited from mysqlns::buffer::Rw_buffer_sequence< unsigned char, std::vector >
using Buffer_sequence_view_t = Buffer_sequence_view< unsigned char, std::vector >
 
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< unsigned char, std::vector, true >
 

Public Member Functions

 Managed_buffer_sequence (const Grow_calculator_t &grow_calculator=Grow_calculator_t(), const Memory_resource_t &memory_resource=Memory_resource_t(), const Size_t default_buffer_count=16)
 Construct a new, empty object. More...
 
 Managed_buffer_sequence (Managed_buffer_sequence &)=delete
 
 Managed_buffer_sequence (Managed_buffer_sequence &&)=delete
 
Managed_buffer_sequenceoperator= (Managed_buffer_sequence &)=delete
 
Managed_buffer_sequenceoperator= (Managed_buffer_sequence &&)=delete
 
 ~Managed_buffer_sequence () override
 
Grow_status reserve_write_size (Size_t requested_write_size)
 Ensure the write part has at least the given size. More...
 
Grow_status reserve_total_size (Size_t requested_total_size)
 Ensure the total capacity - the sum of sizes of read part and write part - is at least the given number. More...
 
void reset (Size_t keep_buffer_count=1, Size_t keep_container_capacity=16)
 Reset the read part and the write part to size 0. More...
 
const Grow_calculator_tget_grow_calculator () const
 Return a const reference to the grow calculator. More...
 
void set_grow_calculator (const Grow_calculator_t &grow_calculator)
 Set the grow calculator. More...
 
Grow_status write (const Char_t *data, Size_t size)
 Append the given data. More...
 
std::string debug_string (bool show_contents, int indent) const override
 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...
 
- Public Member Functions inherited from mysqlns::buffer::Rw_buffer_sequence< unsigned char, std::vector >
 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...
 
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...
 

Protected Types

using List_t = typename std::list< Buffer_view_t, Buffer_allocator_t >
 
using List_iterator_t = typename List_t::iterator
 
using Vector_t = typename std::vector< Buffer_view_t, Buffer_allocator_t >
 
using Vector_iterator_t = typename Vector_t::iterator
 

Protected Member Functions

 Managed_buffer_sequence (Container_t buffers, const Grow_calculator_t &grow_calculator, const Memory_resource_t &memory_resource)
 Construct a new object from a given container, where both the read part and the write part are size zero. More...
 
bool allocate_and_add_buffer (Size_t size)
 Allocate and add a new buffer. More...
 
bool add_buffer (Char_t *buffer_data, Size_t buffer_size)
 Insert the given buffer in the container, appending it to the write part. More...
 

Static Protected Member Functions

static void reset_container (Vector_t &container, Size_t keep_container_capacity)
 std::vector-specific function to reset the container. More...
 
static void reset_container (List_t &container, Size_t keep_container_capacity)
 std::list-specific function to reset the container. More...
 
- Static Protected Member Functions inherited from mysqlns::buffer::Rw_buffer_sequence< unsigned char, std::vector >
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

Grow_calculator_t m_grow_calculator
 Determines how much memory to allocate when new memory is needed. More...
 
Char_allocator_t m_char_allocator
 Allocator to allocate buffer data (characters). More...
 
Container_t m_buffers
 Container of buffers. More...
 

Friends

template<class T >
class managed_buffer_sequence::unittest::Accessor
 Open the class internals to any class named Accessor<T>, for some T. More...
 

Detailed Description

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

Owned, non-contiguous, growable memory buffer.

This class never moves buffer data, but is non-contiguous. It is implemented as a container of Buffer objects.

Objects have a growable size, a movable position, and two buffer_sequence_view objects called the read part and the write part, which are accessible through the member functions read_part and write_part. The read part is everything preceding the position, and the write part is everything following the position. API clients acting as producers should write to the write part and then move the position forward as many bytes as it wrote. API clients acting as consumers should read the read part.

Generally, std::ostringstream or std::vector<char> are safer and simpler interfaces for buffers and should be preferred when possible. However they do not fit all use cases:

  • std::ostringstream is preferrable and more convenient when appending existing data to the stream. But it is not suitable for interaction with C-like APIs that produce data in a char* given by the caller. The user would need to allocate a buffer outside the ostringsteam and then append the buffer to the ostringstream, which would imply unnecessary memory and cpu overheads.
  • When using a C-like API that produces data in a char* given by the caller, std::vector is often good. The user can reserve as much memory as needed and then pass the underlying data array to the API. However, the following properties are sometimes advantageous for Managed_buffer_sequence:
    • Vector has no practical way to put an exact bound on the memory usage. Managed_buffer_sequence uses a Grow_calculator which allows exact control over memory usage, including a maximum size.
    • Vector has to copy all existing data when it grows. Managed_buffer_sequence never needs to copy data. Since it allows data to be non-contigous, it retains existing buffers while allocating new ones.

The main drawbacks of Managed_buffer_sequence are that it is non-standard, has a minimal feature set, and is non-contiguous.

This class never throws any exception.

Template Parameters
Char_tthe type of elements stored in the buffer: typically unsigned char.
Container_tpThe type of container to hold the buffers. This defaults to std::vector, but std::list is also possible.

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::Managed_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::Managed_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_allocator_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::Char_allocator_t = mysqlns::resource::Allocator<Char_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_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

◆ Grow_calculator_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::Grow_calculator_t = Grow_calculator

◆ 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

◆ List_iterator_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::List_iterator_t = typename List_t::iterator
protected

◆ List_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::List_t = typename std::list<Buffer_view_t, Buffer_allocator_t>
protected

◆ Memory_resource_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::Memory_resource_t = mysqlns::resource::Memory_resource

◆ Rw_buffer_sequence_t

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

◆ 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

◆ Vector_iterator_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::Vector_iterator_t = typename Vector_t::iterator
protected

◆ Vector_t

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
using mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::Vector_t = typename std::vector<Buffer_view_t, Buffer_allocator_t>
protected

Constructor & Destructor Documentation

◆ Managed_buffer_sequence() [1/4]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::Managed_buffer_sequence ( const Grow_calculator_t grow_calculator = Grow_calculator_t(),
const Memory_resource_t memory_resource = Memory_resource_t(),
const Size_t  default_buffer_count = 16 
)
inlineexplicit

Construct a new, empty object.

Parameters
grow_calculatorthe policy to determine how much memory to allocate, when new memory is needed
memory_resourceThe memory_resource used to allocate new memory, both for the container and for the buffers.
default_buffer_countThe initial size of the container. This preallocates the container but not the buffers contained in it.

◆ Managed_buffer_sequence() [2/4]

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

◆ Managed_buffer_sequence() [3/4]

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

◆ ~Managed_buffer_sequence()

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

◆ Managed_buffer_sequence() [4/4]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::Managed_buffer_sequence ( Container_t  buffers,
const Grow_calculator_t grow_calculator,
const Memory_resource_t memory_resource 
)
inlineprotected

Construct a new object from a given container, where both the read part and the write part are size zero.

The container will be moved. All elements in the container must be null buffers.

Parameters
buffersContainer of buffers. This must have at least one element. All elements must be null buffers.
grow_calculatordetermines how much memory to allocate when new memory is needed.
memory_resourceThe memory_resource used to allocate new memory, both for the container and for the buffers.

Member Function Documentation

◆ add_buffer()

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
bool mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::add_buffer ( Char_t buffer_data,
Size_t  buffer_size 
)
inlineprotected

Insert the given buffer in the container, appending it to the write part.

Parameters
buffer_dataThe buffer.
buffer_sizeThe buffer size.
Return values
falseSuccess.
trueAn out of memory error occurred when growing the container.

◆ allocate_and_add_buffer()

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
bool mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::allocate_and_add_buffer ( Size_t  size)
inlineprotected

Allocate and add a new buffer.

Parameters
sizeThe size of the new buffer that should be allocated.
Return values
trueAn out of memory condition occurred, and the function did not produce any side effects.
falseThe operation succeeded, and the object now has at least the requested size.

◆ debug_string() [1/2]

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

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 from mysqlns::buffer::Rw_buffer_sequence< unsigned char, std::vector >.

◆ 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::Managed_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_grow_calculator()

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
const Grow_calculator_t & mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::get_grow_calculator ( ) const
inline

Return a const reference to the grow calculator.

◆ operator=() [1/2]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
Managed_buffer_sequence & mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::operator= ( Managed_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>
Managed_buffer_sequence & mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::operator= ( Managed_buffer_sequence< Char_tp, Container_tp > &  )
delete

◆ reserve_total_size()

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
Grow_status mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::reserve_total_size ( Size_t  requested_total_size)
inline

Ensure the total capacity - the sum of sizes of read part and write part - is at least the given number.

This may add a new buffer if needed. When the previous size is less than the default size, this may even add two buffers: the default buffer and one more. Therefore, the caller should not assume that all the added size resides within one buffer.

Existing buffer data will not move. The container of buffers may grow, which may move the Buffer objects which hold pointers to the data. Therefore, all iterators are invalidated by this.

Parameters
requested_total_sizeThe requested total size of all read and write buffers.
Return values
successThe object now has at least the requested total size. The object may have been resized.
exceeds_max_sizeThe existing size or the requested size exceeds either the maximum size. The object is unchanged.
out_of_memoryThe request could only be fulfilled by allocating more memory, but memory allocation failed. The object is unchanged.

◆ reserve_write_size()

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
Grow_status mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::reserve_write_size ( Size_t  requested_write_size)
inline

Ensure the write part has at least the given size.

This is only a convenience wrapper around reserve_total_size.

Parameters
requested_write_sizeThe requested size of the write part.
Return values
successThe write part now has at least the requested size. The object may have been resized, following the rules of the Grow_calculator.
exceeds_max_sizeEither size() or read_part.size() + requested_write_size exceeds the max size configured in the Grow_calculator. The object is unchanged.
out_of_memoryThe request could only be fulfilled by allocating more memory, but memory allocation failed. The object is unchanged.

◆ reset()

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
void mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::reset ( Size_t  keep_buffer_count = 1,
Size_t  keep_container_capacity = 16 
)
inline

Reset the read part and the write part to size 0.

This optionally keeps a given number of allocated buffers in the write part, as well as a given amount of container capacity.

Parameters
keep_buffer_countThe number of existing buffers to keep. Using a nonzero value for this reduces container allocations when this object is reused. If the container has fewer buffers, the existing buffers will be kept and no more will be allocated. If the container has more buffers, the excess buffers will be deallocated.
keep_container_capacityThe amount of container capacity to keep. Using a small nonzero value for this reduces container allocations when this object is reused. This must be at least the number of kept buffers plus two; otherwise it is modified to that number. If the underlying container type is a vector, it will only shrink if it would reduce the number of elements by half.

◆ reset_container() [1/2]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
static void mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::reset_container ( List_t container,
Size_t  keep_container_capacity 
)
inlinestaticprotected

std::list-specific function to reset the container.

This shrinks the list to keep_container_capacity if it is bigger than keep_container_capacity.

Parameters
[in,out]containerReference to the list to be reset.
keep_container_capacityKeep this number of elements in the list, in order to save future allocations of list nodes.
Returns
Iterator to one-past-the-end of the list.

◆ reset_container() [2/2]

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
static void mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::reset_container ( Vector_t container,
Size_t  keep_container_capacity 
)
inlinestaticprotected

std::vector-specific function to reset the container.

This shrinks the vector to keep_container_capacity if it is bigger than twice keep_container_capacity.

Parameters
[in,out]containerReference to the vector to be reset.
keep_container_capacityKeep a number of elements in the vector, to save on future vector resize operations. If the number of elements is at least twice this number, the vector size is reduced to this number.
Returns
Iterator to the end.

◆ set_grow_calculator()

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
void mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::set_grow_calculator ( const Grow_calculator_t grow_calculator)
inline

Set the grow calculator.

◆ write()

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
Grow_status mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::write ( const Char_t data,
Size_t  size 
)
inline

Append the given data.

This will grow the buffer if needed. Then it writes the data to the write part, and moves the position so that the written becomes part of the read part instead of the write part.

Parameters
dataThe data to write
sizeThe number of bytes to write.
Return values
successThe buffer already had enough capacity, or could be grown without error. The data has been appended and the position has been advanced size bytes.
out_of_memoryAn out of memory condition occurred when allocating memory for the buffer. This object is unchanged.
exceeds_max_sizeThe required size would exceed the maximum specified by the Grow_calculator. This object is unchanged.

Friends And Related Function Documentation

◆ managed_buffer_sequence::unittest::Accessor

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
template<class T >
friend class managed_buffer_sequence::unittest::Accessor
friend

Open the class internals to any class named Accessor<T>, for some T.

This may be used by unit tests that need access to internals.

For example, if unittest SomeTest needs access to member int m, define the helper class:

template<> class Accessor<SomeTest> {
static int &m(Managed_buffer_sequence &rbs) { return rbs.m; }
};
}
Managed_buffer_sequence(const Grow_calculator_t &grow_calculator=Grow_calculator_t(), const Memory_resource_t &memory_resource=Memory_resource_t(), const Size_t default_buffer_count=16)
Construct a new, empty object.
Definition: managed_buffer_sequence.h:144
Definition: managed_buffer_sequence.h:53

Member Data Documentation

◆ m_buffers

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
Container_t mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::m_buffers
private

Container of buffers.

◆ m_char_allocator

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
Char_allocator_t mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::m_char_allocator
private

Allocator to allocate buffer data (characters).

◆ m_grow_calculator

template<class Char_tp = unsigned char, template< class Element_tp, class Allocator_tp > class Container_tp = std::vector>
Grow_calculator_t mysqlns::buffer::Managed_buffer_sequence< Char_tp, Container_tp >::m_grow_calculator
private

Determines how much memory to allocate when new memory is needed.


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