1
0
Fork 0
mirror of https://github.com/eliboa/TegraRcmGUI.git synced 2024-09-20 14:03:40 +01:00
TegraRcmGUI/WinHandle.h

31 lines
815 B
C
Raw Normal View History

2018-05-10 23:39:24 +01:00
#pragma once
#include "Win32Def.h"
class WinHandle
{
public:
WinHandle(HANDLE srcHandle = INVALID_HANDLE_VALUE) noexcept : _handle(srcHandle) {}
~WinHandle()
{
if (_handle != INVALID_HANDLE_VALUE)
{
::CloseHandle(_handle);
_handle = INVALID_HANDLE_VALUE;
}
}
void swap(WinHandle&& other) noexcept { std::swap(_handle, other._handle); }
WinHandle(WinHandle&& moved) noexcept : _handle(INVALID_HANDLE_VALUE) { swap(std::move(moved)); }
WinHandle(const WinHandle& copied) = delete;
WinHandle& operator=(WinHandle&& moved) { swap(std::move(moved)); return *this; }
WinHandle& operator=(const WinHandle& copied) = delete;
HANDLE get() const { return _handle; }
HANDLE release() { HANDLE retHandle = _handle; _handle = INVALID_HANDLE_VALUE; return retHandle; }
protected:
HANDLE _handle;
};