Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:58:20

0001 //
0002 // Copyright (c) 2019-2025 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_MYSQL_DETAIL_ROW_IMPL_HPP
0009 #define BOOST_MYSQL_DETAIL_ROW_IMPL_HPP
0010 
0011 #include <boost/mysql/field_view.hpp>
0012 
0013 #include <boost/mysql/detail/config.hpp>
0014 
0015 #include <boost/core/span.hpp>
0016 
0017 #include <cstddef>
0018 #include <vector>
0019 
0020 namespace boost {
0021 namespace mysql {
0022 namespace detail {
0023 
0024 // Adds num_fields default-constructed fields to the vector, return pointer to the first
0025 // allocated value. Used to allocate fields before deserialization
0026 inline span<field_view> add_fields(std::vector<field_view>& storage, std::size_t num_fields)
0027 {
0028     std::size_t old_size = storage.size();
0029     storage.resize(old_size + num_fields);
0030     return span<field_view>(storage.data() + old_size, num_fields);
0031 }
0032 
0033 // A field_view vector with strings pointing into a
0034 // single character buffer. Used to implement owning row types
0035 class row_impl
0036 {
0037 public:
0038     row_impl() = default;
0039 
0040     BOOST_MYSQL_DECL
0041     row_impl(const row_impl&);
0042 
0043     row_impl(row_impl&&) = default;
0044 
0045     BOOST_MYSQL_DECL
0046     row_impl& operator=(const row_impl&);
0047 
0048     row_impl& operator=(row_impl&&) = default;
0049 
0050     ~row_impl() = default;
0051 
0052     // Copies the given span into *this
0053     BOOST_MYSQL_DECL
0054     row_impl(const field_view* fields, std::size_t size);
0055 
0056     // Copies the given span into *this, used by row/rows in assignment from view
0057     BOOST_MYSQL_DECL
0058     void assign(const field_view* fields, std::size_t size);
0059 
0060     // Adds new default constructed fields to provide storage to deserialization
0061     span<field_view> add_fields(std::size_t num_fields)
0062     {
0063         return ::boost::mysql::detail::add_fields(fields_, num_fields);
0064     }
0065 
0066     // Saves strings in the [first, first+num_fields) range into the string buffer, used by execute
0067     BOOST_MYSQL_DECL
0068     void copy_strings_as_offsets(std::size_t first, std::size_t num_fields);
0069 
0070     // Restores any offsets into string views, used by execute
0071     BOOST_MYSQL_DECL
0072     void offsets_to_string_views();
0073 
0074     const std::vector<field_view>& fields() const noexcept { return fields_; }
0075 
0076     void clear() noexcept
0077     {
0078         fields_.clear();
0079         string_buffer_.clear();
0080     }
0081 
0082 private:
0083     std::vector<field_view> fields_;
0084     std::vector<unsigned char> string_buffer_;
0085 };
0086 
0087 }  // namespace detail
0088 }  // namespace mysql
0089 }  // namespace boost
0090 
0091 #ifdef BOOST_MYSQL_HEADER_ONLY
0092 #include <boost/mysql/impl/row_impl.ipp>
0093 #endif
0094 
0095 #endif