diff options
Diffstat (limited to 'c/common.cpp')
-rw-r--r-- | c/common.cpp | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/c/common.cpp b/c/common.cpp index 5d786da..59f0fdc 100644 --- a/c/common.cpp +++ b/c/common.cpp @@ -3,48 +3,48 @@ #include "common.h" -/* wstring_owner: Simple wrapper for wide C strings. */ +/* wchar_ptr: Simple wrapper for wide C strings. */ -wstring_owner::wstring_owner() {} +wchar_ptr::wchar_ptr() {} -wstring_owner::wstring_owner(wchar_t* const s) : p(s) {} +wchar_ptr::wchar_ptr(wchar_t* const s) : m_p(s) {} -wstring_owner& wstring_owner::operator=(wchar_t* const s) +wchar_ptr& wchar_ptr::operator=(wchar_t* const s) { - if (p != s) { - delete p; - p = s; + if (m_p != s) { + delete m_p; + m_p = s; } return *this; } -wstring_owner::wstring_owner(wstring_owner&& other) noexcept : p(std::exchange(other.p, nullptr)) {} +wchar_ptr::wchar_ptr(wchar_ptr&& other) noexcept : m_p(std::exchange(other.m_p, nullptr)) {} -wstring_owner& wstring_owner::operator=(wstring_owner&& other) noexcept +wchar_ptr& wchar_ptr::operator=(wchar_ptr&& other) noexcept { - std::swap(p, other.p); + std::swap(m_p, other.m_p); return *this; } -/* Return pointer, releasing ownership. */ -wchar_t* wstring_owner::release() +wchar_ptr::operator wchar_t*() noexcept { - wchar_t* p2 = p; - p = nullptr; - return p2; + return m_p; } -wstring_owner::operator bool() const +/* Return pointer, releasing ownership. */ +wchar_t* wchar_ptr::release() { - return p; + wchar_t* p2 = m_p; + m_p = nullptr; + return p2; } -wstring_owner::~wstring_owner() +wchar_ptr::~wchar_ptr() { - delete p; + delete m_p; } -wstring_owner wstring_owner::from_narrow(const char* const src, const int cp) +wchar_ptr wchar_ptr::from_narrow(const char* const src, const int cp) { int cbMultiByte = strlen(src)+1; int cchWideChar = MultiByteToWideChar(cp, 0, src, cbMultiByte, NULL, 0); @@ -56,7 +56,7 @@ wstring_owner wstring_owner::from_narrow(const char* const src, const int cp) return dst; } -wstring_owner wstring_owner::copy(const wchar_t* const src) +wchar_ptr wchar_ptr::copy(const wchar_t* const src) { const int cb = wcslen(src)+1; wchar_t* dst = new wchar_t[cb]; |