Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
PlatformHelpers.h
Go to the documentation of this file.
1
//--------------------------------------------------------------------------------------
2
// File: PlatformHelpers.h
3
//
4
// Copyright (c) Microsoft Corporation.
5
// Licensed under the MIT License.
6
//
7
// https://go.microsoft.com/fwlink/?LinkId=248929
8
// https://go.microsoft.com/fwlink/?LinkID=615561
9
//--------------------------------------------------------------------------------------
10
11
#pragma once
12
13
#ifdef _MSC_VER
14
#pragma warning(disable : 4324)
15
#endif
16
17
#include <cstdio>
18
#include <exception>
19
#include <memory>
20
#include <string>
21
22
#ifndef MAKEFOURCC
23
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
24
(static_cast<uint32_t>(static_cast<uint8_t>(ch0)) | (static_cast<uint32_t>(static_cast<uint8_t>(ch1)) << 8) \
25
| (static_cast<uint32_t>(static_cast<uint8_t>(ch2)) << 16) | (static_cast<uint32_t>(static_cast<uint8_t>(ch3)) << 24))
26
#endif
/* defined(MAKEFOURCC) */
27
28
// See https://walbourn.github.io/modern-c++-bitmask-types/
29
#ifndef ENUM_FLAGS_CONSTEXPR
30
#if defined(NTDDI_WIN10_RS1) && !defined(__MINGW32__)
31
#define ENUM_FLAGS_CONSTEXPR constexpr
32
#else
33
#define ENUM_FLAGS_CONSTEXPR const
34
#endif
35
#endif
36
37
namespace
DirectX
38
{
39
// Helper class for COM exceptions
40
class
com_exception
:
public
std::exception
41
{
42
public
:
43
explicit
com_exception
(
HRESULT
hr)
44
:
result
(hr)
45
{
46
char
str[64] = {};
47
sprintf_s(str,
"Failure with HRESULT of %08X"
,
static_cast<
unsigned
int
>
(
result
));
48
message
= str;
49
}
50
51
const
char
*
what
() const noexcept
override
{
return
message
.c_str(); }
52
53
HRESULT
get_result
() const noexcept {
return
result
; }
54
55
private
:
56
HRESULT
result
;
57
std::string
message
;
58
};
59
60
// Helper utility converts D3D API failures into exceptions.
61
inline
void
ThrowIfFailed
(
HRESULT
hr)
noexcept
(
false
)
62
{
63
if
(FAILED(hr))
64
{
65
throw
com_exception
(hr);
66
}
67
}
68
69
// Helper for output debug tracing
70
inline
void
DebugTrace
(_In_z_ _Printf_format_string_
const
char
* format, ...) noexcept
71
{
72
#ifdef _DEBUG
73
va_list args;
74
va_start(args, format);
75
76
char
buff[1024] = {};
77
vsprintf_s(buff, format, args);
78
OutputDebugStringA(buff);
79
va_end(args);
80
#else
81
UNREFERENCED_PARAMETER(format);
82
#endif
83
}
84
85
// Helper smart-pointers
86
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10) || (defined(_XBOX_ONE) && defined(_TITLE)) || !defined(WINAPI_FAMILY) \
87
|| (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
88
struct
virtual_deleter
89
{
90
void
operator()
(
void
* p)
noexcept
91
{
92
if
(p)
93
VirtualFree(p, 0, MEM_RELEASE);
94
}
95
};
96
#endif
97
98
struct
handle_closer
99
{
100
void
operator()
(HANDLE h)
noexcept
101
{
102
if
(h)
103
CloseHandle(h);
104
}
105
};
106
107
using
ScopedHandle
= std::unique_ptr<void, handle_closer>;
108
109
inline
HANDLE
safe_handle
(HANDLE h)
noexcept
110
{
111
return
(h == INVALID_HANDLE_VALUE) ? nullptr : h;
112
}
113
}
// namespace DirectX
HRESULT
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
DirectX::com_exception::result
HRESULT result
Definition
PlatformHelpers.h:56
DirectX::com_exception::what
const char * what() const noexcept override
Definition
PlatformHelpers.h:51
DirectX::com_exception::com_exception
com_exception(HRESULT hr)
Definition
PlatformHelpers.h:43
DirectX::com_exception::message
std::string message
Definition
PlatformHelpers.h:57
DirectX::com_exception::get_result
HRESULT get_result() const noexcept
Definition
PlatformHelpers.h:53
DirectX
Definition
DDS.h:24
DirectX::DebugTrace
void DebugTrace(_In_z_ _Printf_format_string_ const char *format,...) noexcept
Definition
PlatformHelpers.h:70
DirectX::safe_handle
HANDLE safe_handle(HANDLE h) noexcept
Definition
PlatformHelpers.h:109
DirectX::ScopedHandle
std::unique_ptr< void, handle_closer > ScopedHandle
Definition
PlatformHelpers.h:107
DirectX::ThrowIfFailed
void ThrowIfFailed(HRESULT hr) noexcept(false)
Definition
PlatformHelpers.h:61
DirectX::handle_closer
Definition
PlatformHelpers.h:99
DirectX::handle_closer::operator()
void operator()(HANDLE h) noexcept
Definition
PlatformHelpers.h:100
DirectX::virtual_deleter
Definition
PlatformHelpers.h:89
DirectX::virtual_deleter::operator()
void operator()(void *p) noexcept
Definition
PlatformHelpers.h:90
ThirdParty
DirectXTK
PlatformHelpers.h
Generated on
for Rise by
1.18.0