Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/smart_ptr/intrusive_ptr.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 #ifndef BOOST_SMART_PTR_INTRUSIVE_PTR_HPP_INCLUDED | |
2 #define BOOST_SMART_PTR_INTRUSIVE_PTR_HPP_INCLUDED | |
3 | |
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) | |
12 // | |
13 // See http://www.boost.org/libs/smart_ptr/intrusive_ptr.html for documentation. | |
14 // | |
15 | |
16 #include <boost/config.hpp> | |
17 | |
18 #include <boost/assert.hpp> | |
19 #include <boost/detail/workaround.hpp> | |
20 #include <boost/smart_ptr/detail/sp_convertible.hpp> | |
21 #include <boost/smart_ptr/detail/sp_nullptr_t.hpp> | |
22 | |
23 #include <boost/config/no_tr1/functional.hpp> // for std::less | |
24 | |
25 #if !defined(BOOST_NO_IOSTREAM) | |
26 #if !defined(BOOST_NO_IOSFWD) | |
27 #include <iosfwd> // for std::basic_ostream | |
28 #else | |
29 #include <ostream> | |
30 #endif | |
31 #endif | |
32 | |
33 | |
34 namespace boost | |
35 { | |
36 | |
37 // | |
38 // intrusive_ptr | |
39 // | |
40 // A smart pointer that uses intrusive reference counting. | |
41 // | |
42 // Relies on unqualified calls to | |
43 // | |
44 // void intrusive_ptr_add_ref(T * p); | |
45 // void intrusive_ptr_release(T * p); | |
46 // | |
47 // (p != 0) | |
48 // | |
49 // The object is responsible for destroying itself. | |
50 // | |
51 | |
52 template<class T> class intrusive_ptr | |
53 { | |
54 private: | |
55 | |
56 typedef intrusive_ptr this_type; | |
57 | |
58 public: | |
59 | |
60 typedef T element_type; | |
61 | |
62 intrusive_ptr() BOOST_NOEXCEPT : px( 0 ) | |
63 { | |
64 } | |
65 | |
66 intrusive_ptr( T * p, bool add_ref = true ): px( p ) | |
67 { | |
68 if( px != 0 && add_ref ) intrusive_ptr_add_ref( px ); | |
69 } | |
70 | |
71 #if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES) | |
72 | |
73 template<class U> | |
74 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE ) | |
75 | |
76 intrusive_ptr( intrusive_ptr<U> const & rhs, typename boost::detail::sp_enable_if_convertible<U,T>::type = boost::detail::sp_empty() ) | |
77 | |
78 #else | |
79 | |
80 intrusive_ptr( intrusive_ptr<U> const & rhs ) | |
81 | |
82 #endif | |
83 : px( rhs.get() ) | |
84 { | |
85 if( px != 0 ) intrusive_ptr_add_ref( px ); | |
86 } | |
87 | |
88 #endif | |
89 | |
90 intrusive_ptr(intrusive_ptr const & rhs): px( rhs.px ) | |
91 { | |
92 if( px != 0 ) intrusive_ptr_add_ref( px ); | |
93 } | |
94 | |
95 ~intrusive_ptr() | |
96 { | |
97 if( px != 0 ) intrusive_ptr_release( px ); | |
98 } | |
99 | |
100 #if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES) | |
101 | |
102 template<class U> intrusive_ptr & operator=(intrusive_ptr<U> const & rhs) | |
103 { | |
104 this_type(rhs).swap(*this); | |
105 return *this; | |
106 } | |
107 | |
108 #endif | |
109 | |
110 // Move support | |
111 | |
112 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) | |
113 | |
114 intrusive_ptr(intrusive_ptr && rhs) BOOST_NOEXCEPT : px( rhs.px ) | |
115 { | |
116 rhs.px = 0; | |
117 } | |
118 | |
119 intrusive_ptr & operator=(intrusive_ptr && rhs) BOOST_NOEXCEPT | |
120 { | |
121 this_type( static_cast< intrusive_ptr && >( rhs ) ).swap(*this); | |
122 return *this; | |
123 } | |
124 | |
125 #endif | |
126 | |
127 intrusive_ptr & operator=(intrusive_ptr const & rhs) | |
128 { | |
129 this_type(rhs).swap(*this); | |
130 return *this; | |
131 } | |
132 | |
133 intrusive_ptr & operator=(T * rhs) | |
134 { | |
135 this_type(rhs).swap(*this); | |
136 return *this; | |
137 } | |
138 | |
139 void reset() BOOST_NOEXCEPT | |
140 { | |
141 this_type().swap( *this ); | |
142 } | |
143 | |
144 void reset( T * rhs ) | |
145 { | |
146 this_type( rhs ).swap( *this ); | |
147 } | |
148 | |
149 T * get() const BOOST_NOEXCEPT | |
150 { | |
151 return px; | |
152 } | |
153 | |
154 T & operator*() const | |
155 { | |
156 BOOST_ASSERT( px != 0 ); | |
157 return *px; | |
158 } | |
159 | |
160 T * operator->() const | |
161 { | |
162 BOOST_ASSERT( px != 0 ); | |
163 return px; | |
164 } | |
165 | |
166 // implicit conversion to "bool" | |
167 #include <boost/smart_ptr/detail/operator_bool.hpp> | |
168 | |
169 void swap(intrusive_ptr & rhs) BOOST_NOEXCEPT | |
170 { | |
171 T * tmp = px; | |
172 px = rhs.px; | |
173 rhs.px = tmp; | |
174 } | |
175 | |
176 private: | |
177 | |
178 T * px; | |
179 }; | |
180 | |
181 template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b) | |
182 { | |
183 return a.get() == b.get(); | |
184 } | |
185 | |
186 template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b) | |
187 { | |
188 return a.get() != b.get(); | |
189 } | |
190 | |
191 template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, U * b) | |
192 { | |
193 return a.get() == b; | |
194 } | |
195 | |
196 template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, U * b) | |
197 { | |
198 return a.get() != b; | |
199 } | |
200 | |
201 template<class T, class U> inline bool operator==(T * a, intrusive_ptr<U> const & b) | |
202 { | |
203 return a == b.get(); | |
204 } | |
205 | |
206 template<class T, class U> inline bool operator!=(T * a, intrusive_ptr<U> const & b) | |
207 { | |
208 return a != b.get(); | |
209 } | |
210 | |
211 #if __GNUC__ == 2 && __GNUC_MINOR__ <= 96 | |
212 | |
213 // Resolve the ambiguity between our op!= and the one in rel_ops | |
214 | |
215 template<class T> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b) | |
216 { | |
217 return a.get() != b.get(); | |
218 } | |
219 | |
220 #endif | |
221 | |
222 #if !defined( BOOST_NO_CXX11_NULLPTR ) | |
223 | |
224 template<class T> inline bool operator==( intrusive_ptr<T> const & p, boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT | |
225 { | |
226 return p.get() == 0; | |
227 } | |
228 | |
229 template<class T> inline bool operator==( boost::detail::sp_nullptr_t, intrusive_ptr<T> const & p ) BOOST_NOEXCEPT | |
230 { | |
231 return p.get() == 0; | |
232 } | |
233 | |
234 template<class T> inline bool operator!=( intrusive_ptr<T> const & p, boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT | |
235 { | |
236 return p.get() != 0; | |
237 } | |
238 | |
239 template<class T> inline bool operator!=( boost::detail::sp_nullptr_t, intrusive_ptr<T> const & p ) BOOST_NOEXCEPT | |
240 { | |
241 return p.get() != 0; | |
242 } | |
243 | |
244 #endif | |
245 | |
246 template<class T> inline bool operator<(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b) | |
247 { | |
248 return std::less<T *>()(a.get(), b.get()); | |
249 } | |
250 | |
251 template<class T> void swap(intrusive_ptr<T> & lhs, intrusive_ptr<T> & rhs) | |
252 { | |
253 lhs.swap(rhs); | |
254 } | |
255 | |
256 // mem_fn support | |
257 | |
258 template<class T> T * get_pointer(intrusive_ptr<T> const & p) | |
259 { | |
260 return p.get(); | |
261 } | |
262 | |
263 template<class T, class U> intrusive_ptr<T> static_pointer_cast(intrusive_ptr<U> const & p) | |
264 { | |
265 return static_cast<T *>(p.get()); | |
266 } | |
267 | |
268 template<class T, class U> intrusive_ptr<T> const_pointer_cast(intrusive_ptr<U> const & p) | |
269 { | |
270 return const_cast<T *>(p.get()); | |
271 } | |
272 | |
273 template<class T, class U> intrusive_ptr<T> dynamic_pointer_cast(intrusive_ptr<U> const & p) | |
274 { | |
275 return dynamic_cast<T *>(p.get()); | |
276 } | |
277 | |
278 // operator<< | |
279 | |
280 #if !defined(BOOST_NO_IOSTREAM) | |
281 | |
282 #if defined(BOOST_NO_TEMPLATED_IOSTREAMS) || ( defined(__GNUC__) && (__GNUC__ < 3) ) | |
283 | |
284 template<class Y> std::ostream & operator<< (std::ostream & os, intrusive_ptr<Y> const & p) | |
285 { | |
286 os << p.get(); | |
287 return os; | |
288 } | |
289 | |
290 #else | |
291 | |
292 // in STLport's no-iostreams mode no iostream symbols can be used | |
293 #ifndef _STLP_NO_IOSTREAMS | |
294 | |
295 # if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300 && __SGI_STL_PORT) | |
296 // MSVC6 has problems finding std::basic_ostream through the using declaration in namespace _STL | |
297 using std::basic_ostream; | |
298 template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, intrusive_ptr<Y> const & p) | |
299 # else | |
300 template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, intrusive_ptr<Y> const & p) | |
301 # endif | |
302 { | |
303 os << p.get(); | |
304 return os; | |
305 } | |
306 | |
307 #endif // _STLP_NO_IOSTREAMS | |
308 | |
309 #endif // __GNUC__ < 3 | |
310 | |
311 #endif // !defined(BOOST_NO_IOSTREAM) | |
312 | |
313 // hash_value | |
314 | |
315 template< class T > struct hash; | |
316 | |
317 template< class T > std::size_t hash_value( boost::intrusive_ptr<T> const & p ) | |
318 { | |
319 return boost::hash< T* >()( p.get() ); | |
320 } | |
321 | |
322 } // namespace boost | |
323 | |
324 #endif // #ifndef BOOST_SMART_PTR_INTRUSIVE_PTR_HPP_INCLUDED |