-
Notifications
You must be signed in to change notification settings - Fork 13
/
WinHandle.h
30 lines (24 loc) · 815 Bytes
/
WinHandle.h
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
#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;
};