// // Copyright (c) 2019-2024 Ruben Perez Hidalgo (rubenperez038 at gmail dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_MYSQL_DETAIL_ROW_IMPL_HPP #define BOOST_MYSQL_DETAIL_ROW_IMPL_HPP #include #include #include #include #include namespace boost { namespace mysql { namespace detail { // Adds num_fields default-constructed fields to the vector, return pointer to the first // allocated value. Used to allocate fields before deserialization inline span add_fields(std::vector& storage, std::size_t num_fields) { std::size_t old_size = storage.size(); storage.resize(old_size + num_fields); return span(storage.data() + old_size, num_fields); } // A field_view vector with strings pointing into a // single character buffer. Used to implement owning row types class row_impl { public: row_impl() = default; BOOST_MYSQL_DECL row_impl(const row_impl&); row_impl(row_impl&&) = default; BOOST_MYSQL_DECL row_impl& operator=(const row_impl&); row_impl& operator=(row_impl&&) = default; ~row_impl() = default; // Copies the given span into *this BOOST_MYSQL_DECL row_impl(const field_view* fields, std::size_t size); // Copies the given span into *this, used by row/rows in assignment from view BOOST_MYSQL_DECL void assign(const field_view* fields, std::size_t size); // Adds new default constructed fields to provide storage to deserialization span add_fields(std::size_t num_fields) { return ::boost::mysql::detail::add_fields(fields_, num_fields); } // Saves strings in the [first, first+num_fields) range into the string buffer, used by execute BOOST_MYSQL_DECL void copy_strings_as_offsets(std::size_t first, std::size_t num_fields); // Restores any offsets into string views, used by execute BOOST_MYSQL_DECL void offsets_to_string_views(); const std::vector& fields() const noexcept { return fields_; } void clear() noexcept { fields_.clear(); string_buffer_.clear(); } private: std::vector fields_; std::vector string_buffer_; }; } // namespace detail } // namespace mysql } // namespace boost #ifdef BOOST_MYSQL_HEADER_ONLY #include #endif #endif