File indexing completed on 2025-12-16 09:58:19
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_MYSQL_DETAIL_TYPING_POS_MAP_HPP
0009 #define BOOST_MYSQL_DETAIL_TYPING_POS_MAP_HPP
0010
0011 #include <boost/mysql/field_view.hpp>
0012 #include <boost/mysql/metadata.hpp>
0013 #include <boost/mysql/metadata_collection_view.hpp>
0014 #include <boost/mysql/string_view.hpp>
0015
0016 #include <boost/assert.hpp>
0017 #include <boost/config.hpp>
0018 #include <boost/core/span.hpp>
0019
0020 #include <cstddef>
0021
0022 namespace boost {
0023 namespace mysql {
0024 namespace detail {
0025
0026
0027
0028 BOOST_INLINE_CONSTEXPR std::size_t pos_absent = static_cast<std::size_t>(-1);
0029 using name_table_t = boost::span<const string_view>;
0030
0031 inline bool has_field_names(name_table_t name_table) noexcept { return !name_table.empty(); }
0032
0033 inline void pos_map_reset(span<std::size_t> self) noexcept
0034 {
0035 for (std::size_t i = 0; i < self.size(); ++i)
0036 self.data()[i] = pos_absent;
0037 }
0038
0039 inline void pos_map_add_field(
0040 span<std::size_t> self,
0041 name_table_t name_table,
0042 std::size_t db_index,
0043 string_view field_name
0044 ) noexcept
0045 {
0046 if (has_field_names(name_table))
0047 {
0048 BOOST_ASSERT(self.size() == name_table.size());
0049
0050
0051
0052 auto it = std::find(name_table.begin(), name_table.end(), field_name);
0053 if (it != name_table.end())
0054 {
0055 std::size_t cpp_index = it - name_table.begin();
0056 self[cpp_index] = db_index;
0057 }
0058 }
0059 else
0060 {
0061
0062 if (db_index < self.size())
0063 {
0064 self[db_index] = db_index;
0065 }
0066 }
0067 }
0068
0069 inline field_view map_field_view(
0070 span<const std::size_t> self,
0071 std::size_t cpp_index,
0072 span<const field_view> array
0073 ) noexcept
0074 {
0075 BOOST_ASSERT(cpp_index < self.size());
0076 return array[self[cpp_index]];
0077 }
0078
0079 inline const metadata& map_metadata(
0080 span<const std::size_t> self,
0081 std::size_t cpp_index,
0082 metadata_collection_view meta
0083 ) noexcept
0084 {
0085 BOOST_ASSERT(cpp_index < self.size());
0086 return meta[self[cpp_index]];
0087 }
0088
0089 }
0090 }
0091 }
0092
0093 #endif