Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
Ed Tanous | 95c6307 | 2024-03-26 13:19:52 -0700 | [diff] [blame] | 3 | #pragma once |
| 4 | |
| 5 | #include <boost/system/error_code.hpp> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 6 | #include <boost/url/grammar/string_view_base.hpp> |
Ed Tanous | 95c6307 | 2024-03-26 13:19:52 -0700 | [diff] [blame] | 7 | #include <boost/url/url_view_base.hpp> |
| 8 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 9 | #include <concepts> |
Ed Tanous | 95c6307 | 2024-03-26 13:19:52 -0700 | [diff] [blame] | 10 | #include <format> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 11 | #include <string_view> |
Ed Tanous | 95c6307 | 2024-03-26 13:19:52 -0700 | [diff] [blame] | 12 | |
| 13 | // NOLINTBEGIN(readability-convert-member-functions-to-static, cert-dcl58-cpp) |
| 14 | template <std::derived_from<boost::system::error_code> ErrorCodeType> |
| 15 | struct std::formatter<ErrorCodeType> |
| 16 | { |
| 17 | constexpr auto parse(std::format_parse_context& ctx) |
| 18 | { |
| 19 | return ctx.begin(); |
| 20 | } |
| 21 | |
| 22 | auto format(const ErrorCodeType& ec, auto& ctx) const |
| 23 | { |
| 24 | return std::format_to(ctx.out(), "{}", ec.what()); |
| 25 | } |
| 26 | }; |
| 27 | |
| 28 | template <std::derived_from<boost::urls::grammar::string_view_base> StringView> |
| 29 | struct std::formatter<StringView> |
| 30 | { |
| 31 | constexpr auto parse(std::format_parse_context& ctx) |
| 32 | { |
| 33 | return ctx.begin(); |
| 34 | } |
| 35 | auto format(const StringView& msg, auto& ctx) const |
| 36 | { |
| 37 | return std::format_to(ctx.out(), "{}", |
| 38 | std::string_view(msg.data(), msg.size())); |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | template <std::derived_from<boost::urls::url_view_base> UrlBase> |
| 43 | struct std::formatter<UrlBase> |
| 44 | { |
| 45 | constexpr auto parse(std::format_parse_context& ctx) |
| 46 | { |
| 47 | return ctx.begin(); |
| 48 | } |
| 49 | auto format(const UrlBase& msg, auto& ctx) const |
| 50 | { |
| 51 | return std::format_to(ctx.out(), "{}", std::string_view(msg.buffer())); |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | template <std::derived_from<boost::core::string_view> StringView> |
| 56 | struct std::formatter<StringView> |
| 57 | { |
| 58 | constexpr auto parse(std::format_parse_context& ctx) |
| 59 | { |
| 60 | return ctx.begin(); |
| 61 | } |
| 62 | auto format(const StringView& msg, auto& ctx) const |
| 63 | { |
| 64 | return std::format_to(ctx.out(), "{}", std::string_view(msg)); |
| 65 | } |
| 66 | }; |
| 67 | // NOLINTEND(readability-convert-member-functions-to-static, cert-dcl58-cpp) |