diff options
Diffstat (limited to 'c/wcharptr.cpp')
-rw-r--r-- | c/wcharptr.cpp | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/c/wcharptr.cpp b/c/wcharptr.cpp deleted file mode 100644 index f659767..0000000 --- a/c/wcharptr.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include <utility> -#include <windows.h> - -#include "wcharptr.h" -#include "win.h" - -WcharPtr WcharPtr::FromNarrow(const char* const src, const int cp) -{ - int cchNarrow = strlen(src)+1; - int cchWide = MultiByteToWideChar(cp, 0, src, cchNarrow, nullptr, 0); - wchar_t* dst = new wchar_t[cchWide]; - if (!MultiByteToWideChar(cp, 0, src, cchNarrow, dst, cchWide)) { - delete dst; - throw Win32Error(); - } - return dst; -} - -WcharPtr WcharPtr::Copy(const wchar_t* const src) -{ - const int cch = wcslen(src)+1; - wchar_t* dst = new wchar_t[cch]; - memcpy(dst, src, cch*sizeof(wchar_t)); - return dst; -} - -WcharPtr::WcharPtr() noexcept {} - -WcharPtr::~WcharPtr() noexcept -{ - delete m_p; -} - -WcharPtr::operator wchar_t*() noexcept -{ - return m_p; -} - -WcharPtr::WcharPtr(wchar_t* const s) noexcept : m_p(s) {} - -WcharPtr& WcharPtr::operator=(wchar_t* const s) noexcept -{ - if (m_p != s) { - delete m_p; - m_p = s; - } - return *this; -} - -WcharPtr::WcharPtr(WcharPtr&& other) noexcept - : m_p(std::exchange(other.m_p, nullptr)) {} - -WcharPtr& WcharPtr::operator=(WcharPtr&& other) noexcept -{ - std::swap(m_p, other.m_p); - return *this; -} - -wchar_t* WcharPtr::Release() noexcept -{ - wchar_t* const p = m_p; - m_p = nullptr; - return p; -} |