29#ifndef MYSQL_CONTAINERS_BUFFERS_BUFFER_VIEW_H
30#define MYSQL_CONTAINERS_BUFFERS_BUFFER_VIEW_H
49template <
class Char_tp =
unsigned char>
61 if (
data ==
nullptr) assert(
size == 0);
115 template <
class Str_char_t = char,
116 class Str_traits_t = std::char_traits<Str_char_t>,
117 class Str_allocator_t = std::allocator<Str_char_t>>
118 std::basic_string<Str_char_t, Str_traits_t, Str_allocator_t>
str(
119 const Str_allocator_t &allocator = Str_allocator_t())
const {
120 return std::basic_string<Str_char_t, Str_traits_t, Str_allocator_t>(
121 reinterpret_cast<const Str_char_t *
>(
m_data),
m_size, allocator);
128 std::string
debug_string([[maybe_unused]]
bool show_contents =
false)
const {
134 ss <<
"Buffer_view(ptr=" << (
const void *)
this
135 <<
", data=" << (
const void *)
data()
136 <<
", size=" <<
size();
138 if (show_contents &&
begin() !=
nullptr)
139 ss <<
", contents=\""
140 << std::string(
reinterpret_cast<const char *
>(
begin()),
size())
Non-owning view of a memory buffer with a fixed size.
Definition: buffer_view.h:50
std::size_t Size_t
The 'size' type.
Definition: buffer_view.h:55
Char_t * data()
Return non-const pointer to the data.
Definition: buffer_view.h:91
Char_t * m_data
Pointer to the data.
Definition: buffer_view.h:149
Char_t * Iterator_t
Definition: buffer_view.h:56
Const_iterator_t begin() const
Return pointer to the first character of the data.
Definition: buffer_view.h:100
Const_iterator_t cbegin() const
Return const pointer to the first character of the data.
Definition: buffer_view.h:106
const Char_t * Const_iterator_t
Definition: buffer_view.h:57
Const_iterator_t cend() const
Return const pointer to one-past-the-last character of the data.
Definition: buffer_view.h:109
Size_t m_size
The number of bytes.
Definition: buffer_view.h:152
Const_iterator_t end() const
Return pointer to one-past-the-last character of the data.
Definition: buffer_view.h:103
Buffer_view()=default
Create a new "null Buffer_view": pointer is nullptr and size is 0.
Buffer_view(const Buffer_view &)=default
Shallow copy constructor.
std::string debug_string(bool show_contents=false) const
In debug mode, return a string with debug info.
Definition: buffer_view.h:128
const Char_t * data() const
Return const pointer to the data.
Definition: buffer_view.h:88
Size_t size() const
Return the number of bytes.
Definition: buffer_view.h:112
Iterator_t begin()
Return pointer to the first character of the data.
Definition: buffer_view.h:94
Iterator_t end()
Return pointer to one-past-the-last character of the data.
Definition: buffer_view.h:97
Buffer_view(Char_t *data, Size_t size)
Create a new Buffer_view with the specified size and data.
Definition: buffer_view.h:60
std::basic_string< Str_char_t, Str_traits_t, Str_allocator_t > str(const Str_allocator_t &allocator=Str_allocator_t()) const
Return a copy of this object as a std::string.
Definition: buffer_view.h:118
Char_tp Char_t
Definition: buffer_view.h:52
Buffer_view(Buffer_view &&) noexcept=default
Default move constructor.
Definition: buffer_sequence_view.h:51
std::basic_ostringstream< char, std::char_traits< char >, ut::allocator< char > > ostringstream
Specialization of basic_ostringstream which uses ut::allocator.
Definition: ut0new.h:2872