Improve Handle wrapper class
This commit is contained in:
parent
16d3b5ea2b
commit
c77b899840
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue