////////////////////////////////////////////////////////////////////////////// // // This file is the adaptation for Interprocess of boost/enable_shared_from_this.hpp // // (C) Copyright Peter Dimov 2002 // (C) Copyright Ion Gaztanaga 2006. 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) // // See http://www.boost.org/libs/interprocess for documentation. // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_INTERPROCESS_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED #define BOOST_INTERPROCESS_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED #include #include #include #include #include //!\file //!Describes an utility to form a shared pointer from this namespace boost{ namespace interprocess{ //!This class is used as a base class that allows a shared_ptr to the current //!object to be obtained from within a member function. //!enable_shared_from_this defines two member functions called shared_from_this //!that return a shared_ptr and shared_ptr, depending on constness, to this. template class enable_shared_from_this { /// @cond protected: enable_shared_from_this() {} enable_shared_from_this(enable_shared_from_this const &) {} enable_shared_from_this & operator=(enable_shared_from_this const &) { return *this; } ~enable_shared_from_this() {} /// @endcond public: shared_ptr shared_from_this() { shared_ptr p(_internal_weak_this); BOOST_ASSERT(ipcdetail::to_raw_pointer(p.get()) == this); return p; } shared_ptr shared_from_this() const { shared_ptr p(_internal_weak_this); BOOST_ASSERT(ipcdetail::to_raw_pointer(p.get()) == this); return p; } /// @cond typedef T element_type; mutable weak_ptr _internal_weak_this; /// @endcond }; } // namespace interprocess } // namespace boost #include #endif // #ifndef BOOST_INTERPROCESS_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED