// // 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_FIELD_IMPL_HPP #define BOOST_MYSQL_DETAIL_FIELD_IMPL_HPP #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace mysql { namespace detail { // Breaks a circular dependency between field_view and field struct field_impl { using null_t = boost::variant2::monostate; using variant_type = boost::variant2::variant< null_t, // Any of the below when the value is NULL std::int64_t, // signed TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT std::uint64_t, // unsigned TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT, YEAR, BIT std::string, // CHAR, VARCHAR, TEXT (all sizes), , ENUM, // SET, DECIMAL blob, // BINARY, VARBINARY, BLOB (all sizes), GEOMETRY float, // FLOAT double, // DOUBLE date, // DATE datetime, // DATETIME, TIMESTAMP time // TIME >; variant_type data; field_impl() = default; template field_impl(Args&&... args) noexcept(std::is_nothrow_constructible::value) : data(std::forward(args)...) { } field_kind kind() const noexcept { return static_cast(data.index()); } template const T& as() const { const T* res = boost::variant2::get_if(&data); if (!res) BOOST_THROW_EXCEPTION(bad_field_access()); return *res; } template T& as() { T* res = boost::variant2::get_if(&data); if (!res) BOOST_THROW_EXCEPTION(bad_field_access()); return *res; } template const T& get() const noexcept { constexpr auto I = mp11::mp_find::value; return boost::variant2::unsafe_get(data); } template T& get() noexcept { constexpr auto I = mp11::mp_find::value; return boost::variant2::unsafe_get(data); } }; } // namespace detail } // namespace mysql } // namespace boost #endif