diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-30 03:14:13 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-30 03:14:13 +0200 |
commit | ebabd34385feb629b759216c1f7d85edc20bf2fd (patch) | |
tree | 432e68a6a58bcaf4bc1dd3c5ae438157f09f4d4a /c/common.h | |
parent | d485eb2bf7e0a82702afec9387f21bf0f89c985f (diff) | |
download | EpisodeBrowser-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.h | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -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 |