1
0
Fork 0

Improve Handle wrapper class

This commit is contained in:
Duncan Ogilvie 2022-01-03 03:58:16 +01:00
parent 16d3b5ea2b
commit c77b899840
1 changed files with 7 additions and 18 deletions

View File

@ -6,10 +6,9 @@
class Handle
{
public:
Handle(HANDLE h = nullptr)
{
mHandle = h;
}
Handle(HANDLE h = nullptr) : mHandle(h) { }
Handle(const Handle &) = delete;
Handle(Handle &&) = delete;
~Handle()
{
@ -18,7 +17,7 @@ public:
void Close()
{
if(mHandle != INVALID_HANDLE_VALUE)
if(*this)
{
DWORD dwFlags = 0;
if(GetHandleInformation(mHandle, &dwFlags) && !(dwFlags & HANDLE_FLAG_PROTECT_FROM_CLOSE))
@ -27,24 +26,14 @@ public:
}
}
const HANDLE & operator=(const HANDLE & h)
{
return mHandle = h;
}
operator HANDLE & ()
operator HANDLE()
{
return mHandle;
}
bool operator!() const
explicit operator bool() const
{
return (!mHandle || mHandle == INVALID_HANDLE_VALUE);
}
operator bool() const
{
return !this;
return mHandle != nullptr && mHandle != INVALID_HANDLE_VALUE;
}
private: