| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | #ifndef BOOST_SMART_PTR_INTRUSIVE_PTR_HPP_INCLUDED
 | 
					
						
							|  |  |  | #define BOOST_SMART_PTR_INTRUSIVE_PTR_HPP_INCLUDED
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  intrusive_ptr.hpp
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Copyright (c) 2001, 2002 Peter Dimov
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // 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)
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  See http://www.boost.org/libs/smart_ptr/intrusive_ptr.html for documentation.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/config.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/assert.hpp>
 | 
					
						
							|  |  |  | #include <boost/detail/workaround.hpp>
 | 
					
						
							|  |  |  | #include <boost/smart_ptr/detail/sp_convertible.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/config/no_tr1/functional.hpp>           // for std::less
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if !defined(BOOST_NO_IOSTREAM)
 | 
					
						
							|  |  |  | #if !defined(BOOST_NO_IOSFWD)
 | 
					
						
							|  |  |  | #include <iosfwd>               // for std::basic_ostream
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #include <ostream>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace boost | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  intrusive_ptr
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  A smart pointer that uses intrusive reference counting.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Relies on unqualified calls to
 | 
					
						
							|  |  |  | //  
 | 
					
						
							|  |  |  | //      void intrusive_ptr_add_ref(T * p);
 | 
					
						
							|  |  |  | //      void intrusive_ptr_release(T * p);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //          (p != 0)
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  The object is responsible for destroying itself.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T> class intrusive_ptr | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     typedef intrusive_ptr this_type; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     typedef T element_type; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-21 15:38:06 +00:00
										 |  |  |     intrusive_ptr() BOOST_NOEXCEPT : px( 0 ) | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |     intrusive_ptr( T * p, bool add_ref = true ): px( p ) | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |         if( px != 0 && add_ref ) intrusive_ptr_add_ref( px ); | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template<class U> | 
					
						
							|  |  |  | #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-14 17:44:19 +00:00
										 |  |  |     intrusive_ptr( intrusive_ptr<U> const & rhs, typename boost::detail::sp_enable_if_convertible<U,T>::type = boost::detail::sp_empty() ) | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     intrusive_ptr( intrusive_ptr<U> const & rhs ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |     : px( rhs.get() ) | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |         if( px != 0 ) intrusive_ptr_add_ref( px ); | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |     intrusive_ptr(intrusive_ptr const & rhs): px( rhs.px ) | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |         if( px != 0 ) intrusive_ptr_add_ref( px ); | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ~intrusive_ptr() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |         if( px != 0 ) intrusive_ptr_release( px ); | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template<class U> intrusive_ptr & operator=(intrusive_ptr<U> const & rhs) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         this_type(rhs).swap(*this); | 
					
						
							|  |  |  |         return *this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-08 23:21:15 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Move support
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-15 20:20:20 +00:00
										 |  |  | #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
 | 
					
						
							| 
									
										
										
										
											2009-08-08 23:21:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-21 15:38:06 +00:00
										 |  |  |     intrusive_ptr(intrusive_ptr && rhs) BOOST_NOEXCEPT : px( rhs.px ) | 
					
						
							| 
									
										
										
										
											2009-08-08 23:21:15 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         rhs.px = 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-21 15:38:06 +00:00
										 |  |  |     intrusive_ptr & operator=(intrusive_ptr && rhs) BOOST_NOEXCEPT | 
					
						
							| 
									
										
										
										
											2009-08-08 23:21:15 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-11-30 20:34:39 +00:00
										 |  |  |         this_type( static_cast< intrusive_ptr && >( rhs ) ).swap(*this); | 
					
						
							| 
									
										
										
										
											2009-08-08 23:21:15 +00:00
										 |  |  |         return *this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     intrusive_ptr & operator=(intrusive_ptr const & rhs) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         this_type(rhs).swap(*this); | 
					
						
							|  |  |  |         return *this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     intrusive_ptr & operator=(T * rhs) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         this_type(rhs).swap(*this); | 
					
						
							|  |  |  |         return *this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-21 15:38:06 +00:00
										 |  |  |     void reset() BOOST_NOEXCEPT | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         this_type().swap( *this ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void reset( T * rhs ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         this_type( rhs ).swap( *this ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-21 15:38:06 +00:00
										 |  |  |     T * get() const BOOST_NOEXCEPT | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |         return px; | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     T & operator*() const | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |         BOOST_ASSERT( px != 0 ); | 
					
						
							|  |  |  |         return *px; | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     T * operator->() const | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |         BOOST_ASSERT( px != 0 ); | 
					
						
							|  |  |  |         return px; | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  | // implicit conversion to "bool"
 | 
					
						
							|  |  |  | #include <boost/smart_ptr/detail/operator_bool.hpp>
 | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-21 15:38:06 +00:00
										 |  |  |     void swap(intrusive_ptr & rhs) BOOST_NOEXCEPT | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |         T * tmp = px; | 
					
						
							|  |  |  |         px = rhs.px; | 
					
						
							|  |  |  |         rhs.px = tmp; | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |     T * px; | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return a.get() == b.get(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return a.get() != b.get(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, U * b) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return a.get() == b; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, U * b) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return a.get() != b; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T, class U> inline bool operator==(T * a, intrusive_ptr<U> const & b) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return a == b.get(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T, class U> inline bool operator!=(T * a, intrusive_ptr<U> const & b) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return a != b.get(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if __GNUC__ == 2 && __GNUC_MINOR__ <= 96
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Resolve the ambiguity between our op!= and the one in rel_ops
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return a.get() != b.get(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-11 18:35:21 +00:00
										 |  |  | #if !defined( BOOST_NO_CXX11_NULLPTR )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T> inline bool operator==( intrusive_ptr<T> const & p, std::nullptr_t ) BOOST_NOEXCEPT | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return p.get() == 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T> inline bool operator==( std::nullptr_t, intrusive_ptr<T> const & p ) BOOST_NOEXCEPT | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return p.get() == 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T> inline bool operator!=( intrusive_ptr<T> const & p, std::nullptr_t ) BOOST_NOEXCEPT | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return p.get() != 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T> inline bool operator!=( std::nullptr_t, intrusive_ptr<T> const & p ) BOOST_NOEXCEPT | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return p.get() != 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | template<class T> inline bool operator<(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return std::less<T *>()(a.get(), b.get()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T> void swap(intrusive_ptr<T> & lhs, intrusive_ptr<T> & rhs) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     lhs.swap(rhs); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // mem_fn support
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T> T * get_pointer(intrusive_ptr<T> const & p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return p.get(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T, class U> intrusive_ptr<T> static_pointer_cast(intrusive_ptr<U> const & p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return static_cast<T *>(p.get()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T, class U> intrusive_ptr<T> const_pointer_cast(intrusive_ptr<U> const & p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return const_cast<T *>(p.get()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T, class U> intrusive_ptr<T> dynamic_pointer_cast(intrusive_ptr<U> const & p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return dynamic_cast<T *>(p.get()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // operator<<
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if !defined(BOOST_NO_IOSTREAM)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined(BOOST_NO_TEMPLATED_IOSTREAMS) || ( defined(__GNUC__) &&  (__GNUC__ < 3) )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class Y> std::ostream & operator<< (std::ostream & os, intrusive_ptr<Y> const & p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     os << p.get(); | 
					
						
							|  |  |  |     return os; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // in STLport's no-iostreams mode no iostream symbols can be used
 | 
					
						
							|  |  |  | #ifndef _STLP_NO_IOSTREAMS
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300 && __SGI_STL_PORT)
 | 
					
						
							|  |  |  | // 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, intrusive_ptr<Y> const & p) | 
					
						
							|  |  |  | # else
 | 
					
						
							|  |  |  | template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, intrusive_ptr<Y> const & p) | 
					
						
							|  |  |  | # endif 
 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     os << p.get(); | 
					
						
							|  |  |  |     return os; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // _STLP_NO_IOSTREAMS
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // __GNUC__ < 3
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // !defined(BOOST_NO_IOSTREAM)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-30 18:01:02 +00:00
										 |  |  | // hash_value
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template< class T > struct hash; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template< class T > std::size_t hash_value( boost::intrusive_ptr<T> const & p ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return boost::hash< T* >()( p.get() ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | } // namespace boost
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif  // #ifndef BOOST_SMART_PTR_INTRUSIVE_PTR_HPP_INCLUDED
 |