reflow/respace

This commit is contained in:
mjk 2021-03-21 19:30:22 +00:00 committed by LAGonauta
parent 7b6f3ea9f6
commit 332216e63c
4 changed files with 50 additions and 30 deletions

View file

@ -55,25 +55,33 @@ namespace impl
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>
inline auto &describe_argument(OStream &s, const 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, typename T,
std::enable_if_t<!std::is_enum_v<T>,int> = 0>
inline auto &describe_argument(OStream &s, const 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>
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>
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>
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 *
// not implemented (TODO maybe):
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>
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>
inline auto &describe_argument(OStream &s, const wchar_t * const a) = delete; // not implemented
// TODO: handle wide strings maybe
inline auto &describe_argument(OStream &s, const wchar_t * const a) = delete;
inline impl::varstring describe_arguments() noexcept { return {""}; }
@ -94,13 +102,15 @@ catch (...)
#define FORMAT "%s(%s) failed: %s"
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...);
g_warning(FORMAT, func_name, args.c_str(), e);
}
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...);
g_warning(FORMAT": %s", func_name, args.c_str(), e, e_desc);
@ -112,7 +122,8 @@ struct regular_void {};
template<typename Invokable, typename... Arg>
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...);
return regular_void{};
@ -122,7 +133,8 @@ inline auto invoke(Invokable &&i, const Arg &... a)
}
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...))>
try
{
@ -139,7 +151,8 @@ catch (...)
{
auto hr = make_array("hresult 0x01234567\0");
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
log_invocation_failure("unknown error", func_name, a...);
@ -150,7 +163,10 @@ catch (...)
} // namespace glib
#define g_try_invoke(invokable, ...) glib::try_invoke(#invokable, invokable, __VA_ARGS__)
#define g_try_invoke0(invokable) glib::try_invoke(#invokable, invokable)
#define g_try_invoke(invokable, ...) \
glib::try_invoke(#invokable, invokable, __VA_ARGS__)
#define g_try_invoke0(invokable) \
glib::try_invoke(#invokable, invokable)
#endif

View file

@ -5,7 +5,8 @@
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:
@ -23,9 +24,10 @@ typedef enum {
WINRT_WINDOWS_UI_NOTIFICATIONS_TOAST_DISMISSAL_REASON_TimedOut,
} 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:
@ -52,7 +54,7 @@ typedef enum {
WINRT_WINDOWS_UI_NOTIFICATIONS_TOAST_TEMPLATE_TYPE_ToastText04,
} 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

View file

@ -7,7 +7,8 @@
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);
}
@ -23,7 +24,8 @@ namespace glib::impl
if (not ptr)
throw 42;
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) }};
}
else

View file

@ -4,14 +4,14 @@
{ value, #value, nick },
#define WINRT_GLIB_DEFINE_ENUM_TYPE(TypeName, type_name, values) \
GType \
type_name ## _get_type (void) \
GType type_name##_get_type() \
{ \
static constexpr GEnumValue v[] = { \
values \
{ 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; \
}