blob: 856369871e9ebe15cebbfe09481ca07b6a0d7313 [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>
6#include <boost/url/grammar.hpp>
7#include <boost/url/url_view_base.hpp>
8
9#include <format>
10
11// NOLINTBEGIN(readability-convert-member-functions-to-static, cert-dcl58-cpp)
12template <std::derived_from<boost::system::error_code> ErrorCodeType>
13struct std::formatter<ErrorCodeType>
14{
15 constexpr auto parse(std::format_parse_context& ctx)
16 {
17 return ctx.begin();
18 }
19
20 auto format(const ErrorCodeType& ec, auto& ctx) const
21 {
22 return std::format_to(ctx.out(), "{}", ec.what());
23 }
24};
25
26template <std::derived_from<boost::urls::grammar::string_view_base> StringView>
27struct std::formatter<StringView>
28{
29 constexpr auto parse(std::format_parse_context& ctx)
30 {
31 return ctx.begin();
32 }
33 auto format(const StringView& msg, auto& ctx) const
34 {
35 return std::format_to(ctx.out(), "{}",
36 std::string_view(msg.data(), msg.size()));
37 }
38};
39
40template <std::derived_from<boost::urls::url_view_base> UrlBase>
41struct std::formatter<UrlBase>
42{
43 constexpr auto parse(std::format_parse_context& ctx)
44 {
45 return ctx.begin();
46 }
47 auto format(const UrlBase& msg, auto& ctx) const
48 {
49 return std::format_to(ctx.out(), "{}", std::string_view(msg.buffer()));
50 }
51};
52
53template <std::derived_from<boost::core::string_view> StringView>
54struct std::formatter<StringView>
55{
56 constexpr auto parse(std::format_parse_context& ctx)
57 {
58 return ctx.begin();
59 }
60 auto format(const StringView& msg, auto& ctx) const
61 {
62 return std::format_to(ctx.out(), "{}", std::string_view(msg));
63 }
64};
65// NOLINTEND(readability-convert-member-functions-to-static, cert-dcl58-cpp)