diff options
author | John Ankarström <john@ankarstrom.se> | 2022-08-03 21:57:27 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-08-03 21:57:27 +0200 |
commit | 04daecdd21e86e7556a9462380096530228cd6ca (patch) | |
tree | ed2a8134532607687c165c4a13d6f6c020c42d18 /c/wcharptr.h | |
parent | 32bb4696396e48521614d00e5b8f6e6586822f31 (diff) | |
download | EpisodeBrowser-04daecdd21e86e7556a9462380096530228cd6ca.tar.gz |
Split common.h to util.h, wcharptr.h and win.h.
Diffstat (limited to 'c/wcharptr.h')
-rw-r--r-- | c/wcharptr.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/c/wcharptr.h b/c/wcharptr.h new file mode 100644 index 0000000..1f579b5 --- /dev/null +++ b/c/wcharptr.h @@ -0,0 +1,33 @@ +#ifndef WCHARPTR_H +#define WCHARPTR_H + +#include <windows.h> + +/* 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); + + /* 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; + + /* Return pointer, releasing ownership. */ + wchar_t *release() noexcept; +private: + wchar_t* m_p = nullptr; +}; + +#endif |