2 * Copyright Andrey Semashev 2016.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
8 * \file windows/auto_handle.hpp
9 * \author Andrey Semashev
12 * \brief This header is the Boost.Log library implementation, see the library documentation
13 * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
16 #ifndef BOOST_LOG_WINDOWS_AUTO_HANDLE_HPP_INCLUDED_
17 #define BOOST_LOG_WINDOWS_AUTO_HANDLE_HPP_INCLUDED_
19 #include <boost/log/detail/config.hpp>
20 #include <boost/assert.hpp>
21 #include <boost/winapi/handles.hpp>
22 #include <boost/log/detail/header.hpp>
26 BOOST_LOG_OPEN_NAMESPACE
32 //! A wrapper around a kernel object handle. Automatically closes the handle on destruction.
36 boost::winapi::HANDLE_ m_handle;
39 explicit auto_handle(boost::winapi::HANDLE_ h = NULL) BOOST_NOEXCEPT : m_handle(h)
43 ~auto_handle() BOOST_NOEXCEPT
46 BOOST_VERIFY(boost::winapi::CloseHandle(m_handle) != 0);
49 void init(boost::winapi::HANDLE_ h) BOOST_NOEXCEPT
51 BOOST_ASSERT(m_handle == NULL);
55 boost::winapi::HANDLE_ get() const BOOST_NOEXCEPT { return m_handle; }
56 boost::winapi::HANDLE_* get_ptr() BOOST_NOEXCEPT { return &m_handle; }
58 void swap(auto_handle& that) BOOST_NOEXCEPT
60 boost::winapi::HANDLE_ h = m_handle;
61 m_handle = that.m_handle;
65 BOOST_DELETED_FUNCTION(auto_handle(auto_handle const&))
66 BOOST_DELETED_FUNCTION(auto_handle& operator=(auto_handle const&))
73 BOOST_LOG_CLOSE_NAMESPACE // namespace log
77 #include <boost/log/detail/footer.hpp>
79 #endif // BOOST_LOG_WINDOWS_AUTO_HANDLE_HPP_INCLUDED_