Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-06-30 08:21:30

0001 //
0002 // Copyright (c) 2019-2024 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_MYSQL_IMPL_FIELD_VIEW_IPP
0009 #define BOOST_MYSQL_IMPL_FIELD_VIEW_IPP
0010 
0011 #pragma once
0012 
0013 #include <boost/mysql/field_view.hpp>
0014 #include <boost/mysql/string_view.hpp>
0015 
0016 #include <boost/mysql/impl/internal/byte_to_hex.hpp>
0017 #include <boost/mysql/impl/internal/dt_to_string.hpp>
0018 
0019 #include <boost/assert.hpp>
0020 
0021 #include <cstddef>
0022 #include <ostream>
0023 
0024 namespace boost {
0025 namespace mysql {
0026 namespace detail {
0027 
0028 inline std::ostream& print_blob(std::ostream& os, blob_view value)
0029 {
0030     if (value.empty())
0031         return os << "{}";
0032 
0033     char buffer[16]{'0', 'x'};
0034 
0035     os << "{ ";
0036     for (std::size_t i = 0; i < value.size(); ++i)
0037     {
0038         // Separating comma
0039         if (i != 0)
0040             os << ", ";
0041 
0042         // Convert to hex
0043         byte_to_hex(value[i], buffer + 2);
0044 
0045         // Insert
0046         os << string_view(buffer, 4);
0047     }
0048     os << " }";
0049     return os;
0050 }
0051 
0052 inline std::ostream& print_time(std::ostream& os, const boost::mysql::time& value)
0053 {
0054     char buffer[64]{};
0055     std::size_t sz = detail::time_to_string(value, buffer);
0056     os << string_view(buffer, sz);
0057     return os;
0058 }
0059 
0060 }  // namespace detail
0061 }  // namespace mysql
0062 }  // namespace boost
0063 
0064 std::ostream& boost::mysql::operator<<(std::ostream& os, const field_view& value)
0065 {
0066     // Make operator<< work for detail::string_view_offset types
0067     if (value.impl_.is_string_offset() || value.impl_.is_blob_offset())
0068     {
0069         return os << "<sv_offset>";
0070     }
0071 
0072     switch (value.kind())
0073     {
0074     case field_kind::null: return os << "<NULL>";
0075     case field_kind::int64: return os << value.get_int64();
0076     case field_kind::uint64: return os << value.get_uint64();
0077     case field_kind::string: return os << value.get_string();
0078     case field_kind::blob: return detail::print_blob(os, value.get_blob());
0079     case field_kind::float_: return os << value.get_float();
0080     case field_kind::double_: return os << value.get_double();
0081     case field_kind::date: return os << value.get_date();
0082     case field_kind::datetime: return os << value.get_datetime();
0083     case field_kind::time: return detail::print_time(os, value.get_time());
0084     default: BOOST_ASSERT(false); return os;
0085     }
0086 }
0087 
0088 #endif