Support unrar64.dll
[xy_vsfilter.git] / src / thirdparty / boost_1_47_0 / boost / smart_ptr / intrusive_ptr.hpp
blob911069a82b079e636d765125ab2d30fc413fd394
1 #ifndef BOOST_SMART_PTR_INTRUSIVE_PTR_HPP_INCLUDED
2 #define BOOST_SMART_PTR_INTRUSIVE_PTR_HPP_INCLUDED
4 //
5 // intrusive_ptr.hpp
6 //
7 // Copyright (c) 2001, 2002 Peter Dimov
8 //
9 // Distributed under the Boost Software License, Version 1.0. (See
10 // accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
13 // See http://www.boost.org/libs/smart_ptr/intrusive_ptr.html for documentation.
16 #include <boost/config.hpp>
18 #include <boost/assert.hpp>
19 #include <boost/detail/workaround.hpp>
20 #include <boost/smart_ptr/detail/sp_convertible.hpp>
22 #include <boost/config/no_tr1/functional.hpp> // for std::less
24 #if !defined(BOOST_NO_IOSTREAM)
25 #if !defined(BOOST_NO_IOSFWD)
26 #include <iosfwd> // for std::basic_ostream
27 #else
28 #include <ostream>
29 #endif
30 #endif
33 namespace boost
37 // intrusive_ptr
39 // A smart pointer that uses intrusive reference counting.
41 // Relies on unqualified calls to
42 //
43 // void intrusive_ptr_add_ref(T * p);
44 // void intrusive_ptr_release(T * p);
46 // (p != 0)
48 // The object is responsible for destroying itself.
51 template<class T> class intrusive_ptr
53 private:
55 typedef intrusive_ptr this_type;
57 public:
59 typedef T element_type;
61 intrusive_ptr(): px( 0 )
65 intrusive_ptr( T * p, bool add_ref = true ): px( p )
67 if( px != 0 && add_ref ) intrusive_ptr_add_ref( px );
70 #if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
72 template<class U>
73 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
75 intrusive_ptr( intrusive_ptr<U> const & rhs, typename boost::detail::sp_enable_if_convertible<U,T>::type = boost::detail::sp_empty() )
77 #else
79 intrusive_ptr( intrusive_ptr<U> const & rhs )
81 #endif
82 : px( rhs.get() )
84 if( px != 0 ) intrusive_ptr_add_ref( px );
87 #endif
89 intrusive_ptr(intrusive_ptr const & rhs): px( rhs.px )
91 if( px != 0 ) intrusive_ptr_add_ref( px );
94 ~intrusive_ptr()
96 if( px != 0 ) intrusive_ptr_release( px );
99 #if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
101 template<class U> intrusive_ptr & operator=(intrusive_ptr<U> const & rhs)
103 this_type(rhs).swap(*this);
104 return *this;
107 #endif
109 // Move support
111 #if defined( BOOST_HAS_RVALUE_REFS )
113 intrusive_ptr(intrusive_ptr && rhs): px( rhs.px )
115 rhs.px = 0;
118 intrusive_ptr & operator=(intrusive_ptr && rhs)
120 this_type( static_cast< intrusive_ptr && >( rhs ) ).swap(*this);
121 return *this;
124 #endif
126 intrusive_ptr & operator=(intrusive_ptr const & rhs)
128 this_type(rhs).swap(*this);
129 return *this;
132 intrusive_ptr & operator=(T * rhs)
134 this_type(rhs).swap(*this);
135 return *this;
138 void reset()
140 this_type().swap( *this );
143 void reset( T * rhs )
145 this_type( rhs ).swap( *this );
148 T * get() const
150 return px;
153 T & operator*() const
155 BOOST_ASSERT( px != 0 );
156 return *px;
159 T * operator->() const
161 BOOST_ASSERT( px != 0 );
162 return px;
165 // implicit conversion to "bool"
166 #include <boost/smart_ptr/detail/operator_bool.hpp>
168 void swap(intrusive_ptr & rhs)
170 T * tmp = px;
171 px = rhs.px;
172 rhs.px = tmp;
175 private:
177 T * px;
180 template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b)
182 return a.get() == b.get();
185 template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b)
187 return a.get() != b.get();
190 template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, U * b)
192 return a.get() == b;
195 template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, U * b)
197 return a.get() != b;
200 template<class T, class U> inline bool operator==(T * a, intrusive_ptr<U> const & b)
202 return a == b.get();
205 template<class T, class U> inline bool operator!=(T * a, intrusive_ptr<U> const & b)
207 return a != b.get();
210 #if __GNUC__ == 2 && __GNUC_MINOR__ <= 96
212 // Resolve the ambiguity between our op!= and the one in rel_ops
214 template<class T> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b)
216 return a.get() != b.get();
219 #endif
221 template<class T> inline bool operator<(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b)
223 return std::less<T *>()(a.get(), b.get());
226 template<class T> void swap(intrusive_ptr<T> & lhs, intrusive_ptr<T> & rhs)
228 lhs.swap(rhs);
231 // mem_fn support
233 template<class T> T * get_pointer(intrusive_ptr<T> const & p)
235 return p.get();
238 template<class T, class U> intrusive_ptr<T> static_pointer_cast(intrusive_ptr<U> const & p)
240 return static_cast<T *>(p.get());
243 template<class T, class U> intrusive_ptr<T> const_pointer_cast(intrusive_ptr<U> const & p)
245 return const_cast<T *>(p.get());
248 template<class T, class U> intrusive_ptr<T> dynamic_pointer_cast(intrusive_ptr<U> const & p)
250 return dynamic_cast<T *>(p.get());
253 // operator<<
255 #if !defined(BOOST_NO_IOSTREAM)
257 #if defined(BOOST_NO_TEMPLATED_IOSTREAMS) || ( defined(__GNUC__) && (__GNUC__ < 3) )
259 template<class Y> std::ostream & operator<< (std::ostream & os, intrusive_ptr<Y> const & p)
261 os << p.get();
262 return os;
265 #else
267 // in STLport's no-iostreams mode no iostream symbols can be used
268 #ifndef _STLP_NO_IOSTREAMS
270 # if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300 && __SGI_STL_PORT)
271 // MSVC6 has problems finding std::basic_ostream through the using declaration in namespace _STL
272 using std::basic_ostream;
273 template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, intrusive_ptr<Y> const & p)
274 # else
275 template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, intrusive_ptr<Y> const & p)
276 # endif
278 os << p.get();
279 return os;
282 #endif // _STLP_NO_IOSTREAMS
284 #endif // __GNUC__ < 3
286 #endif // !defined(BOOST_NO_IOSTREAM)
288 } // namespace boost
290 #endif // #ifndef BOOST_SMART_PTR_INTRUSIVE_PTR_HPP_INCLUDED