diff options
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 |