#ifndef QUERY_VALUE_HPP #define QUERY_VALUE_HPP #include "matador/utils/basic_type_converter.hpp" #include "matador/utils/default_type_traits.hpp" #include "matador/utils/types.hpp" #include namespace matador::utils { namespace detail { template size_t determine_size(const Type &/*val*/) { return 0; } size_t determine_size(const std::string &val); size_t determine_size(const char *val); size_t determine_size(const blob &val); } class value { public: value() = default; template explicit value(Type value, size_t size = 0) : value_(value) , size_(size) , type_(data_type_traits::type(size)) {} explicit value(basic_type data_type, size_t size = 0); value(const value &x) = default; value& operator=(const value &x) = default; template value& operator=(Type val) { value_ = val; size_ = detail::determine_size(val); type_ = data_type_traits::type(size_); return *this; } value(value &&x) noexcept; value& operator=(value &&x) noexcept; template std::optional as() const { if (std::holds_alternative(value_)) { return std::get(value_); } const auto res = basic_type_converter::convert_value(value_); if (!res.is_ok()) { return std::nullopt; } return *res; } template std::optional> ref() { if (std::holds_alternative(value_)) { return std::get(value_); } return std::nullopt; } [[nodiscard]] std::string str() const; [[nodiscard]] size_t size() const; [[nodiscard]] basic_type type() const; [[nodiscard]] bool is_integer() const; [[nodiscard]] bool is_floating_point() const; [[nodiscard]] bool is_bool() const; [[nodiscard]] bool is_string() const; [[nodiscard]] bool is_varchar() const; [[nodiscard]] bool is_date() const; [[nodiscard]] bool is_time() const; [[nodiscard]] bool is_blob() const; [[nodiscard]] bool is_null() const; private: utils::database_type value_; size_t size_{}; basic_type type_{basic_type::type_null}; }; } #endif //QUERY_VALUE_HPP