File indexing completed on 2025-04-09 08:28:01
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_MYSQL_DETAIL_OUTPUT_STRING_HPP
0009 #define BOOST_MYSQL_DETAIL_OUTPUT_STRING_HPP
0010
0011 #include <boost/mysql/string_view.hpp>
0012
0013 #include <boost/mysql/detail/config.hpp>
0014
0015 #include <cstddef>
0016
0017 #ifdef BOOST_MYSQL_HAS_CONCEPTS
0018 #include <concepts>
0019 #endif
0020
0021 namespace boost {
0022 namespace mysql {
0023 namespace detail {
0024
0025 #ifdef BOOST_MYSQL_HAS_CONCEPTS
0026
0027 template <class T>
0028 concept output_string = std::movable<T> && requires(T& t, const char* data, std::size_t sz) {
0029 t.append(data, sz);
0030 t.clear();
0031 };
0032
0033 #define BOOST_MYSQL_OUTPUT_STRING ::boost::mysql::detail::output_string
0034
0035 #else
0036
0037 #define BOOST_MYSQL_OUTPUT_STRING class
0038
0039 #endif
0040
0041 class output_string_ref
0042 {
0043 using append_fn_t = void (*)(void*, const char*, std::size_t);
0044
0045 append_fn_t append_fn_;
0046 void* container_;
0047
0048 template <class T>
0049 static void do_append(void* container, const char* data, std::size_t size)
0050 {
0051 static_cast<T*>(container)->append(data, size);
0052 }
0053
0054 public:
0055 output_string_ref(append_fn_t append_fn, void* container) noexcept
0056 : append_fn_(append_fn), container_(container)
0057 {
0058 }
0059
0060 template <class T>
0061 static output_string_ref create(T& obj) noexcept
0062 {
0063 return output_string_ref(&do_append<T>, &obj);
0064 }
0065
0066 void append(string_view data)
0067 {
0068 if (data.size() > 0u)
0069 append_fn_(container_, data.data(), data.size());
0070 }
0071 };
0072
0073 }
0074 }
0075 }
0076
0077 #endif