libcruft-util/cruft/util/win32/handle.cpp

91 lines
1.9 KiB
C++
Raw Normal View History

#include "handle.hpp"
#include "except.hpp"
using cruft::win32::handle;
///////////////////////////////////////////////////////////////////////////////
handle::handle ():
m_native (INVALID_HANDLE_VALUE)
{ ; }
//-----------------------------------------------------------------------------
handle::handle (HANDLE &&h):
m_native (h)
{ ; }
//-----------------------------------------------------------------------------
2019-03-27 19:07:51 +11:00
handle::handle (posix::fd &&rhs):
m_native (reinterpret_cast<HANDLE> (_get_osfhandle (rhs.release ())))
{
2019-03-27 19:07:51 +11:00
win32::error::try_value (m_native);
}
//-----------------------------------------------------------------------------
2019-03-27 19:07:51 +11:00
handle::handle (cruft::win32::handle &&rhs) noexcept
: handle ()
{
2019-03-27 19:07:51 +11:00
std::swap (m_native, rhs.m_native);
}
//-----------------------------------------------------------------------------
handle& handle::operator= (handle &&rhs) noexcept
{
std::swap (m_native, rhs.m_native);
return *this;
}
//-----------------------------------------------------------------------------
handle::~handle ()
{
if (m_native != INVALID_HANDLE_VALUE)
CloseHandle (m_native);
}
///////////////////////////////////////////////////////////////////////////////
handle::operator HANDLE& (void) &
{
return native ();
}
//-----------------------------------------------------------------------------
HANDLE&
handle::native (void) &
{
return m_native;
}
//-----------------------------------------------------------------------------
const HANDLE&
handle::native (void) const &
{
return m_native;
}
///////////////////////////////////////////////////////////////////////////////
void
handle::reset (HANDLE rhs)
{
if (m_native != INVALID_HANDLE_VALUE)
CloseHandle (m_native);
m_native = rhs;
}
///////////////////////////////////////////////////////////////////////////////
handle
handle::current_process (void)
{
return handle (GetCurrentProcess ());
}