blob: bf8397faa6d4d4abc4370da73a7fc45c7157e1fb [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Ed Tanous95c63072024-03-26 13:19:52 -07003#pragma once
4
5#include <boost/system/error_code.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -08006#include <boost/url/grammar/string_view_base.hpp>
Ed Tanous95c63072024-03-26 13:19:52 -07007#include <boost/url/url_view_base.hpp>
8
Ed Tanousd7857202025-01-28 15:32:26 -08009#include <concepts>
Ed Tanous95c63072024-03-26 13:19:52 -070010#include <format>
Ed Tanousd7857202025-01-28 15:32:26 -080011#include <string_view>
Ed Tanous95c63072024-03-26 13:19:52 -070012
13// NOLINTBEGIN(readability-convert-member-functions-to-static, cert-dcl58-cpp)
14template <std::derived_from<boost::system::error_code> ErrorCodeType>
15struct 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
28template <std::derived_from<boost::urls::grammar::string_view_base> StringView>
29struct 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
42template <std::derived_from<boost::urls::url_view_base> UrlBase>
43struct 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
55template <std::derived_from<boost::core::string_view> StringView>
56struct 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)