| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | #ifndef BOOST_DETAIL_SHARED_COUNT_HPP_INCLUDED
 | 
					
						
							|  |  |  | #define BOOST_DETAIL_SHARED_COUNT_HPP_INCLUDED
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-11-28 15:35:21 +00:00
										 |  |  | // MS compatible compilers support #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 17:09:24 +00:00
										 |  |  | #if defined(_MSC_VER) && (_MSC_VER >= 1020)
 | 
					
						
							|  |  |  | # pragma once
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  detail/shared_count.hpp
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2003-01-13 18:32:16 +00:00
										 |  |  | //  Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
 | 
					
						
							| 
									
										
										
										
											2005-03-17 22:45:11 +00:00
										 |  |  | //  Copyright 2004-2005 Peter Dimov
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2004-07-26 00:32:12 +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
										 |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-30 21:49:40 +00:00
										 |  |  | #ifdef __BORLANDC__
 | 
					
						
							|  |  |  | # pragma warn -8027     // Functions containing try are not expanded inline
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-02-01 18:40:35 +00:00
										 |  |  | #include <boost/config.hpp>
 | 
					
						
							|  |  |  | #include <boost/checked_delete.hpp>
 | 
					
						
							| 
									
										
										
										
											2002-08-14 12:27:22 +00:00
										 |  |  | #include <boost/throw_exception.hpp>
 | 
					
						
							| 
									
										
										
										
											2005-03-17 22:45:11 +00:00
										 |  |  | #include <boost/detail/bad_weak_ptr.hpp>
 | 
					
						
							|  |  |  | #include <boost/detail/sp_counted_base.hpp>
 | 
					
						
							| 
									
										
										
										
											2005-03-17 23:05:26 +00:00
										 |  |  | #include <boost/detail/sp_counted_impl.hpp>
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-11 21:06:08 +00:00
										 |  |  | #include <memory>           // std::auto_ptr
 | 
					
						
							| 
									
										
										
										
											2003-01-30 14:20:22 +00:00
										 |  |  | #include <functional>       // std::less
 | 
					
						
							|  |  |  | #include <new>              // std::bad_alloc
 | 
					
						
							|  |  |  | #include <typeinfo>         // std::type_info in get_deleter
 | 
					
						
							| 
									
										
										
										
											2002-02-09 12:34:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | namespace boost | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-18 14:37:02 +00:00
										 |  |  | namespace detail | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-10 12:54:43 +00:00
										 |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							| 
									
										
										
										
											2002-11-19 16:11:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-07 15:34:56 +00:00
										 |  |  | int const shared_count_id = 0x2C35F101; | 
					
						
							|  |  |  | int const   weak_count_id = 0x298C38A4; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-02-14 23:08:30 +00:00
										 |  |  | class weak_count; | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class shared_count | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-14 15:13:53 +00:00
										 |  |  |     sp_counted_base * pi_; | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-10 12:54:43 +00:00
										 |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							| 
									
										
										
										
											2003-01-07 15:34:56 +00:00
										 |  |  |     int id_; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     friend class weak_count; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-19 16:11:21 +00:00
										 |  |  |     shared_count(): pi_(0) // nothrow
 | 
					
						
							| 
									
										
										
										
											2003-02-10 12:54:43 +00:00
										 |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							| 
									
										
										
										
											2003-01-07 15:34:56 +00:00
										 |  |  |         , id_(shared_count_id) | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-02-15 13:31:58 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-17 23:30:47 +00:00
										 |  |  |     template<class Y> explicit shared_count( Y * p ): pi_( 0 ) | 
					
						
							|  |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							|  |  |  |         , id_(shared_count_id) | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  | #ifndef BOOST_NO_EXCEPTIONS
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         try | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             pi_ = new sp_counted_impl_p<Y>( p ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         catch(...) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             boost::checked_delete( p ); | 
					
						
							|  |  |  |             throw; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         pi_ = new sp_counted_impl_p<Y>( p ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if( pi_ == 0 ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             boost::checked_delete( p ); | 
					
						
							|  |  |  |             boost::throw_exception( std::bad_alloc() ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-18 14:37:02 +00:00
										 |  |  |     template<class P, class D> shared_count(P p, D d): pi_(0) | 
					
						
							| 
									
										
										
										
											2003-02-10 12:54:43 +00:00
										 |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							| 
									
										
										
										
											2003-01-07 15:34:56 +00:00
										 |  |  |         , id_(shared_count_id) | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-08-14 12:27:22 +00:00
										 |  |  | #ifndef BOOST_NO_EXCEPTIONS
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |         try | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2005-03-17 23:05:26 +00:00
										 |  |  |             pi_ = new sp_counted_impl_pd<P, D>(p, d); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         catch(...) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             d(p); // delete p
 | 
					
						
							|  |  |  |             throw; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2002-08-14 12:27:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-17 23:05:26 +00:00
										 |  |  |         pi_ = new sp_counted_impl_pd<P, D>(p, d); | 
					
						
							| 
									
										
										
										
											2002-08-14 12:27:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if(pi_ == 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             d(p); // delete p
 | 
					
						
							|  |  |  |             boost::throw_exception(std::bad_alloc()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-09 20:05:42 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template<class P, class D, class A> shared_count( P p, D d, A a ): pi_( 0 ) | 
					
						
							|  |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							|  |  |  |         , id_(shared_count_id) | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         typedef sp_counted_impl_pda<P, D, A> impl_type; | 
					
						
							|  |  |  |         typedef typename A::template rebind< impl_type >::other A2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         A2 a2( a ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef BOOST_NO_EXCEPTIONS
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         try | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             pi_ = a2.allocate( 1, static_cast< impl_type* >( 0 ) ); | 
					
						
							|  |  |  |             new( static_cast< void* >( pi_ ) ) impl_type( p, d, a ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         catch(...) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             d( p ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if( pi_ != 0 ) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 a2.deallocate( static_cast< impl_type* >( pi_ ), 1 ); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             throw; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         pi_ = a2.allocate( 1, static_cast< impl_type* >( 0 ) ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if( pi_ != 0 ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             new( static_cast< void* >( pi_ ) ) impl_type( p, d, a ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             d( p ); | 
					
						
							|  |  |  |             boost::throw_exception( std::bad_alloc() ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-08-14 12:27:22 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-02-01 18:40:35 +00:00
										 |  |  | #ifndef BOOST_NO_AUTO_PTR
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // auto_ptr<Y> is special cased to provide the strong guarantee
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  |     template<class Y> | 
					
						
							| 
									
										
										
										
											2005-03-17 23:30:47 +00:00
										 |  |  |     explicit shared_count( std::auto_ptr<Y> & r ): pi_( new sp_counted_impl_p<Y>( r.get() ) ) | 
					
						
							| 
									
										
										
										
											2003-02-10 12:54:43 +00:00
										 |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							| 
									
										
										
										
											2003-01-07 15:34:56 +00:00
										 |  |  |         , id_(shared_count_id) | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-02-01 18:40:35 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2005-03-17 23:30:47 +00:00
										 |  |  | #ifdef BOOST_NO_EXCEPTIONS
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if( pi_ == 0 ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             boost::throw_exception(std::bad_alloc()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-02-01 18:40:35 +00:00
										 |  |  |         r.release(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     ~shared_count() // nothrow
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2005-03-17 23:30:47 +00:00
										 |  |  |         if( pi_ != 0 ) pi_->release(); | 
					
						
							| 
									
										
										
										
											2003-02-10 12:54:43 +00:00
										 |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							| 
									
										
										
										
											2003-01-27 14:02:00 +00:00
										 |  |  |         id_ = 0; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     shared_count(shared_count const & r): pi_(r.pi_) // nothrow
 | 
					
						
							| 
									
										
										
										
											2003-02-10 12:54:43 +00:00
										 |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							| 
									
										
										
										
											2003-01-07 15:34:56 +00:00
										 |  |  |         , id_(shared_count_id) | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2005-03-17 23:30:47 +00:00
										 |  |  |         if( pi_ != 0 ) pi_->add_ref_copy(); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-18 14:37:02 +00:00
										 |  |  |     explicit shared_count(weak_count const & r); // throws bad_weak_ptr when r.use_count() == 0
 | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     shared_count & operator= (shared_count const & r) // nothrow
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-01-14 15:13:53 +00:00
										 |  |  |         sp_counted_base * tmp = r.pi_; | 
					
						
							| 
									
										
										
										
											2004-02-10 23:17:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-17 23:30:47 +00:00
										 |  |  |         if( tmp != pi_ ) | 
					
						
							| 
									
										
										
										
											2004-02-10 23:17:12 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2005-03-17 23:30:47 +00:00
										 |  |  |             if( tmp != 0 ) tmp->add_ref_copy(); | 
					
						
							|  |  |  |             if( pi_ != 0 ) pi_->release(); | 
					
						
							| 
									
										
										
										
											2004-02-10 23:17:12 +00:00
										 |  |  |             pi_ = tmp; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return *this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void swap(shared_count & r) // nothrow
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-01-14 15:13:53 +00:00
										 |  |  |         sp_counted_base * tmp = r.pi_; | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |         r.pi_ = pi_; | 
					
						
							|  |  |  |         pi_ = tmp; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     long use_count() const // nothrow
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-01-13 18:32:16 +00:00
										 |  |  |         return pi_ != 0? pi_->use_count(): 0; | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool unique() const // nothrow
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-11-18 14:37:02 +00:00
										 |  |  |         return use_count() == 1; | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2002-02-09 12:34:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     friend inline bool operator==(shared_count const & a, shared_count const & b) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return a.pi_ == b.pi_; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     friend inline bool operator<(shared_count const & a, shared_count const & b) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2005-03-17 23:30:47 +00:00
										 |  |  |         return std::less<sp_counted_base *>()( a.pi_, b.pi_ ); | 
					
						
							| 
									
										
										
										
											2002-02-09 12:34:05 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2002-11-21 14:46:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void * get_deleter(std::type_info const & ti) const | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2005-03-17 23:30:47 +00:00
										 |  |  |         return pi_? pi_->get_deleter( ti ): 0; | 
					
						
							| 
									
										
										
										
											2002-11-21 14:46:45 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-08-20 11:08:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | class weak_count | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-14 15:13:53 +00:00
										 |  |  |     sp_counted_base * pi_; | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-10 12:54:43 +00:00
										 |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							| 
									
										
										
										
											2003-01-07 15:34:56 +00:00
										 |  |  |     int id_; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  |     friend class shared_count; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-19 16:11:21 +00:00
										 |  |  |     weak_count(): pi_(0) // nothrow
 | 
					
						
							| 
									
										
										
										
											2003-02-10 12:54:43 +00:00
										 |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							| 
									
										
										
										
											2003-01-07 15:34:56 +00:00
										 |  |  |         , id_(weak_count_id) | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     weak_count(shared_count const & r): pi_(r.pi_) // nothrow
 | 
					
						
							| 
									
										
										
										
											2003-02-10 12:54:43 +00:00
										 |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							| 
									
										
										
										
											2003-01-07 15:34:56 +00:00
										 |  |  |         , id_(shared_count_id) | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-11-18 14:37:02 +00:00
										 |  |  |         if(pi_ != 0) pi_->weak_add_ref(); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     weak_count(weak_count const & r): pi_(r.pi_) // nothrow
 | 
					
						
							| 
									
										
										
										
											2003-02-10 12:54:43 +00:00
										 |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							| 
									
										
										
										
											2003-01-07 15:34:56 +00:00
										 |  |  |         , id_(shared_count_id) | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-11-18 14:37:02 +00:00
										 |  |  |         if(pi_ != 0) pi_->weak_add_ref(); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ~weak_count() // nothrow
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-11-18 14:37:02 +00:00
										 |  |  |         if(pi_ != 0) pi_->weak_release(); | 
					
						
							| 
									
										
										
										
											2003-02-10 12:54:43 +00:00
										 |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							| 
									
										
										
										
											2003-01-27 14:02:00 +00:00
										 |  |  |         id_ = 0; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     weak_count & operator= (shared_count const & r) // nothrow
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-01-14 15:13:53 +00:00
										 |  |  |         sp_counted_base * tmp = r.pi_; | 
					
						
							| 
									
										
										
										
											2002-11-18 14:37:02 +00:00
										 |  |  |         if(tmp != 0) tmp->weak_add_ref(); | 
					
						
							|  |  |  |         if(pi_ != 0) pi_->weak_release(); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |         pi_ = tmp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return *this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     weak_count & operator= (weak_count const & r) // nothrow
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-01-14 15:13:53 +00:00
										 |  |  |         sp_counted_base * tmp = r.pi_; | 
					
						
							| 
									
										
										
										
											2002-11-18 14:37:02 +00:00
										 |  |  |         if(tmp != 0) tmp->weak_add_ref(); | 
					
						
							|  |  |  |         if(pi_ != 0) pi_->weak_release(); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |         pi_ = tmp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return *this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void swap(weak_count & r) // nothrow
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-01-14 15:13:53 +00:00
										 |  |  |         sp_counted_base * tmp = r.pi_; | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |         r.pi_ = pi_; | 
					
						
							|  |  |  |         pi_ = tmp; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     long use_count() const // nothrow
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-11-21 13:14:04 +00:00
										 |  |  |         return pi_ != 0? pi_->use_count(): 0; | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2002-02-09 12:34:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     friend inline bool operator==(weak_count const & a, weak_count const & b) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return a.pi_ == b.pi_; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     friend inline bool operator<(weak_count const & a, weak_count const & b) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-01-14 15:13:53 +00:00
										 |  |  |         return std::less<sp_counted_base *>()(a.pi_, b.pi_); | 
					
						
							| 
									
										
										
										
											2002-02-09 12:34:05 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-17 23:30:47 +00:00
										 |  |  | inline shared_count::shared_count( weak_count const & r ): pi_( r.pi_ ) | 
					
						
							| 
									
										
										
										
											2003-02-10 12:54:43 +00:00
										 |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							| 
									
										
										
										
											2003-01-07 15:34:56 +00:00
										 |  |  |         , id_(shared_count_id) | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-17 22:45:11 +00:00
										 |  |  |     if( pi_ == 0 || !pi_->add_ref_lock() ) | 
					
						
							| 
									
										
										
										
											2002-11-21 13:14:04 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2005-03-17 22:45:11 +00:00
										 |  |  |         boost::throw_exception( boost::bad_weak_ptr() ); | 
					
						
							| 
									
										
										
										
											2002-11-21 13:14:04 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | } // namespace detail
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace boost
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-09 12:06:46 +00:00
										 |  |  | #ifdef __BORLANDC__
 | 
					
						
							|  |  |  | # pragma warn .8027     // Functions containing try are not expanded inline
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | #endif  // #ifndef BOOST_DETAIL_SHARED_COUNT_HPP_INCLUDED
 |