From a8f05a7efc5a0fc2b809ee609b122d768b1a36db Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 19 May 2021 17:43:43 +0200 Subject: [PATCH] win32/HResult: un-inline HRESULTToString() to reduce header dependencies --- src/win32/HResult.cxx | 39 +++++++++++++++++++++++++++++++++++++++ src/win32/HResult.hxx | 39 ++++----------------------------------- 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/src/win32/HResult.cxx b/src/win32/HResult.cxx index 0daa80163..89cca898b 100644 --- a/src/win32/HResult.cxx +++ b/src/win32/HResult.cxx @@ -25,6 +25,45 @@ #include #include +#include + +std::string_view +HRESULTToString(HRESULT result) noexcept +{ + using namespace std::literals; + switch (result) { +#define C(x) \ +case x: \ + return #x##sv + C(AUDCLNT_E_ALREADY_INITIALIZED); + C(AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL); + C(AUDCLNT_E_BUFFER_ERROR); + C(AUDCLNT_E_BUFFER_OPERATION_PENDING); + C(AUDCLNT_E_BUFFER_SIZE_ERROR); + C(AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED); + C(AUDCLNT_E_BUFFER_TOO_LARGE); + C(AUDCLNT_E_CPUUSAGE_EXCEEDED); + C(AUDCLNT_E_DEVICE_INVALIDATED); + C(AUDCLNT_E_DEVICE_IN_USE); + C(AUDCLNT_E_ENDPOINT_CREATE_FAILED); + C(AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED); + C(AUDCLNT_E_INVALID_DEVICE_PERIOD); + C(AUDCLNT_E_OUT_OF_ORDER); + C(AUDCLNT_E_SERVICE_NOT_RUNNING); + C(AUDCLNT_E_UNSUPPORTED_FORMAT); + C(AUDCLNT_E_WRONG_ENDPOINT_TYPE); + C(AUDCLNT_E_NOT_INITIALIZED); + C(AUDCLNT_E_NOT_STOPPED); + C(CO_E_NOTINITIALIZED); + C(E_INVALIDARG); + C(E_OUTOFMEMORY); + C(E_POINTER); + C(NO_ERROR); +#undef C + } + return std::string_view(); +} + std::string HResultCategory::message(int Errcode) const { diff --git a/src/win32/HResult.hxx b/src/win32/HResult.hxx index 9bf612727..5ed92732c 100644 --- a/src/win32/HResult.hxx +++ b/src/win32/HResult.hxx @@ -25,42 +25,11 @@ #include #include -#include +#include -constexpr std::string_view HRESULTToString(HRESULT result) { - using namespace std::literals; - switch (result) { -#define C(x) \ -case x: \ - return #x##sv - C(AUDCLNT_E_ALREADY_INITIALIZED); - C(AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL); - C(AUDCLNT_E_BUFFER_ERROR); - C(AUDCLNT_E_BUFFER_OPERATION_PENDING); - C(AUDCLNT_E_BUFFER_SIZE_ERROR); - C(AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED); - C(AUDCLNT_E_BUFFER_TOO_LARGE); - C(AUDCLNT_E_CPUUSAGE_EXCEEDED); - C(AUDCLNT_E_DEVICE_INVALIDATED); - C(AUDCLNT_E_DEVICE_IN_USE); - C(AUDCLNT_E_ENDPOINT_CREATE_FAILED); - C(AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED); - C(AUDCLNT_E_INVALID_DEVICE_PERIOD); - C(AUDCLNT_E_OUT_OF_ORDER); - C(AUDCLNT_E_SERVICE_NOT_RUNNING); - C(AUDCLNT_E_UNSUPPORTED_FORMAT); - C(AUDCLNT_E_WRONG_ENDPOINT_TYPE); - C(AUDCLNT_E_NOT_INITIALIZED); - C(AUDCLNT_E_NOT_STOPPED); - C(CO_E_NOTINITIALIZED); - C(E_INVALIDARG); - C(E_OUTOFMEMORY); - C(E_POINTER); - C(NO_ERROR); -#undef C - } - return std::string_view(); -} +gcc_const +std::string_view +HRESULTToString(HRESULT result) noexcept; static inline const std::error_category &hresult_category() noexcept; class HResultCategory : public std::error_category {