File indexing completed on 2025-01-18 09:42:42
0001
0002
0003
0004
0005
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
0015 #include <boost/mysql/detail/config.hpp>
0016
0017 #include <ostream>
0018
0019 namespace boost {
0020 namespace mysql {
0021 namespace detail {
0022
0023 BOOST_MYSQL_STATIC_OR_INLINE
0024 std::ostream& print_blob(std::ostream& os, blob_view value)
0025 {
0026 if (value.empty())
0027 return os << "{}";
0028
0029 char buffer[16]{};
0030
0031 os << "{ ";
0032 for (std::size_t i = 0; i < value.size(); ++i)
0033 {
0034 if (i != 0)
0035 os << ", ";
0036 unsigned byte = value[i];
0037 std::snprintf(buffer, sizeof(buffer), "0x%02x", byte);
0038 os << buffer;
0039 }
0040 os << " }";
0041 return os;
0042 }
0043
0044 BOOST_MYSQL_STATIC_OR_INLINE
0045 std::ostream& print_time(std::ostream& os, const boost::mysql::time& value)
0046 {
0047
0048 char buffer[64]{};
0049
0050 using namespace std::chrono;
0051 const char* sign = value < microseconds(0) ? "-" : "";
0052 auto num_micros = value % seconds(1);
0053 auto num_secs = duration_cast<seconds>(value % minutes(1) - num_micros);
0054 auto num_mins = duration_cast<minutes>(value % hours(1) - num_secs);
0055 auto num_hours = duration_cast<hours>(value - num_mins);
0056
0057 snprintf(
0058 buffer,
0059 sizeof(buffer),
0060 "%s%02d:%02u:%02u.%06u",
0061 sign,
0062 static_cast<int>(std::abs(num_hours.count())),
0063 static_cast<unsigned>(std::abs(num_mins.count())),
0064 static_cast<unsigned>(std::abs(num_secs.count())),
0065 static_cast<unsigned>(std::abs(num_micros.count()))
0066 );
0067
0068 os << buffer;
0069 return os;
0070 }
0071
0072 }
0073 }
0074 }
0075
0076 std::ostream& boost::mysql::operator<<(std::ostream& os, const field_view& value)
0077 {
0078
0079 if (value.impl_.is_string_offset() || value.impl_.is_blob_offset())
0080 {
0081 return os << "<sv_offset>";
0082 }
0083
0084 switch (value.kind())
0085 {
0086 case field_kind::null: return os << "<NULL>";
0087 case field_kind::int64: return os << value.get_int64();
0088 case field_kind::uint64: return os << value.get_uint64();
0089 case field_kind::string: return os << value.get_string();
0090 case field_kind::blob: return detail::print_blob(os, value.get_blob());
0091 case field_kind::float_: return os << value.get_float();
0092 case field_kind::double_: return os << value.get_double();
0093 case field_kind::date: return os << value.get_date();
0094 case field_kind::datetime: return os << value.get_datetime();
0095 case field_kind::time: return detail::print_time(os, value.get_time());
0096 default: BOOST_ASSERT(false); return os;
0097 }
0098 }
0099
0100 #endif