// (C) Copyright Jonathan Turkanis 2004. // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) // Disclaimer: Not a Boost library. // reinterpret_cast is eliminable here; it is used to simplify the // implementation. #ifndef BOOST_IDL_UNIQUE_INTERFACE_PTR_HPP_INCLUDED #define BOOST_IDL_UNIQUE_INTERFACE_PTR_HPP_INCLUDED #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif #include // swap. #include #include #include #include #include #include #include #include #include #include #include // BOOST_MSVC. #if defined(BOOST_MSVC) # pragma warning(push) # pragma warning(disable:4521) // Multiple copy constuctors. #endif namespace boost { namespace interfaces { template class unique_ptr { public: BOOST_IDL_CORE_SMART_PTR_SUPPORT(unique_ptr, Interface) // Constructors BOOST_IDL_CTOR_DEFAULT(unique_ptr) BOOST_IDL_SMART_PTR_CTOR_FROM_PTR(unique_ptr, Interface) unique_ptr(const unique_ptr& p) : BOOST_IDL_MEMBER_PTR(p.get_pointer()), BOOST_IDL_MEMBER_TABLE(p.get_table()) { p.get_pointer() = 0; p.get_table() = 0; } template unique_ptr(const unique_ptr& p) : BOOST_IDL_MEMBER_PTR(p.get_pointer()), BOOST_IDL_MEMBER_TABLE( p.get_table() + detail::offset_of::value ) { p.get_pointer() = 0; p.get_table() = 0; } template unique_ptr(move_source< unique_ptr > src) : BOOST_IDL_MEMBER_PTR(src.ptr().get_pointer()), BOOST_IDL_MEMBER_TABLE( src.ptr().get_table() + detail::offset_of::value ) { src.ptr().get_pointer() = 0; src.ptr().get_table() = 0; } // Destructor ~unique_ptr() { if (get_pointer()) detail::get_deleter(*this)(get_pointer()); } // Assignment unique_ptr& operator=(unique_ptr p) { p.swap(*this); return *this; } template unique_ptr& operator=(unique_ptr p) { std::swap(get_pointer(), p.get_pointer()); get_table() = p.get_table() + detail::offset_of::value; p.get_table() = 0; return *this; } // Smart pointer interface BOOST_IDL_SMART_PTR_SWAP(unique_ptr) void reset() { if (get_pointer()) { detail::get_deleter(*this)(get_pointer()); get_pointer() = 0; get_table() = 0; } } template void reset(T* t) { BOOST_ASSERT(t && t != get_pointer()); unique_ptr(t).swap(*this); } manual_ptr release() { manual_ptr result = *reinterpret_cast*>(this); get_pointer() = 0; get_table() = 0; return result; } // VC7.1 requires this to be at end. BOOST_IDL_MOVE_SUPPORT(unique_ptr) }; } } // End namespace interfaces, boost. #if defined(BOOST_MSVC) #pragma warning(pop) // #pragma warning(disable:4251) #endif #endif // #ifndef BOOST_IDL_UNIQUE_INTERFACE_PTR_HPP_INCLUDED