New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
enable_shared_from_this.hpp in vendors/XIOS/current/extern/boost/include/boost/smart_ptr – NEMO

source: vendors/XIOS/current/extern/boost/include/boost/smart_ptr/enable_shared_from_this.hpp @ 3408

Last change on this file since 3408 was 3408, checked in by rblod, 12 years ago

importing initial XIOS vendor drop

  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
1#ifndef BOOST_SMART_PTR_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
2#define BOOST_SMART_PTR_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
3
4//
5//  enable_shared_from_this.hpp
6//
7//  Copyright 2002, 2009 Peter Dimov
8//
9//  Distributed under the Boost Software License, Version 1.0.
10//  See accompanying file LICENSE_1_0.txt or copy at
11//  http://www.boost.org/LICENSE_1_0.txt
12//
13//  http://www.boost.org/libs/smart_ptr/enable_shared_from_this.html
14//
15
16#include <boost/smart_ptr/weak_ptr.hpp>
17#include <boost/smart_ptr/shared_ptr.hpp>
18#include <boost/assert.hpp>
19#include <boost/config.hpp>
20
21namespace boost
22{
23
24template<class T> class enable_shared_from_this
25{
26protected:
27
28    enable_shared_from_this()
29    {
30    }
31
32    enable_shared_from_this(enable_shared_from_this const &)
33    {
34    }
35
36    enable_shared_from_this & operator=(enable_shared_from_this const &)
37    {
38        return *this;
39    }
40
41    ~enable_shared_from_this()
42    {
43    }
44
45public:
46
47    shared_ptr<T> shared_from_this()
48    {
49        shared_ptr<T> p( weak_this_ );
50        BOOST_ASSERT( p.get() == this );
51        return p;
52    }
53
54    shared_ptr<T const> shared_from_this() const
55    {
56        shared_ptr<T const> p( weak_this_ );
57        BOOST_ASSERT( p.get() == this );
58        return p;
59    }
60
61public: // actually private, but avoids compiler template friendship issues
62
63    // Note: invoked automatically by shared_ptr; do not call
64    template<class X, class Y> void _internal_accept_owner( shared_ptr<X> const * ppx, Y * py ) const
65    {
66        if( weak_this_.expired() )
67        {
68            weak_this_ = shared_ptr<T>( *ppx, py );
69        }
70    }
71
72private:
73
74    mutable weak_ptr<T> weak_this_;
75};
76
77} // namespace boost
78
79#endif  // #ifndef BOOST_SMART_PTR_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
Note: See TracBrowser for help on using the repository browser.