aboutsummaryrefslogtreecommitdiff
path: root/c/common.h
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-30 03:14:13 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-30 03:14:13 +0200
commitebabd34385feb629b759216c1f7d85edc20bf2fd (patch)
tree432e68a6a58bcaf4bc1dd3c5ae438157f09f4d4a /c/common.h
parentd485eb2bf7e0a82702afec9387f21bf0f89c985f (diff)
downloadEpisodeBrowser-ebabd34385feb629b759216c1f7d85edc20bf2fd.tar.gz
Add wstring_owner, replacing std::wstring.
std::basic_string is nice, but it is not very ergonomic if everything you really need is to automatically free C strings at end of scope. I suppose I could have used std::unique_ptr for this, but I suspect the ergonomics would be worse.
Diffstat (limited to 'c/common.h')
-rw-r--r--c/common.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/c/common.h b/c/common.h
index 8b88635..7b7e996 100644
--- a/c/common.h
+++ b/c/common.h
@@ -11,7 +11,22 @@
#define WA "A"
#endif
-std::wstring WsFromSz(const char* sz, int iCp = CP_UTF8);
+struct wstring_owner
+{
+ wstring_owner();
+ wstring_owner(wchar_t* wsz);
+ wstring_owner& operator=(wchar_t* wsz);
+ wstring_owner(wstring_owner& wso) = delete;
+ wstring_owner& operator=(wstring_owner& wso) = delete;
+ wstring_owner(wstring_owner&& wso) noexcept;
+ wstring_owner& operator=(wstring_owner&& wso) noexcept;
+ wchar_t *release();
+ operator bool() const;
+ ~wstring_owner();
+ wchar_t* p = nullptr;
+};
+
+wstring_owner WsoFromSz(const char* sz, int iCp = CP_UTF8);
int EBMessageBox(const wchar_t* wszText, const wchar_t* wszCaption, unsigned uType);
struct Win32Error : public std::exception