| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | #ifndef BOOST_SHARED_PTR_HPP_INCLUDED
 | 
					
						
							|  |  |  | #define BOOST_SHARED_PTR_HPP_INCLUDED
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  shared_ptr.hpp
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
 | 
					
						
							| 
									
										
										
										
											2003-01-04 14:24:14 +00:00
										 |  |  | //  Copyright (c) 2001, 2002, 2003 Peter Dimov
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2004-08-19 15:23:47 +00:00
										 |  |  | //  Distributed under the Boost Software License, Version 1.0. (See
 | 
					
						
							|  |  |  | //  accompanying file LICENSE_1_0.txt or copy at
 | 
					
						
							|  |  |  | //  http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2002-02-04 11:15:40 +00:00
										 |  |  | //  See http://www.boost.org/libs/smart_ptr/shared_ptr.htm for documentation.
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/config.hpp>   // for broken compiler workarounds
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-24 15:36:25 +00:00
										 |  |  | #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | #include <boost/detail/shared_ptr_nmt.hpp>
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/assert.hpp>
 | 
					
						
							|  |  |  | #include <boost/checked_delete.hpp>
 | 
					
						
							| 
									
										
										
										
											2002-08-14 12:27:22 +00:00
										 |  |  | #include <boost/throw_exception.hpp>
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | #include <boost/detail/shared_count.hpp>
 | 
					
						
							| 
									
										
										
										
											2002-12-26 18:23:11 +00:00
										 |  |  | #include <boost/detail/workaround.hpp>
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-25 12:27:11 +00:00
										 |  |  | #include <memory>               // for std::auto_ptr
 | 
					
						
							|  |  |  | #include <algorithm>            // for std::swap
 | 
					
						
							|  |  |  | #include <functional>           // for std::less
 | 
					
						
							|  |  |  | #include <typeinfo>             // for std::bad_cast
 | 
					
						
							|  |  |  | #include <iosfwd>               // for std::basic_ostream
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef BOOST_MSVC  // moved here to work around VC++ compiler crash
 | 
					
						
							|  |  |  | # pragma warning(push)
 | 
					
						
							|  |  |  | # pragma warning(disable:4284) // odd return type for operator->
 | 
					
						
							| 
									
										
										
										
											2002-01-24 19:16:12 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace boost | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-20 12:38:51 +00:00
										 |  |  | template<class T> class weak_ptr; | 
					
						
							|  |  |  | template<class T> class enable_shared_from_this; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | namespace detail | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct static_cast_tag {}; | 
					
						
							| 
									
										
										
										
											2003-07-16 11:51:12 +00:00
										 |  |  | struct const_cast_tag {}; | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | struct dynamic_cast_tag {}; | 
					
						
							| 
									
										
										
										
											2002-02-06 19:42:04 +00:00
										 |  |  | struct polymorphic_cast_tag {}; | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  | template<class T> struct shared_ptr_traits | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     typedef T & reference; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<> struct shared_ptr_traits<void> | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     typedef void reference; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-23 12:33:11 +00:00
										 |  |  | #if !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<> struct shared_ptr_traits<void const> | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     typedef void reference; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-16 11:51:12 +00:00
										 |  |  | template<> struct shared_ptr_traits<void volatile> | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     typedef void reference; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<> struct shared_ptr_traits<void const volatile> | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     typedef void reference; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-23 12:33:11 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-20 12:38:51 +00:00
										 |  |  | // enable_shared_from_this support
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-08-24 16:27:31 +00:00
										 |  |  | template<class T, class Y> void sp_enable_shared_from_this( shared_count const & pn, boost::enable_shared_from_this<T> const * pe, Y const * px ) | 
					
						
							| 
									
										
										
										
											2002-11-20 12:38:51 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-02-16 18:50:07 +00:00
										 |  |  |     if(pe != 0) pe->_internal_weak_this._internal_assign(const_cast<Y*>(px), pn); | 
					
						
							| 
									
										
										
										
											2002-11-20 12:38:51 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-08-24 16:27:31 +00:00
										 |  |  | inline void sp_enable_shared_from_this( shared_count const & /*pn*/, ... ) | 
					
						
							| 
									
										
										
										
											2002-11-20 12:38:51 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | } // namespace detail
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  shared_ptr
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  An enhanced relative of scoped_ptr with reference counted copy semantics.
 | 
					
						
							|  |  |  | //  The object pointed to is deleted when the last shared_ptr pointing to it
 | 
					
						
							|  |  |  | //  is destroyed or reset.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  | template<class T> class shared_ptr | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | { | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-19 18:21:32 +00:00
										 |  |  |     // Borland 5.5.1 specific workaround
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     typedef shared_ptr<T> this_type; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     typedef T element_type; | 
					
						
							| 
									
										
										
										
											2002-08-14 12:27:22 +00:00
										 |  |  |     typedef T value_type; | 
					
						
							| 
									
										
										
										
											2002-11-18 14:37:02 +00:00
										 |  |  |     typedef T * pointer; | 
					
						
							|  |  |  |     typedef typename detail::shared_ptr_traits<T>::reference reference; | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-03 16:53:04 +00:00
										 |  |  |     shared_ptr(): px(0), pn() // never throws in 1.30+
 | 
					
						
							| 
									
										
										
										
											2002-02-15 13:31:58 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  |     template<class Y> | 
					
						
							| 
									
										
										
										
											2005-03-17 23:30:47 +00:00
										 |  |  |     explicit shared_ptr( Y * p ): px( p ), pn( p ) // Y must be complete
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2004-08-24 16:27:31 +00:00
										 |  |  |         detail::sp_enable_shared_from_this( pn, p, p ); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     // Requirements: D's copy constructor must not throw
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     // shared_ptr will release p by calling d(p)
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  |     template<class Y, class D> shared_ptr(Y * p, D d): px(p), pn(p, d) | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2004-08-24 16:27:31 +00:00
										 |  |  |         detail::sp_enable_shared_from_this( pn, p, p ); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-19 18:21:32 +00:00
										 |  |  | //  generated copy constructor, assignment, destructor are fine...
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-03 13:48:33 +00:00
										 |  |  | //  except that Borland C++ has a bug, and g++ with -Wsynth warns
 | 
					
						
							|  |  |  | #if defined(__BORLANDC__) || defined(__GNUC__)
 | 
					
						
							| 
									
										
										
										
											2002-11-19 18:21:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     shared_ptr & operator=(shared_ptr const & r) // never throws
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         px = r.px; | 
					
						
							|  |  |  |         pn = r.pn; // shared_count::op= doesn't throw
 | 
					
						
							|  |  |  |         return *this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  |     template<class Y> | 
					
						
							| 
									
										
										
										
											2002-11-22 13:49:54 +00:00
										 |  |  |     explicit shared_ptr(weak_ptr<Y> const & r): pn(r.pn) // may throw
 | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-11-22 13:49:54 +00:00
										 |  |  |         // it is now safe to copy r.px, as pn(r.pn) did not throw
 | 
					
						
							|  |  |  |         px = r.px; | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  |     template<class Y> | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     shared_ptr(shared_ptr<Y> const & r): px(r.px), pn(r.pn) // never throws
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  |     template<class Y> | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     shared_ptr(shared_ptr<Y> const & r, detail::static_cast_tag): px(static_cast<element_type *>(r.px)), pn(r.pn) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-16 11:51:12 +00:00
										 |  |  |     template<class Y> | 
					
						
							|  |  |  |     shared_ptr(shared_ptr<Y> const & r, detail::const_cast_tag): px(const_cast<element_type *>(r.px)), pn(r.pn) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  |     template<class Y> | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     shared_ptr(shared_ptr<Y> const & r, detail::dynamic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-11-19 16:18:58 +00:00
										 |  |  |         if(px == 0) // need to allocate new counter -- the cast failed
 | 
					
						
							| 
									
										
										
										
											2002-02-04 11:15:40 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2002-02-15 14:19:30 +00:00
										 |  |  |             pn = detail::shared_count(); | 
					
						
							| 
									
										
										
										
											2002-02-04 11:15:40 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  |     template<class Y> | 
					
						
							| 
									
										
										
										
											2002-02-06 19:42:04 +00:00
										 |  |  |     shared_ptr(shared_ptr<Y> const & r, detail::polymorphic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-11-22 13:49:54 +00:00
										 |  |  |         if(px == 0) | 
					
						
							| 
									
										
										
										
											2002-02-06 19:42:04 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2002-08-14 12:27:22 +00:00
										 |  |  |             boost::throw_exception(std::bad_cast()); | 
					
						
							| 
									
										
										
										
											2002-02-06 19:42:04 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | #ifndef BOOST_NO_AUTO_PTR
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  |     template<class Y> | 
					
						
							| 
									
										
										
										
											2002-11-18 14:37:02 +00:00
										 |  |  |     explicit shared_ptr(std::auto_ptr<Y> & r): px(r.get()), pn() | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-11-18 14:37:02 +00:00
										 |  |  |         Y * tmp = r.get(); | 
					
						
							|  |  |  |         pn = detail::shared_count(r); | 
					
						
							| 
									
										
										
										
											2004-08-24 16:27:31 +00:00
										 |  |  |         detail::sp_enable_shared_from_this( pn, tmp, tmp ); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-10 14:12:12 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if !defined(BOOST_MSVC) || (BOOST_MSVC > 1200)
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  |     template<class Y> | 
					
						
							| 
									
										
										
										
											2002-02-02 18:36:12 +00:00
										 |  |  |     shared_ptr & operator=(shared_ptr<Y> const & r) // never throws
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         px = r.px; | 
					
						
							|  |  |  |         pn = r.pn; // shared_count::op= doesn't throw
 | 
					
						
							|  |  |  |         return *this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-10 14:12:12 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | #ifndef BOOST_NO_AUTO_PTR
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  |     template<class Y> | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     shared_ptr & operator=(std::auto_ptr<Y> & r) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         this_type(r).swap(*this); | 
					
						
							|  |  |  |         return *this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-03 16:53:04 +00:00
										 |  |  |     void reset() // never throws in 1.30+
 | 
					
						
							| 
									
										
										
										
											2002-02-15 13:31:58 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         this_type().swap(*this); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  |     template<class Y> void reset(Y * p) // Y must be complete
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-02-15 13:31:58 +00:00
										 |  |  |         BOOST_ASSERT(p == 0 || p != px); // catch self-reset errors
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |         this_type(p).swap(*this); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  |     template<class Y, class D> void reset(Y * p, D d) | 
					
						
							| 
									
										
										
										
											2002-01-24 19:16:12 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         this_type(p, d).swap(*this); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-18 14:37:02 +00:00
										 |  |  |     reference operator* () const // never throws
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         BOOST_ASSERT(px != 0); | 
					
						
							|  |  |  |         return *px; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     T * operator-> () const // never throws
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         BOOST_ASSERT(px != 0); | 
					
						
							|  |  |  |         return px; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     T * get() const // never throws
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return px; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 15:15:39 +00:00
										 |  |  |     // implicit conversion to "bool"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 17:09:24 +00:00
										 |  |  | #if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
 | 
					
						
							| 
									
										
										
										
											2003-05-16 12:11:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     operator bool () const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return px != 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-02 12:00:14 +00:00
										 |  |  | #elif \
 | 
					
						
							|  |  |  |     ( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \ | 
					
						
							|  |  |  |     ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-02 17:49:06 +00:00
										 |  |  |     typedef T * (this_type::*unspecified_bool_type)() const; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     operator unspecified_bool_type() const // never throws
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return px == 0? 0: &this_type::get; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #else 
 | 
					
						
							| 
									
										
										
										
											2003-05-16 12:11:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-01 11:12:15 +00:00
										 |  |  |     typedef T * this_type::*unspecified_bool_type; | 
					
						
							| 
									
										
										
										
											2002-07-17 15:15:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     operator unspecified_bool_type() const // never throws
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-10-01 11:12:15 +00:00
										 |  |  |         return px == 0? 0: &this_type::px; | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-16 12:11:17 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-03 16:53:04 +00:00
										 |  |  |     // operator! is redundant, but some compilers need it
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 15:15:39 +00:00
										 |  |  |     bool operator! () const // never throws
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-07-17 15:15:39 +00:00
										 |  |  |         return px == 0; | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 15:15:39 +00:00
										 |  |  |     bool unique() const // never throws
 | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-07-17 15:15:39 +00:00
										 |  |  |         return pn.unique(); | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 15:15:39 +00:00
										 |  |  |     long use_count() const // never throws
 | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-07-17 15:15:39 +00:00
										 |  |  |         return pn.use_count(); | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     void swap(shared_ptr<T> & other) // never throws
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         std::swap(px, other.px); | 
					
						
							|  |  |  |         pn.swap(other.pn); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-23 12:47:38 +00:00
										 |  |  |     template<class Y> bool _internal_less(shared_ptr<Y> const & rhs) const | 
					
						
							| 
									
										
										
										
											2002-11-18 14:37:02 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         return pn < rhs.pn; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-21 14:46:45 +00:00
										 |  |  |     void * _internal_get_deleter(std::type_info const & ti) const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return pn.get_deleter(ti); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | // Tasteless as this may seem, making all members public allows member templates
 | 
					
						
							|  |  |  | // to work in the absence of member template friends. (Matthew Langston)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  |     template<class Y> friend class shared_ptr; | 
					
						
							|  |  |  |     template<class Y> friend class weak_ptr; | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     T * px;                     // contained pointer
 | 
					
						
							|  |  |  |     detail::shared_count pn;    // reference counter
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | };  // shared_ptr
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  | template<class T, class U> inline bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b) | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return a.get() == b.get(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  | template<class T, class U> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<U> const & b) | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return a.get() != b.get(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-02-09 15:45:29 +00:00
										 |  |  | #if __GNUC__ == 2 && __GNUC_MINOR__ <= 96
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Resolve the ambiguity between our op!= and the one in rel_ops
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  | template<class T> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<T> const & b) | 
					
						
							| 
									
										
										
										
											2002-02-09 15:45:29 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return a.get() != b.get(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-23 12:47:38 +00:00
										 |  |  | template<class T, class U> inline bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b) | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2002-11-20 12:38:51 +00:00
										 |  |  |     return a._internal_less(b); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  | template<class T> inline void swap(shared_ptr<T> & a, shared_ptr<T> & b) | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2002-02-02 18:36:12 +00:00
										 |  |  |     a.swap(b); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-18 14:37:02 +00:00
										 |  |  | template<class T, class U> shared_ptr<T> static_pointer_cast(shared_ptr<U> const & r) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return shared_ptr<T>(r, detail::static_cast_tag()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-16 11:51:12 +00:00
										 |  |  | template<class T, class U> shared_ptr<T> const_pointer_cast(shared_ptr<U> const & r) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return shared_ptr<T>(r, detail::const_cast_tag()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-18 14:37:02 +00:00
										 |  |  | template<class T, class U> shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const & r) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return shared_ptr<T>(r, detail::dynamic_cast_tag()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // shared_*_cast names are deprecated. Use *_pointer_cast instead.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  | template<class T, class U> shared_ptr<T> shared_static_cast(shared_ptr<U> const & r) | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2002-02-02 18:36:12 +00:00
										 |  |  |     return shared_ptr<T>(r, detail::static_cast_tag()); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  | template<class T, class U> shared_ptr<T> shared_dynamic_cast(shared_ptr<U> const & r) | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2002-02-02 18:36:12 +00:00
										 |  |  |     return shared_ptr<T>(r, detail::dynamic_cast_tag()); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  | template<class T, class U> shared_ptr<T> shared_polymorphic_cast(shared_ptr<U> const & r) | 
					
						
							| 
									
										
										
										
											2002-02-06 19:42:04 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return shared_ptr<T>(r, detail::polymorphic_cast_tag()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  | template<class T, class U> shared_ptr<T> shared_polymorphic_downcast(shared_ptr<U> const & r) | 
					
						
							| 
									
										
										
										
											2002-02-06 19:42:04 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     BOOST_ASSERT(dynamic_cast<T *>(r.get()) == r.get()); | 
					
						
							|  |  |  |     return shared_static_cast<T>(r); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | // get_pointer() enables boost::mem_fn to recognize shared_ptr
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  | template<class T> inline T * get_pointer(shared_ptr<T> const & p) | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return p.get(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-25 12:27:11 +00:00
										 |  |  | // operator<<
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-25 13:52:42 +00:00
										 |  |  | #if defined(__GNUC__) &&  (__GNUC__ < 3)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class Y> std::ostream & operator<< (std::ostream & os, shared_ptr<Y> const & p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     os << p.get(); | 
					
						
							|  |  |  |     return os; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 17:09:24 +00:00
										 |  |  | # if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, <= 1200 && __SGI_STL_PORT)
 | 
					
						
							| 
									
										
										
										
											2002-12-26 18:23:11 +00:00
										 |  |  | // MSVC6 has problems finding std::basic_ostream through the using declaration in namespace _STL
 | 
					
						
							|  |  |  | using std::basic_ostream; | 
					
						
							|  |  |  | template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, shared_ptr<Y> const & p) | 
					
						
							|  |  |  | # else
 | 
					
						
							| 
									
										
										
										
											2002-11-25 12:27:11 +00:00
										 |  |  | template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, shared_ptr<Y> const & p) | 
					
						
							| 
									
										
										
										
											2002-12-26 18:23:11 +00:00
										 |  |  | # endif 
 | 
					
						
							| 
									
										
										
										
											2002-11-25 12:27:11 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     os << p.get(); | 
					
						
							|  |  |  |     return os; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-25 13:52:42 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-21 14:46:45 +00:00
										 |  |  | // get_deleter (experimental)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-02-04 16:28:50 +00:00
										 |  |  | #if ( defined(__GNUC__) && BOOST_WORKAROUND(__GNUC__, < 3) ) || \
 | 
					
						
							|  |  |  |     ( defined(__EDG_VERSION__) && BOOST_WORKAROUND(__EDG_VERSION__, <= 238) ) || \ | 
					
						
							|  |  |  |     ( defined(__HP_aCC) && BOOST_WORKAROUND(__HP_aCC, <= 33500) ) | 
					
						
							| 
									
										
										
										
											2002-11-22 16:29:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // g++ 2.9x doesn't allow static_cast<X const *>(void *)
 | 
					
						
							| 
									
										
										
										
											2005-02-04 16:28:50 +00:00
										 |  |  | // apparently EDG 2.38 and HP aCC A.03.35 also don't accept it
 | 
					
						
							| 
									
										
										
										
											2002-11-22 16:29:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | template<class D, class T> D * get_deleter(shared_ptr<T> const & p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     void const * q = p._internal_get_deleter(typeid(D)); | 
					
						
							|  |  |  |     return const_cast<D *>(static_cast<D const *>(q)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-21 14:46:45 +00:00
										 |  |  | template<class D, class T> D * get_deleter(shared_ptr<T> const & p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return static_cast<D *>(p._internal_get_deleter(typeid(D))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-22 16:29:51 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | } // namespace boost
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef BOOST_MSVC
 | 
					
						
							|  |  |  | # pragma warning(pop)
 | 
					
						
							|  |  |  | #endif    
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-24 15:36:25 +00:00
										 |  |  | #endif  // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif  // #ifndef BOOST_SHARED_PTR_HPP_INCLUDED
 |