CppCMS
enable_shared_from_this.h
1 #ifndef BOOSTER_SMART_PTR_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
2 #define BOOSTER_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 <booster/weak_ptr.h>
17 #include <booster/shared_ptr.h>
18 #include <assert.h>
19 #include <booster/config.h>
20 
21 namespace booster
22 {
23 
29 
30 template<class T> class enable_shared_from_this
31 {
32 protected:
33 
35  {
36  }
37 
39  {
40  }
41 
43  {
44  return *this;
45  }
46 
48  {
49  }
50 
51 public:
52 
53  shared_ptr<T> shared_from_this()
54  {
55  shared_ptr<T> p( weak_this_ );
56  assert( p.get() == this );
57  return p;
58  }
59 
60  shared_ptr<T const> shared_from_this() const
61  {
62  shared_ptr<T const> p( weak_this_ );
63  assert( p.get() == this );
64  return p;
65  }
66 
67 public: // actually private, but avoids compiler template friendship issues
68 
69  // Note: invoked automatically by shared_ptr; do not call
70  template<class X, class Y> void _internal_accept_owner( shared_ptr<X> const * ppx, Y * py ) const
71  {
72  if( weak_this_.expired() )
73  {
74  weak_this_ = shared_ptr<T>( *ppx, py );
75  }
76  }
77 
78 private:
79 
80  mutable weak_ptr<T> weak_this_;
81 };
82 
83 } // namespace boost
84 
85 #endif // #ifndef BOOST_SMART_PTR_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
Definition: log.h:25
Definition: log.h:27
This class is borrowed from boost.
Definition: enable_shared_from_this.h:30
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23