From 32bb4696396e48521614d00e5b8f6e6586822f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 3 Aug 2022 20:51:23 +0200 Subject: Minor improvements. --- c/common.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'c/common.cpp') diff --git a/c/common.cpp b/c/common.cpp index 59f0fdc..0a54f69 100644 --- a/c/common.cpp +++ b/c/common.cpp @@ -3,13 +3,11 @@ #include "common.h" -/* wchar_ptr: Simple wrapper for wide C strings. */ +wchar_ptr::wchar_ptr() noexcept {} -wchar_ptr::wchar_ptr() {} +wchar_ptr::wchar_ptr(wchar_t* const s) noexcept : m_p(s) {} -wchar_ptr::wchar_ptr(wchar_t* const s) : m_p(s) {} - -wchar_ptr& wchar_ptr::operator=(wchar_t* const s) +wchar_ptr& wchar_ptr::operator=(wchar_t* const s) noexcept { if (m_p != s) { delete m_p; @@ -31,15 +29,14 @@ wchar_ptr::operator wchar_t*() noexcept return m_p; } -/* Return pointer, releasing ownership. */ -wchar_t* wchar_ptr::release() +wchar_t* wchar_ptr::release() noexcept { wchar_t* p2 = m_p; m_p = nullptr; return p2; } -wchar_ptr::~wchar_ptr() +wchar_ptr::~wchar_ptr() noexcept { delete m_p; } @@ -64,8 +61,6 @@ wchar_ptr wchar_ptr::copy(const wchar_t* const src) return dst; } -/* Win32Error: Exception for Windows API errors. */ - Win32Error::Win32Error() : code(GetLastError()) {} Win32Error::Win32Error(const DWORD code) : code(code) {} @@ -90,7 +85,7 @@ const char* Win32Error::what() const noexcept return m_szMsg; } -const wchar_t* Win32Error::WhatW() const noexcept +const wchar_t* Win32Error::What() const noexcept { if (!m_wszMsg) FormatMessage( @@ -103,8 +98,6 @@ const wchar_t* Win32Error::WhatW() const noexcept return m_wszMsg; } -/* Library: Wrapper for loading and freeing dynamically linked libraries. */ - std::optional Library::Maybe(const wchar_t* const lib) { HMODULE hModule = LoadLibrary(lib); @@ -126,7 +119,6 @@ Library::~Library() FreeLibrary(m_hModule); } -/* Show message box owned by and centered in the main window. */ int EBMessageBox(const wchar_t* const wszText, const wchar_t* const wszCaption, const unsigned uType) { extern HWND g_hWnd; -- cgit v1.2.3