123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- #ifndef BOOST_MYSQL_DIAGNOSTICS_HPP
- #define BOOST_MYSQL_DIAGNOSTICS_HPP
- #include <boost/mysql/string_view.hpp>
- #include <boost/mysql/detail/access.hpp>
- #include <string>
- namespace boost {
- namespace mysql {
- class diagnostics
- {
- public:
-
- diagnostics() = default;
-
- string_view client_message() const noexcept
- {
- return impl_.is_server ? string_view() : string_view(impl_.msg);
- }
-
- string_view server_message() const noexcept
- {
- return impl_.is_server ? string_view(impl_.msg) : string_view();
- }
-
- void clear() noexcept
- {
- impl_.is_server = false;
- impl_.msg.clear();
- }
- private:
- #ifndef BOOST_MYSQL_DOXYGEN
- struct
- {
- bool is_server{};
- std::string msg;
- void assign_client(std::string from)
- {
- msg = std::move(from);
- is_server = false;
- }
- void assign_server(std::string from)
- {
- msg = std::move(from);
- is_server = true;
- }
- } impl_;
- friend bool operator==(const diagnostics& lhs, const diagnostics& rhs) noexcept;
- friend struct detail::access;
- #endif
- };
- inline bool operator==(const diagnostics& lhs, const diagnostics& rhs) noexcept
- {
- return lhs.impl_.is_server == rhs.impl_.is_server && lhs.impl_.msg == rhs.impl_.msg;
- }
- inline bool operator!=(const diagnostics& lhs, const diagnostics& rhs) noexcept { return !(lhs == rhs); }
- }
- }
- #endif
|