]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/signals2/include/boost/signals2/deconstruct_ptr.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / signals2 / include / boost / signals2 / deconstruct_ptr.hpp
1 // DEPRECATED in favor of adl_postconstruct and adl_predestruct with
2 // deconstruct<T>().
3 // A factory function for creating a shared_ptr that enhances the plain
4 // shared_ptr constructors by adding support for postconstructors
5 // and predestructors through the boost::signals2::postconstructible and
6 // boost::signals2::predestructible base classes.
7 //
8 // Copyright Frank Mori Hess 2007-2008.
9 //
10 // Use, modification and
11 // distribution is subject to the Boost Software License, Version
12 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14
15 #ifndef BOOST_SIGNALS2_DECONSTRUCT_PTR_HPP
16 #define BOOST_SIGNALS2_DECONSTRUCT_PTR_HPP
17
18 #include <boost/assert.hpp>
19 #include <boost/checked_delete.hpp>
20 #include <boost/signals2/postconstructible.hpp>
21 #include <boost/signals2/predestructible.hpp>
22 #include <boost/shared_ptr.hpp>
23
24 namespace boost
25 {
26 namespace signals2
27 {
28 namespace detail
29 {
30 inline void do_postconstruct(const postconstructible *ptr)
31 {
32 postconstructible *nonconst_ptr = const_cast<postconstructible*>(ptr);
33 nonconst_ptr->postconstruct();
34 }
35 inline void do_postconstruct(...)
36 {
37 }
38 inline void do_predestruct(...)
39 {
40 }
41 inline void do_predestruct(const predestructible *ptr)
42 {
43 try
44 {
45 predestructible *nonconst_ptr = const_cast<predestructible*>(ptr);
46 nonconst_ptr->predestruct();
47 }
48 catch(...)
49 {
50 BOOST_ASSERT(false);
51 }
52 }
53 }
54
55 template<typename T> class predestructing_deleter
56 {
57 public:
58 void operator()(const T *ptr) const
59 {
60 detail::do_predestruct(ptr);
61 checked_delete(ptr);
62 }
63 };
64
65 template<typename T>
66 shared_ptr<T> deconstruct_ptr(T *ptr)
67 {
68 if(ptr == 0) return shared_ptr<T>(ptr);
69 shared_ptr<T> shared(ptr, boost::signals2::predestructing_deleter<T>());
70 detail::do_postconstruct(ptr);
71 return shared;
72 }
73 template<typename T, typename D>
74 shared_ptr<T> deconstruct_ptr(T *ptr, D deleter)
75 {
76 shared_ptr<T> shared(ptr, deleter);
77 if(ptr == 0) return shared;
78 detail::do_postconstruct(ptr);
79 return shared;
80 }
81 }
82 }
83
84 #endif // BOOST_SIGNALS2_DECONSTRUCT_PTR_HPP