mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Common: Create HRWrap
HRWrap now allows HRESULT to be formatted, giving useful information beyond "it failed" or a hex code that isn't obvious to most users. This commit does not add any uses of it, though.
This commit is contained in:
33
Source/Core/Common/HRWrap.h
Normal file
33
Source/Core/Common/HRWrap.h
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright 2021 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <string>
|
||||
#include <winerror.h>
|
||||
|
||||
namespace Common
|
||||
{
|
||||
std::string GetHResultMessage(HRESULT hr);
|
||||
|
||||
// Wrapper for HRESULT to be used with fmt. Note that we can't create a fmt::formatter directly
|
||||
// for HRESULT as HRESULT is simply a typedef on long and not a distinct type.
|
||||
struct HRWrap
|
||||
{
|
||||
constexpr explicit HRWrap(HRESULT hr) : m_hr(hr) {}
|
||||
const HRESULT m_hr;
|
||||
};
|
||||
} // namespace Common
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<Common::HRWrap>
|
||||
{
|
||||
constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
|
||||
template <typename FormatContext>
|
||||
auto format(const Common::HRWrap& hr, FormatContext& ctx)
|
||||
{
|
||||
return fmt::format_to(ctx.out(), "{} ({:#010x})", Common::GetHResultMessage(hr.m_hr),
|
||||
static_cast<u32>(hr.m_hr));
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user