Debian Codegraph @

Source/Core/Common/HRWrap.h

raw symbols SCIP
1 // Copyright 2021 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <fmt/format.h>
7 #include <string>
8 #include <winerror.h>
9 #include <winrt/base.h>
10
11 #include "Common/CommonTypes.h"
12
13 namespace Common
14 {
15 std::string GetHResultMessage(HRESULT hr);
16
17 // Wrapper for HRESULT to be used with fmt. Note that we can't create a fmt::formatter directly
18 // for HRESULT as HRESULT is simply a typedef on long and not a distinct type.
19 struct HRWrap
20 {
21 constexpr explicit HRWrap(HRESULT hr) : m_hr(hr) {}
22 const HRESULT m_hr;
23 };
24 } // namespace Common
25
26 template <>
27 struct fmt::formatter<Common::HRWrap>
28 {
29 constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
30 template <typename FormatContext>
31 auto format(const Common::HRWrap& hr, FormatContext& ctx) const
32 {
33 return fmt::format_to(ctx.out(), "{} ({:#010x})", Common::GetHResultMessage(hr.m_hr),
34 static_cast<u32>(hr.m_hr));
35 }
36 };
37
38 template <>
39 struct fmt::formatter<winrt::hresult>
40 {
41 constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
42 template <typename FormatContext>
43 auto format(const winrt::hresult& hr, FormatContext& ctx) const
44 {
45 return fmt::format_to(ctx.out(), "{} ({:#010x})", Common::GetHResultMessage(hr), hr.value);
46 }
47 };