aboutsummaryrefslogtreecommitdiff
path: root/c/common.h
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-03 20:51:23 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-03 21:39:06 +0200
commit32bb4696396e48521614d00e5b8f6e6586822f31 (patch)
tree1c5bd8e5d1a3f549b0a84159b66af472e6aff178 /c/common.h
parentdee3a413f072e5779fc5ba80692f895ba43815c6 (diff)
downloadEpisodeBrowser-32bb4696396e48521614d00e5b8f6e6586822f31.tar.gz
Minor improvements.
Diffstat (limited to 'c/common.h')
-rw-r--r--c/common.h31
1 files changed, 21 insertions, 10 deletions
diff --git a/c/common.h b/c/common.h
index 9d322b3..70c2c32 100644
--- a/c/common.h
+++ b/c/common.h
@@ -8,37 +8,48 @@
int EBMessageBox(const wchar_t* wszText, const wchar_t* wszCaption, unsigned uType);
int GetRelativeCursorPos(HWND hWnd, POINT* pt);
+/* wchar_ptr: Simple wrapper for wide C strings. */
struct wchar_ptr
{
+ /* Named copy constructors (expensive). */
static wchar_ptr from_narrow(const char* buf, int cp = CP_UTF8);
static wchar_ptr copy(const wchar_t* s);
- wchar_ptr();
- wchar_ptr(wchar_t* s);
- wchar_ptr& operator=(wchar_t* s);
+
+ /* Non-explicit copies are disabled. */
wchar_ptr(wchar_ptr& other) = delete;
wchar_ptr& operator=(wchar_ptr& other) = delete;
+
+ wchar_ptr() noexcept;
+ ~wchar_ptr();
+ operator wchar_t*() noexcept;
+
+ wchar_ptr(wchar_t* s) noexcept;
+ wchar_ptr& operator=(wchar_t* s) noexcept;
+
wchar_ptr(wchar_ptr&& other) noexcept;
wchar_ptr& operator=(wchar_ptr&& other) noexcept;
- operator wchar_t*() noexcept;
- wchar_t *release();
- ~wchar_ptr();
+
+ /* Return pointer, releasing ownership. */
+ wchar_t *release() noexcept;
private:
wchar_t* m_p = nullptr;
};
+/* Win32Error: Exception for Windows API errors. */
struct Win32Error : public std::exception
{
Win32Error();
Win32Error(DWORD code);
~Win32Error();
- const char* what() const noexcept;
- const wchar_t* WhatW() const noexcept;
+ const char* what() const noexcept override;
+ const wchar_t* What() const noexcept;
DWORD code;
private:
char* m_szMsg = NULL;
wchar_t* m_wszMsg = NULL;
};
+/* Library: Wrapper for loading and freeing dynamically linked libraries. */
struct Library
{
static std::optional<Library> Maybe(const wchar_t* lib);
@@ -57,7 +68,7 @@ T* Library::GetProcAddress(const char* const szProc)
}
template<size_t N, typename... T>
-inline int wszf(wchar_t (&buf)[N], const wchar_t* const fmt, T... xs)
+inline int Swprintf(wchar_t (&buf)[N], const wchar_t* const fmt, T... xs)
{
return _snwprintf_s(buf, N, _TRUNCATE, fmt, xs...);
}
@@ -79,7 +90,7 @@ template <typename T>
inline T prefer(const T x)
{
if (!x) {
- EBMessageBox(Win32Error().WhatW(), L"System Error", MB_ICONWARNING);
+ EBMessageBox(Win32Error().What(), L"System Error", MB_ICONWARNING);
return (T)NULL;
}
return x;