aboutsummaryrefslogtreecommitdiff
path: root/c/common.h
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-02 23:50:58 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-02 23:50:58 +0200
commit23dc657f0af27bdac887f8d18208d544cc9f010e (patch)
treea2656d96f11f879d6a4233fef736493a1cc39ba6 /c/common.h
parentedce20642b6d177ee9877775cbfa9e05ebb4e404 (diff)
downloadEpisodeBrowser-23dc657f0af27bdac887f8d18208d544cc9f010e.tar.gz
Improve wstring_owner, rename to wchar_ptr.
The user-defined conversion function makes the interface a lot simpler AND safer.
Diffstat (limited to 'c/common.h')
-rw-r--r--c/common.h27
1 files changed, 14 insertions, 13 deletions
diff --git a/c/common.h b/c/common.h
index 0851bb6..f011565 100644
--- a/c/common.h
+++ b/c/common.h
@@ -8,21 +8,22 @@
int EBMessageBox(const wchar_t* wszText, const wchar_t* wszCaption, unsigned uType);
int GetRelativeCursorPos(HWND hWnd, POINT* pt);
-struct wstring_owner
+struct wchar_ptr
{
- static wstring_owner from_narrow(const char* buf, int cp = CP_UTF8);
- static wstring_owner copy(const wchar_t* s);
- wstring_owner();
- wstring_owner(wchar_t* s);
- wstring_owner& operator=(wchar_t* s);
- wstring_owner(wstring_owner& other) = delete;
- wstring_owner& operator=(wstring_owner& other) = delete;
- wstring_owner(wstring_owner&& other) noexcept;
- wstring_owner& operator=(wstring_owner&& other) noexcept;
+ 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);
+ wchar_ptr(wchar_ptr& other) = delete;
+ wchar_ptr& operator=(wchar_ptr& other) = delete;
+ wchar_ptr(wchar_ptr&& other) noexcept;
+ wchar_ptr& operator=(wchar_ptr&& other) noexcept;
+ operator wchar_t*() noexcept;
wchar_t *release();
- operator bool() const;
- ~wstring_owner();
- wchar_t* p = nullptr;
+ ~wchar_ptr();
+private:
+ wchar_t* m_p = nullptr;
};
struct Win32Error : public std::exception