| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  | #ifndef BOOST_INTRUSIVE_PTR_HPP_INCLUDED
 | 
					
						
							|  |  |  | #define BOOST_INTRUSIVE_PTR_HPP_INCLUDED
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  intrusive_ptr.hpp
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Copyright (c) 2001, 2002 Peter Dimov
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											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-04-19 19:34:16 +00:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  See http://www.boost.org/libs/smart_ptr/intrusive_ptr.html for documentation.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-11 17:03:56 +00:00
										 |  |  | #include <boost/config.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +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-04-22 09:37:08 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-21 17:21:24 +00:00
										 |  |  | #include <boost/assert.hpp>
 | 
					
						
							|  |  |  | #include <boost/detail/workaround.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <functional>           // for std::less
 | 
					
						
							|  |  |  | #include <iosfwd>               // for std::basic_ostream
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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);
 | 
					
						
							| 
									
										
										
										
											2002-05-01 11:22:22 +00:00
										 |  |  | //
 | 
					
						
							|  |  |  | //          (p != 0)
 | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  The object is responsible for destroying itself.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T> class intrusive_ptr | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     typedef intrusive_ptr this_type; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-15 19:44:48 +00:00
										 |  |  |     typedef T element_type; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  |     intrusive_ptr(): p_(0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-21 17:21:24 +00:00
										 |  |  |     intrusive_ptr(T * p, bool add_ref = true): p_(p) | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-01-21 17:21:24 +00:00
										 |  |  |         if(p_ != 0 && add_ref) intrusive_ptr_add_ref(p_); | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-24 15:36:25 +00:00
										 |  |  | #if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
 | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     template<class U> intrusive_ptr(intrusive_ptr<U> const & rhs): p_(rhs.get()) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-05-01 11:22:22 +00:00
										 |  |  |         if(p_ != 0) intrusive_ptr_add_ref(p_); | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     intrusive_ptr(intrusive_ptr const & rhs): p_(rhs.p_) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-05-01 11:22:22 +00:00
										 |  |  |         if(p_ != 0) intrusive_ptr_add_ref(p_); | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-21 17:21:24 +00:00
										 |  |  |     ~intrusive_ptr() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if(p_ != 0) intrusive_ptr_release(p_); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-24 15:36:25 +00:00
										 |  |  | #if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
 | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     template<class U> intrusive_ptr & operator=(intrusive_ptr<U> const & rhs) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         this_type(rhs).swap(*this); | 
					
						
							|  |  |  |         return *this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #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; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     T * get() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return p_; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     T & operator*() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return *p_; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     T * operator->() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return p_; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 p_ != 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-09 14:14:26 +00:00
										 |  |  | #elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
 | 
					
						
							|  |  |  |     typedef T * (this_type::*unspecified_bool_type)() const; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     operator unspecified_bool_type() const // never throws
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return p_ == 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; | 
					
						
							| 
									
										
										
										
											2003-01-21 17:21:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     operator unspecified_bool_type () const | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-10-01 11:12:15 +00:00
										 |  |  |         return p_ == 0? 0: &this_type::p_; | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-16 12:11:17 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-22 15:22:30 +00:00
										 |  |  |     // operator! is a Borland-specific workaround
 | 
					
						
							|  |  |  |     bool operator! () const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return p_ == 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-21 17:21:24 +00:00
										 |  |  |     void swap(intrusive_ptr & rhs) | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-01-21 17:21:24 +00:00
										 |  |  |         T * tmp = p_; | 
					
						
							|  |  |  |         p_ = rhs.p_; | 
					
						
							|  |  |  |         rhs.p_ = tmp; | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     T * p_; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-25 21:27:00 +00:00
										 |  |  | template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, U * b) | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return a.get() == b; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-25 21:27:00 +00:00
										 |  |  | template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, U * b) | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return a.get() != b; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-25 21:27:00 +00:00
										 |  |  | template<class T, class U> inline bool operator==(T * a, intrusive_ptr<U> const & b) | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return a == b.get(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-25 21:27:00 +00:00
										 |  |  | template<class T, class U> inline bool operator!=(T * a, intrusive_ptr<U> const & b) | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return a != b.get(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-22 15:22:30 +00:00
										 |  |  | #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
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-21 17:21:24 +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); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  | // mem_fn support
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T> T * get_pointer(intrusive_ptr<T> const & p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return p.get(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-21 17:21:24 +00:00
										 |  |  | template<class T, class U> intrusive_ptr<T> static_pointer_cast(intrusive_ptr<U> const & p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return static_cast<T *>(p.get()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-16 11:51:12 +00:00
										 |  |  | template<class T, class U> intrusive_ptr<T> const_pointer_cast(intrusive_ptr<U> const & p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return const_cast<T *>(p.get()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-21 17:21:24 +00:00
										 |  |  | 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(__GNUC__) &&  (__GNUC__ < 3)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class Y> std::ostream & operator<< (std::ostream & os, intrusive_ptr<Y> const & p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     os << p.get(); | 
					
						
							|  |  |  |     return os; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-06 17:25:59 +00:00
										 |  |  | // in STLport's no-iostreams mode no iostream symbols can be used
 | 
					
						
							|  |  |  | #ifndef _STLP_NO_IOSTREAMS
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-25 16:27:28 +00:00
										 |  |  | # if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300 && __SGI_STL_PORT)
 | 
					
						
							| 
									
										
										
										
											2003-01-21 17:21:24 +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, 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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-06 17:25:59 +00:00
										 |  |  | #endif // _STLP_NO_IOSTREAMS
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // __GNUC__ < 3
 | 
					
						
							| 
									
										
										
										
											2003-01-21 17:21:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-19 19:34:16 +00:00
										 |  |  | } // namespace boost
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef BOOST_MSVC
 | 
					
						
							|  |  |  | # pragma warning(pop)
 | 
					
						
							|  |  |  | #endif    
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif  // #ifndef BOOST_INTRUSIVE_PTR_HPP_INCLUDED
 |