// // 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_IMPL_FIELD_VIEW_HPP #define BOOST_MYSQL_IMPL_FIELD_VIEW_HPP #pragma once #include #include #include #include #include #include namespace boost { namespace mysql { namespace detail { inline bool blobs_equal(blob_view b1, blob_view b2) { if (b1.size() != b2.size()) return false; return b1.empty() || std::memcmp(b1.data(), b2.data(), b2.size()) == 0; } } // namespace detail } // namespace mysql } // namespace boost BOOST_CXX14_CONSTEXPR inline boost::mysql::field_kind boost::mysql::field_view::kind() const noexcept { switch (impl_.ikind) { case internal_kind::null: return field_kind::null; case internal_kind::int64: return field_kind::int64; case internal_kind::uint64: return field_kind::uint64; case internal_kind::string: return field_kind::string; case internal_kind::blob: return field_kind::blob; case internal_kind::float_: return field_kind::float_; case internal_kind::double_: return field_kind::double_; case internal_kind::date: return field_kind::date; case internal_kind::datetime: return field_kind::datetime; case internal_kind::time: return field_kind::time; case internal_kind::field_ptr: return impl_.repr.field_ptr->kind(); // sv_offset values must be converted via offset_to_string_view before calling any other fn default: return field_kind::null; } } BOOST_CXX14_CONSTEXPR std::int64_t boost::mysql::field_view::as_int64() const { if (is_field_ptr()) return impl_.repr.field_ptr->as(); check_kind(internal_kind::int64); return impl_.repr.int64; } BOOST_CXX14_CONSTEXPR std::uint64_t boost::mysql::field_view::as_uint64() const { if (is_field_ptr()) return impl_.repr.field_ptr->as(); check_kind(internal_kind::uint64); return impl_.repr.uint64; } BOOST_CXX14_CONSTEXPR boost::mysql::string_view boost::mysql::field_view::as_string() const { if (is_field_ptr()) return impl_.repr.field_ptr->as(); check_kind(internal_kind::string); return impl_.repr.string; } BOOST_CXX14_CONSTEXPR boost::mysql::blob_view boost::mysql::field_view::as_blob() const { if (is_field_ptr()) return impl_.repr.field_ptr->as(); check_kind(internal_kind::blob); return impl_.repr.blob; } BOOST_CXX14_CONSTEXPR float boost::mysql::field_view::as_float() const { if (is_field_ptr()) return impl_.repr.field_ptr->as(); check_kind(internal_kind::float_); return impl_.repr.float_; } BOOST_CXX14_CONSTEXPR double boost::mysql::field_view::as_double() const { if (is_field_ptr()) return impl_.repr.field_ptr->as(); check_kind(internal_kind::double_); return impl_.repr.double_; } BOOST_CXX14_CONSTEXPR boost::mysql::date boost::mysql::field_view::as_date() const { if (is_field_ptr()) return impl_.repr.field_ptr->as(); check_kind(internal_kind::date); return impl_.repr.date_; } BOOST_CXX14_CONSTEXPR boost::mysql::datetime boost::mysql::field_view::as_datetime() const { if (is_field_ptr()) return impl_.repr.field_ptr->as(); check_kind(internal_kind::datetime); return impl_.repr.datetime_; } BOOST_CXX14_CONSTEXPR boost::mysql::time boost::mysql::field_view::as_time() const { if (is_field_ptr()) return impl_.repr.field_ptr->as