aboutsummaryrefslogtreecommitdiff
path: root/c/wcharptr.h
blob: 1f579b5fb98208af1843bb3ef929e0f341a97eb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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