Chris@16: // DEPRECATED in favor of adl_postconstruct and adl_predestruct with Chris@16: // deconstruct(). Chris@16: // A factory function for creating a shared_ptr that enhances the plain Chris@16: // shared_ptr constructors by adding support for postconstructors Chris@16: // and predestructors through the boost::signals2::postconstructible and Chris@16: // boost::signals2::predestructible base classes. Chris@16: // Chris@16: // Copyright Frank Mori Hess 2007-2008. Chris@16: // Chris@16: // Use, modification and Chris@16: // distribution is subject to the Boost Software License, Version Chris@16: // 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_SIGNALS2_DECONSTRUCT_PTR_HPP Chris@16: #define BOOST_SIGNALS2_DECONSTRUCT_PTR_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: namespace signals2 Chris@16: { Chris@16: namespace detail Chris@16: { Chris@16: extern inline void do_postconstruct(const postconstructible *ptr) Chris@16: { Chris@16: postconstructible *nonconst_ptr = const_cast(ptr); Chris@16: nonconst_ptr->postconstruct(); Chris@16: } Chris@16: extern inline void do_postconstruct(...) Chris@16: { Chris@16: } Chris@16: extern inline void do_predestruct(...) Chris@16: { Chris@16: } Chris@16: extern inline void do_predestruct(const predestructible *ptr) Chris@16: { Chris@16: try Chris@16: { Chris@16: predestructible *nonconst_ptr = const_cast(ptr); Chris@16: nonconst_ptr->predestruct(); Chris@16: } Chris@16: catch(...) Chris@16: { Chris@16: BOOST_ASSERT(false); Chris@16: } Chris@16: } Chris@16: } Chris@16: Chris@16: template class predestructing_deleter Chris@16: { Chris@16: public: Chris@16: void operator()(const T *ptr) const Chris@16: { Chris@16: detail::do_predestruct(ptr); Chris@16: checked_delete(ptr); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: shared_ptr deconstruct_ptr(T *ptr) Chris@16: { Chris@16: if(ptr == 0) return shared_ptr(ptr); Chris@16: shared_ptr shared(ptr, boost::signals2::predestructing_deleter()); Chris@16: detail::do_postconstruct(ptr); Chris@16: return shared; Chris@16: } Chris@16: template Chris@16: shared_ptr deconstruct_ptr(T *ptr, D deleter) Chris@16: { Chris@16: shared_ptr shared(ptr, deleter); Chris@16: if(ptr == 0) return shared; Chris@16: detail::do_postconstruct(ptr); Chris@16: return shared; Chris@16: } Chris@16: } Chris@16: } Chris@16: Chris@16: #endif // BOOST_SIGNALS2_DECONSTRUCT_PTR_HPP