Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:53:29

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // This file is the adaptation for Interprocess of boost/enable_shared_from_this.hpp
0004 //
0005 // (C) Copyright Peter Dimov 2002
0006 // (C) Copyright Ion Gaztanaga 2006-2012. Distributed under the Boost
0007 // Software License, Version 1.0. (See accompanying file
0008 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 // See http://www.boost.org/libs/interprocess for documentation.
0011 //
0012 //////////////////////////////////////////////////////////////////////////////
0013 
0014 #ifndef BOOST_INTERPROCESS_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
0015 #define BOOST_INTERPROCESS_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
0016 
0017 #ifndef BOOST_CONFIG_HPP
0018 #  include <boost/config.hpp>
0019 #endif
0020 #
0021 #if defined(BOOST_HAS_PRAGMA_ONCE)
0022 #  pragma once
0023 #endif
0024 
0025 #include <boost/interprocess/detail/config_begin.hpp>
0026 #include <boost/interprocess/detail/workaround.hpp>
0027 
0028 #include <boost/assert.hpp>
0029 #include <boost/interprocess/smart_ptr/weak_ptr.hpp>
0030 #include <boost/interprocess/smart_ptr/shared_ptr.hpp>
0031 
0032 //!\file
0033 //!Describes an utility to form a shared pointer from this
0034 
0035 namespace boost{
0036 namespace interprocess{
0037 
0038 //!This class is used as a base class that allows a shared_ptr to the current
0039 //!object to be obtained from within a member function.
0040 //!enable_shared_from_this defines two member functions called shared_from_this
0041 //!that return a shared_ptr<T> and shared_ptr<T const>, depending on constness, to this.
0042 template<class T, class A, class D>
0043 class enable_shared_from_this
0044 {
0045    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0046    protected:
0047    enable_shared_from_this()
0048    {}
0049 
0050    enable_shared_from_this(enable_shared_from_this const &)
0051    {}
0052 
0053    enable_shared_from_this & operator=(enable_shared_from_this const &)
0054    {  return *this;  }
0055 
0056    ~enable_shared_from_this()
0057    {}
0058    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0059 
0060    public:
0061    shared_ptr<T, A, D> shared_from_this()
0062    {
0063       shared_ptr<T, A, D> p(_internal_weak_this);
0064       BOOST_ASSERT(ipcdetail::to_raw_pointer(p.get()) == this);
0065       return p;
0066    }
0067 
0068    shared_ptr<T const, A, D> shared_from_this() const
0069    {
0070       shared_ptr<T const, A, D> p(_internal_weak_this);
0071       BOOST_ASSERT(ipcdetail::to_raw_pointer(p.get()) == this);
0072       return p;
0073    }
0074 
0075    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0076    typedef T element_type;
0077    mutable weak_ptr<element_type, A, D> _internal_weak_this;
0078    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0079 };
0080 
0081 } // namespace interprocess
0082 } // namespace boost
0083 
0084 #include <boost/interprocess/detail/config_end.hpp>
0085 
0086 #endif  // #ifndef BOOST_INTERPROCESS_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
0087