reflow/respace
This commit is contained in:
parent
7b6f3ea9f6
commit
332216e63c
|
@ -55,25 +55,33 @@ namespace impl
|
||||||
std::optional<hresult> get_if_hresult_error(std::exception_ptr) noexcept;
|
std::optional<hresult> get_if_hresult_error(std::exception_ptr) noexcept;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename OStream, typename T, std::enable_if_t<!std::is_enum_v<T>,int> = 0>
|
template<typename OStream, typename T,
|
||||||
inline auto &describe_argument(OStream &s, const T &a) { return s << a; }
|
std::enable_if_t<!std::is_enum_v<T>,int> = 0>
|
||||||
template<typename OStream, typename T, std::enable_if_t< std::is_enum_v<T>,int> = 0>
|
inline auto &describe_argument(OStream &s, const T &a)
|
||||||
inline auto &describe_argument(OStream &s, const T &a) { return s << static_cast<std::underlying_type_t<T>>(a); }
|
{ return s << a; }
|
||||||
|
template<typename OStream, typename T,
|
||||||
|
std::enable_if_t< std::is_enum_v<T>,int> = 0>
|
||||||
|
inline auto &describe_argument(OStream &s, const T &a)
|
||||||
|
{ return s << static_cast<std::underlying_type_t<T>>(a); }
|
||||||
|
|
||||||
template<typename OStream>
|
template<typename OStream>
|
||||||
inline auto &describe_argument(OStream &s, std::string_view const a) { return s << std::quoted(a); }
|
inline auto &describe_argument(OStream &s, std::string_view const a)
|
||||||
|
{ return s << std::quoted(a); }
|
||||||
template<typename OStream>
|
template<typename OStream>
|
||||||
inline auto &describe_argument(OStream &s, const std::string & a) { return s << std::quoted(a); }
|
inline auto &describe_argument(OStream &s, const std::string & a)
|
||||||
|
{ return s << std::quoted(a); }
|
||||||
template<typename OStream>
|
template<typename OStream>
|
||||||
inline auto &describe_argument(OStream &s, const char * const a) { return s << std::quoted(a); }
|
inline auto &describe_argument(OStream &s, const char * const a)
|
||||||
|
{ return s << std::quoted(a); }
|
||||||
// TODO: overload for const GString *
|
// TODO: overload for const GString *
|
||||||
|
|
||||||
|
// not implemented (TODO maybe):
|
||||||
template<typename OStream>
|
template<typename OStream>
|
||||||
inline auto &describe_argument(OStream &s, std::wstring_view const a) = delete; // not implemented
|
inline auto &describe_argument(OStream &s, std::wstring_view const a) = delete;
|
||||||
template<typename OStream>
|
template<typename OStream>
|
||||||
inline auto &describe_argument(OStream &s, const std::wstring & a) = delete; // not implemented
|
inline auto &describe_argument(OStream &s, const std::wstring & a) = delete;
|
||||||
template<typename OStream>
|
template<typename OStream>
|
||||||
inline auto &describe_argument(OStream &s, const wchar_t * const a) = delete; // not implemented
|
inline auto &describe_argument(OStream &s, const wchar_t * const a) = delete;
|
||||||
// TODO: handle wide strings maybe
|
|
||||||
|
|
||||||
inline impl::varstring describe_arguments() noexcept { return {""}; }
|
inline impl::varstring describe_arguments() noexcept { return {""}; }
|
||||||
|
|
||||||
|
@ -94,13 +102,15 @@ catch (...)
|
||||||
|
|
||||||
#define FORMAT "%s(%s) failed: %s"
|
#define FORMAT "%s(%s) failed: %s"
|
||||||
template<typename... Arg>
|
template<typename... Arg>
|
||||||
inline void log_invocation_failure(const char *e, const char *func_name, const Arg &... a) noexcept
|
inline void log_invocation_failure(const char *e,
|
||||||
|
const char *func_name, const Arg &... a) noexcept
|
||||||
{
|
{
|
||||||
const auto args = describe_arguments(a...);
|
const auto args = describe_arguments(a...);
|
||||||
g_warning(FORMAT, func_name, args.c_str(), e);
|
g_warning(FORMAT, func_name, args.c_str(), e);
|
||||||
}
|
}
|
||||||
template<typename... Arg>
|
template<typename... Arg>
|
||||||
inline void log_invocation_failure_desc(const char* e, const char* e_desc, const char* func_name, const Arg&... a) noexcept
|
inline void log_invocation_failure_desc(const char *e, const char *e_desc,
|
||||||
|
const char *func_name, const Arg &... a) noexcept
|
||||||
{
|
{
|
||||||
const auto args = describe_arguments(a...);
|
const auto args = describe_arguments(a...);
|
||||||
g_warning(FORMAT": %s", func_name, args.c_str(), e, e_desc);
|
g_warning(FORMAT": %s", func_name, args.c_str(), e, e_desc);
|
||||||
|
@ -112,7 +122,8 @@ struct regular_void {};
|
||||||
template<typename Invokable, typename... Arg>
|
template<typename Invokable, typename... Arg>
|
||||||
inline auto invoke(Invokable &&i, const Arg &... a)
|
inline auto invoke(Invokable &&i, const Arg &... a)
|
||||||
{
|
{
|
||||||
if constexpr (std::is_void_v<decltype(std::invoke(std::forward<Invokable>(i), a...))>)
|
using R = decltype(std::invoke(std::forward<Invokable>(i), a...));
|
||||||
|
if constexpr (std::is_void_v<R>)
|
||||||
{
|
{
|
||||||
std::invoke(std::forward<Invokable>(i), a...);
|
std::invoke(std::forward<Invokable>(i), a...);
|
||||||
return regular_void{};
|
return regular_void{};
|
||||||
|
@ -122,7 +133,8 @@ inline auto invoke(Invokable &&i, const Arg &... a)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Invokable, typename... Arg>
|
template<typename Invokable, typename... Arg>
|
||||||
inline auto try_invoke(const char *func_name, Invokable &&i, const Arg &... a) noexcept
|
inline auto try_invoke(
|
||||||
|
const char *func_name, Invokable &&i, const Arg &... a) noexcept
|
||||||
-> std::optional<decltype(invoke(std::forward<Invokable>(i), a...))>
|
-> std::optional<decltype(invoke(std::forward<Invokable>(i), a...))>
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -139,7 +151,8 @@ catch (...)
|
||||||
{
|
{
|
||||||
auto hr = make_array("hresult 0x01234567\0");
|
auto hr = make_array("hresult 0x01234567\0");
|
||||||
hexify32(static_cast<std::uint32_t>(e->code), std::end(hr)-1);
|
hexify32(static_cast<std::uint32_t>(e->code), std::end(hr)-1);
|
||||||
log_invocation_failure_desc(std::begin(hr), e->message.c_str(), func_name, a...);
|
log_invocation_failure_desc(
|
||||||
|
std::begin(hr), e->message.c_str(), func_name, a...);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
log_invocation_failure("unknown error", func_name, a...);
|
log_invocation_failure("unknown error", func_name, a...);
|
||||||
|
@ -150,7 +163,10 @@ catch (...)
|
||||||
} // namespace glib
|
} // namespace glib
|
||||||
|
|
||||||
|
|
||||||
#define g_try_invoke(invokable, ...) glib::try_invoke(#invokable, invokable, __VA_ARGS__)
|
#define g_try_invoke(invokable, ...) \
|
||||||
#define g_try_invoke0(invokable) glib::try_invoke(#invokable, invokable)
|
glib::try_invoke(#invokable, invokable, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define g_try_invoke0(invokable) \
|
||||||
|
glib::try_invoke(#invokable, invokable)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define WINRT_TYPE_WINDOWS_UI_NOTIFICATIONS_TOAST_DISMISSAL_REASON (winrtWindowsUINotificationsToastDismissalReason_get_type ())
|
#define WINRT_TYPE_WINDOWS_UI_NOTIFICATIONS_TOAST_DISMISSAL_REASON \
|
||||||
|
(winrtWindowsUINotificationsToastDismissalReason_get_type())
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* winrt_Windows_UI_Notifications_Toast_Dismissal_Reason:
|
* winrt_Windows_UI_Notifications_Toast_Dismissal_Reason:
|
||||||
|
@ -23,9 +24,10 @@ typedef enum {
|
||||||
WINRT_WINDOWS_UI_NOTIFICATIONS_TOAST_DISMISSAL_REASON_TimedOut,
|
WINRT_WINDOWS_UI_NOTIFICATIONS_TOAST_DISMISSAL_REASON_TimedOut,
|
||||||
} winrtWindowsUINotificationsToastDismissalReason;
|
} winrtWindowsUINotificationsToastDismissalReason;
|
||||||
|
|
||||||
GType winrt_windows_ui_notifications_toast_dismissal_reason_get_type (void);
|
GType winrt_windows_ui_notifications_toast_dismissal_reason_get_type();
|
||||||
|
|
||||||
#define WINRT_TYPE_WINDOWS_UI_NOTIFICATIONS_TOAST_TEMPLATE_TYPE (winrt_windows_ui_notifications_toast_template_type_get_type ())
|
#define WINRT_TYPE_WINDOWS_UI_NOTIFICATIONS_TOAST_TEMPLATE_TYPE \
|
||||||
|
(winrt_windows_ui_notifications_toast_template_type_get_type())
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* winrtWindowsUINotificationsToastTemplateType:
|
* winrtWindowsUINotificationsToastTemplateType:
|
||||||
|
@ -52,7 +54,7 @@ typedef enum {
|
||||||
WINRT_WINDOWS_UI_NOTIFICATIONS_TOAST_TEMPLATE_TYPE_ToastText04,
|
WINRT_WINDOWS_UI_NOTIFICATIONS_TOAST_TEMPLATE_TYPE_ToastText04,
|
||||||
} winrtWindowsUINotificationsToastTemplateType;
|
} winrtWindowsUINotificationsToastTemplateType;
|
||||||
|
|
||||||
GType winrt_windows_ui_notifications_toast_template_type_get_type (void);
|
GType winrt_windows_ui_notifications_toast_template_type_get_type();
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,12 @@
|
||||||
|
|
||||||
namespace glib::impl
|
namespace glib::impl
|
||||||
{
|
{
|
||||||
std::optional<hresult> get_if_hresult_error(const std::exception_ptr p) noexcept try
|
std::optional<hresult> get_if_hresult_error(
|
||||||
|
const std::exception_ptr p) noexcept try
|
||||||
{
|
{
|
||||||
std::rethrow_exception(p);
|
std::rethrow_exception(p);
|
||||||
}
|
}
|
||||||
catch (const winrt::hresult_error& e)
|
catch (const winrt::hresult_error &e)
|
||||||
{
|
{
|
||||||
const char *ptr = nullptr;
|
const char *ptr = nullptr;
|
||||||
try
|
try
|
||||||
|
@ -23,7 +24,8 @@ namespace glib::impl
|
||||||
if (not ptr)
|
if (not ptr)
|
||||||
throw 42;
|
throw 42;
|
||||||
std::string msg{ptr};
|
std::string msg{ptr};
|
||||||
g_free(const_cast<char *>(ptr)); // WTF? Deletion is not modification!
|
g_free(const_cast<char *>(ptr));
|
||||||
|
// ^ WTF? Deletion is not modification! ^
|
||||||
return {{ e.code(), std::move(msg) }};
|
return {{ e.code(), std::move(msg) }};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
#include "winrt-enums.h"
|
#include "winrt-enums.h"
|
||||||
|
|
||||||
#define WINRT_GLIB_DEFINE_ENUM_VALUE(value,nick) \
|
#define WINRT_GLIB_DEFINE_ENUM_VALUE(value, nick) \
|
||||||
{ value, #value, nick },
|
{ value, #value, nick },
|
||||||
|
|
||||||
#define WINRT_GLIB_DEFINE_ENUM_TYPE(TypeName,type_name,values) \
|
#define WINRT_GLIB_DEFINE_ENUM_TYPE(TypeName, type_name, values) \
|
||||||
GType \
|
GType type_name##_get_type() \
|
||||||
type_name ## _get_type (void) \
|
|
||||||
{ \
|
{ \
|
||||||
static constexpr GEnumValue v[] = { \
|
static constexpr GEnumValue v[] = { \
|
||||||
values \
|
values \
|
||||||
{ 0, NULL, NULL }, \
|
{ 0, NULL, NULL }, \
|
||||||
}; \
|
}; \
|
||||||
static const auto enum_type_id = g_enum_register_static (g_intern_static_string (#TypeName), v); \
|
static const auto enum_type_id = \
|
||||||
|
g_enum_register_static(g_intern_static_string(#TypeName), v); \
|
||||||
return enum_type_id; \
|
return enum_type_id; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue