From 54570cbc0d6e4798ad47a9db2e726372cfc13297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 16 Jul 2022 18:27:21 +0200 Subject: Formatting. --- c/common.h | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'c/common.h') diff --git a/c/common.h b/c/common.h index 738368f..4b28360 100644 --- a/c/common.h +++ b/c/common.h @@ -6,7 +6,14 @@ #include #include +#ifdef UNICODE +#define WA "W" +#else +#define WA "A" +#endif + std::basic_string TsmFromSz(const char *, int); + struct Win32Error : public std::exception { Win32Error(DWORD); @@ -16,6 +23,7 @@ private: DWORD m_dwErr; char *m_szMsg = NULL; }; + struct Library { Library(const TCHAR *); @@ -25,32 +33,28 @@ private: HMODULE m_hModule; }; -#ifdef UNICODE -#define WA "W" -#else -#define WA "A" -#endif - inline int Cmp(int a, int b) { - if (a == b) - return 0; - if (a > b) - return 1; + if (a == b) return 0; + if (a > b) return 1; return -1; } +/* Return integer scaled for current DPI. */ inline int Dpi(int i) { extern int g_iDPI; return MulDiv(i, g_iDPI, 96); } -template -std::optional try_make(A ...args) +/* Create and return an object of type C. If construction fails, + * return nothing. The returned value must be checked before being + * used, as dereferencing is undefined if the value is empty. */ +template +std::optional try_make(T ...args) { try { - return T(args...); + return C(args...); } catch (...) { return {}; } -- cgit v1.2.3