1 _slist.h |
1 /* |
|
2 * |
|
3 * Copyright (c) 1996,1997 |
|
4 * Silicon Graphics Computer Systems, Inc. |
|
5 * |
|
6 * Copyright (c) 1997 |
|
7 * Moscow Center for SPARC Technology |
|
8 * |
|
9 * Copyright (c) 1999 |
|
10 * Boris Fomitchev |
|
11 * |
|
12 * This material is provided "as is", with absolutely no warranty expressed |
|
13 * or implied. Any use is at your own risk. |
|
14 * |
|
15 * Permission to use or copy this software for any purpose is hereby granted |
|
16 * without fee, provided the above notices are retained on all copies. |
|
17 * Permission to modify the code and to distribute modified code is granted, |
|
18 * provided the above notices are retained, and a notice that the code was |
|
19 * modified is included with the above copyright notice. |
|
20 * |
|
21 */ |
|
22 |
|
23 /* NOTE: This is an internal header file, included by other STL headers. |
|
24 * You should not attempt to use it directly. |
|
25 */ |
|
26 |
|
27 #ifndef _STLP_INTERNAL_DBG_SLIST_H |
|
28 #define _STLP_INTERNAL_DBG_SLIST_H |
|
29 |
|
30 #include <stl/debug/_iterator.h> |
|
31 |
|
32 # ifndef _STLP_USE_WRAPPER_FOR_ALLOC_PARAM |
|
33 # undef _DBG_slist |
|
34 # define _DBG_slist slist |
|
35 # endif |
|
36 |
|
37 # define _STLP_DBG_SLIST_BASE __WORKAROUND_DBG_RENAME(slist) <_Tp, _Alloc> |
|
38 |
|
39 _STLP_BEGIN_NAMESPACE |
|
40 |
|
41 # ifdef _STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS |
|
42 template <class _Tp, class _Alloc> |
|
43 inline _Tp* |
|
44 value_type(const _DBG_iter_base< _STLP_DBG_SLIST_BASE >&) { |
|
45 return (_Tp*)0; |
|
46 } |
|
47 |
|
48 template <class _Tp, class _Alloc> |
|
49 inline forward_iterator_tag |
|
50 iterator_category(const _DBG_iter_base< _STLP_DBG_SLIST_BASE >&) { |
|
51 return forward_iterator_tag(); |
|
52 } |
|
53 # endif |
|
54 |
|
55 template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) > |
|
56 class _DBG_slist : public _STLP_DBG_SLIST_BASE |
|
57 { |
|
58 private: |
|
59 typedef _STLP_DBG_SLIST_BASE _Base; |
|
60 typedef _DBG_slist<_Tp,_Alloc> _Self; |
|
61 |
|
62 public: |
|
63 |
|
64 __IMPORT_CONTAINER_TYPEDEFS(_Base) |
|
65 |
|
66 typedef _DBG_iter<_Base, _Nonconst_traits<value_type> > iterator; |
|
67 typedef _DBG_iter<_Base, _Const_traits<value_type> > const_iterator; |
|
68 |
|
69 protected: |
|
70 friend class __owned_link; |
|
71 mutable __owned_list _M_iter_list; |
|
72 void _Invalidate_all() { _M_iter_list._Invalidate_all();} |
|
73 void _Invalidate_iterator(const iterator& __it) {__invalidate_iterator(&_M_iter_list, __it); } |
|
74 |
|
75 public: |
|
76 const _Base* _Get_base() const { return (const _Base*)this; } |
|
77 _Base* _Get_base() { return (_Base*)this; } |
|
78 |
|
79 public: |
|
80 |
|
81 explicit _DBG_slist(const allocator_type& __a = allocator_type()) : |
|
82 _STLP_DBG_SLIST_BASE(__a) , _M_iter_list(_Get_base()) {} |
|
83 |
|
84 _DBG_slist(size_type __n, const value_type& __x, |
|
85 const allocator_type& __a = allocator_type()) : |
|
86 _STLP_DBG_SLIST_BASE(__n, __x, __a), _M_iter_list(_Get_base()) {} |
|
87 |
|
88 explicit _DBG_slist(size_type __n) : _STLP_DBG_SLIST_BASE(__n) , _M_iter_list(_Get_base()) {} |
|
89 |
|
90 #ifdef _STLP_MEMBER_TEMPLATES |
|
91 // We don't need any dispatching tricks here, because _M_insert_after_range |
|
92 // already does them. |
|
93 # ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS |
|
94 template <class _InputIterator> |
|
95 _DBG_slist(_InputIterator __first, _InputIterator __last) : |
|
96 _STLP_DBG_SLIST_BASE(__first, __last, allocator_type()), _M_iter_list(_Get_base()) {} |
|
97 # endif |
|
98 template <class _InputIterator> |
|
99 _DBG_slist(_InputIterator __first, _InputIterator __last, |
|
100 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL) : |
|
101 _STLP_DBG_SLIST_BASE(__first, __last, __a), _M_iter_list(_Get_base()) {} |
|
102 |
|
103 #else /* _STLP_MEMBER_TEMPLATES */ |
|
104 |
|
105 _DBG_slist(const_iterator __first, const_iterator __last, |
|
106 const allocator_type& __a = allocator_type() ) : |
|
107 _STLP_DBG_SLIST_BASE(__first._M_iterator, __last._M_iterator, __a), |
|
108 _M_iter_list(_Get_base()) {} |
|
109 |
|
110 _DBG_slist(const value_type* __first, const value_type* __last, |
|
111 const allocator_type& __a = allocator_type()) : |
|
112 _STLP_DBG_SLIST_BASE(__first, __last, __a), _M_iter_list(_Get_base()) {} |
|
113 |
|
114 #endif /* _STLP_MEMBER_TEMPLATES */ |
|
115 |
|
116 _DBG_slist(const _Self& __x) : _STLP_DBG_SLIST_BASE(__x), _M_iter_list(_Get_base()) {} |
|
117 |
|
118 _Self& operator= (const _Self& __x) { |
|
119 _Invalidate_all(); |
|
120 (_Base&)*this = (const _Base&)__x; |
|
121 return *this; |
|
122 } |
|
123 |
|
124 ~_DBG_slist() {} |
|
125 |
|
126 public: |
|
127 void assign(size_type __n, const _Tp& __val) { |
|
128 // fbp :check invalidation here ! |
|
129 _Base::assign(__n, __val); |
|
130 } |
|
131 |
|
132 public: |
|
133 |
|
134 iterator before_begin() { return iterator(&_M_iter_list, _Base::before_begin()); } |
|
135 const_iterator before_begin() const |
|
136 { return const_iterator(&_M_iter_list, _Base::before_begin()); } |
|
137 |
|
138 iterator begin() { return iterator(&_M_iter_list, _Base::begin()); } |
|
139 const_iterator begin() const |
|
140 { return const_iterator(&_M_iter_list,_Base::begin());} |
|
141 |
|
142 iterator end() { return iterator(&_M_iter_list, _Base::end()); } |
|
143 const_iterator end() const { return const_iterator(&_M_iter_list, _Base::end()); } |
|
144 |
|
145 void swap(_Self& __x) { |
|
146 _M_iter_list._Swap_owners(__x._M_iter_list); |
|
147 _Base::swap(__x); |
|
148 } |
|
149 |
|
150 public: |
|
151 // fbp : checks here ! |
|
152 reference front() { |
|
153 _STLP_VERBOSE_ASSERT(!this->empty(), _StlMsg_EMPTY_CONTAINER) |
|
154 return _Base::front(); |
|
155 } |
|
156 const_reference front() const { |
|
157 _STLP_VERBOSE_ASSERT(!this->empty(), _StlMsg_EMPTY_CONTAINER) |
|
158 return _Base::front(); |
|
159 } |
|
160 void pop_front() { |
|
161 _STLP_VERBOSE_ASSERT(!this->empty(), _StlMsg_EMPTY_CONTAINER) |
|
162 _Base::pop_front(); |
|
163 } |
|
164 iterator previous(const_iterator __pos) { |
|
165 return iterator(&_M_iter_list,_Base::previous(__pos._M_iterator)); |
|
166 } |
|
167 const_iterator previous(const_iterator __pos) const { |
|
168 return const_iterator(&_M_iter_list,_Base::previous(__pos._M_iterator)); |
|
169 } |
|
170 |
|
171 public: |
|
172 |
|
173 iterator insert_after(iterator __pos, const value_type& __x) { |
|
174 return iterator(&_M_iter_list,_Base::insert_after(__pos._M_iterator, __x)); |
|
175 } |
|
176 |
|
177 iterator insert_after(iterator __pos) { |
|
178 return iterator(&_M_iter_list,_Base::insert_after(__pos._M_iterator)); |
|
179 } |
|
180 |
|
181 void insert_after(iterator __pos, size_type __n, const value_type& __x) { |
|
182 _Base::insert_after(__pos._M_iterator, __n, __x); |
|
183 } |
|
184 |
|
185 #ifdef _STLP_MEMBER_TEMPLATES |
|
186 |
|
187 template <class _InputIterator> |
|
188 void assign(_InputIterator __first, _InputIterator __last) { |
|
189 // fbp :check invalidation here ! |
|
190 _Base::assign(__first, __last); |
|
191 } |
|
192 |
|
193 // We don't need any dispatching tricks here, because _M_insert_after_range |
|
194 // already does them. |
|
195 template <class _InIter> |
|
196 void insert_after(iterator __pos, _InIter __first, _InIter __last) { |
|
197 _Base::insert_after(__pos._M_iterator, __first, __last); |
|
198 } |
|
199 |
|
200 // We don't need any dispatching tricks here, because _M_insert_after_range |
|
201 // already does them. |
|
202 template <class _InIter> |
|
203 void insert(iterator __pos, _InIter __first, _InIter __last) { |
|
204 _Base::insert(__pos._M_iterator, __first, __last); |
|
205 |
|
206 } |
|
207 |
|
208 #else /* _STLP_MEMBER_TEMPLATES */ |
|
209 |
|
210 void insert_after(iterator __pos, |
|
211 const_iterator __first, const_iterator __last) { |
|
212 _Base::insert_after(__pos._M_iterator, __first._M_iterator, __last._M_iterator); |
|
213 } |
|
214 void insert_after(iterator __pos, |
|
215 const value_type* __first, const value_type* __last) { |
|
216 _Base::insert_after(__pos._M_iterator, __first, __last); |
|
217 } |
|
218 |
|
219 void insert(iterator __pos, const_iterator __first, const_iterator __last) { |
|
220 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos)) |
|
221 _Base::insert(__pos._M_iterator, __first._M_iterator, __last._M_iterator); |
|
222 } |
|
223 void insert(iterator __pos, const value_type* __first, |
|
224 const value_type* __last) { |
|
225 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos)) |
|
226 _Base::insert(__pos._M_iterator, __first, __last); |
|
227 } |
|
228 |
|
229 #endif /* _STLP_MEMBER_TEMPLATES */ |
|
230 |
|
231 iterator insert(iterator __pos, const value_type& __x) { |
|
232 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos)) |
|
233 return iterator(&_M_iter_list, _Base::insert(__pos._M_iterator, __x)); |
|
234 } |
|
235 |
|
236 iterator insert(iterator __pos) { |
|
237 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos)) |
|
238 return iterator(&_M_iter_list, _Base::insert(__pos._M_iterator)); |
|
239 } |
|
240 |
|
241 void insert(iterator __pos, size_type __n, const value_type& __x) { |
|
242 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos)) |
|
243 _Base::insert(__pos._M_iterator, __n, __x); |
|
244 } |
|
245 |
|
246 public: |
|
247 iterator erase_after(iterator __pos) { |
|
248 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos)) |
|
249 return iterator(&_M_iter_list, _Base::erase_after(__pos._M_iterator)); |
|
250 } |
|
251 iterator erase_after(iterator __before_first, iterator __last) { |
|
252 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__before_first)) |
|
253 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__last)) |
|
254 return iterator(&_M_iter_list, |
|
255 _Base::erase_after(__before_first._M_iterator, __last._M_iterator)); |
|
256 } |
|
257 |
|
258 iterator erase(iterator __pos) { |
|
259 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos)) |
|
260 return iterator(&_M_iter_list, _Base::erase(__pos._M_iterator)); |
|
261 } |
|
262 iterator erase(iterator __first, iterator __last) { |
|
263 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__first)) |
|
264 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__last)) |
|
265 return iterator(&_M_iter_list, |
|
266 _Base::erase(__first._M_iterator, __last._M_iterator)); |
|
267 } |
|
268 |
|
269 void resize(size_type __new_size, const _Tp& __x) { |
|
270 _Base::resize(__new_size, __x); |
|
271 } |
|
272 void resize(size_type new_size) { resize(new_size, _Tp()); } |
|
273 |
|
274 void clear() { |
|
275 _Invalidate_all(); |
|
276 _Base::clear(); |
|
277 } |
|
278 |
|
279 public: |
|
280 // Moves the range [__before_first + 1, __before_last + 1) to *this, |
|
281 // inserting it immediately after __pos. This is constant time. |
|
282 void splice_after(iterator __pos, |
|
283 iterator __before_first, iterator __before_last) |
|
284 { |
|
285 if (__before_first != __before_last) { |
|
286 _Base::splice_after(__pos._M_iterator, |
|
287 __before_first._M_iterator, __before_last._M_iterator); |
|
288 __before_first++; |
|
289 __before_last++; |
|
290 __invalidate_range(__before_first._Owner(), |
|
291 __before_first, __before_last); |
|
292 } |
|
293 } |
|
294 |
|
295 // Moves the element that follows __prev to *this, inserting it immediately |
|
296 // after __pos. This is constant time. |
|
297 void splice_after(iterator __pos, iterator __prev) |
|
298 { |
|
299 _Base::splice_after(__pos._M_iterator, __prev._M_iterator); |
|
300 __invalidate_iterator(__prev._Owner(), ++__prev); |
|
301 } |
|
302 |
|
303 // Removes all of the elements from the list __x to *this, inserting |
|
304 // them immediately after __pos. __x must not be *this. Complexity: |
|
305 // linear in __x.size(). |
|
306 void splice_after(iterator __pos, _Self& __x) |
|
307 { |
|
308 _Base::splice_after(__pos._M_iterator, (_Base&)__x); |
|
309 __x._Invalidate_all(); |
|
310 } |
|
311 |
|
312 // Linear in distance(begin(), __pos), and linear in __x.size(). |
|
313 void splice(iterator __pos, _Self& __x) { |
|
314 _STLP_VERBOSE_ASSERT(!(&__x==this), _StlMsg_INVALID_ARGUMENT) |
|
315 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos)) |
|
316 _Base::splice(__pos._M_iterator, (_Base&)__x); |
|
317 __x._Invalidate_all(); |
|
318 } |
|
319 |
|
320 // Linear in distance(begin(), __pos), and in distance(__x.begin(), __i). |
|
321 void splice(iterator __pos, _Self& __x, iterator __i) { |
|
322 _STLP_VERBOSE_ASSERT(&__x!=this, _StlMsg_INVALID_ARGUMENT) |
|
323 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos) && |
|
324 __check_if_owner(&__x._M_iter_list ,__i)) |
|
325 _Base::splice(__pos._M_iterator, (_Base&)__x, __i._M_iterator); |
|
326 __x._Invalidate_iterator(__i); |
|
327 } |
|
328 |
|
329 // Linear in distance(begin(), __pos), in distance(__x.begin(), __first), |
|
330 // and in distance(__first, __last). |
|
331 void splice(iterator __pos, _Self& __x, iterator __first, iterator __last) |
|
332 { |
|
333 _STLP_VERBOSE_ASSERT(&__x!=this, _StlMsg_INVALID_ARGUMENT) |
|
334 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos)) |
|
335 if (__first != __last) |
|
336 _Base::splice(__pos._M_iterator, (_Base&)__x, __first._M_iterator, __last._M_iterator); |
|
337 __invalidate_range(&__x._M_iter_list, __first, __last); |
|
338 } |
|
339 |
|
340 public: |
|
341 |
|
342 void remove(const _Tp& __val) { |
|
343 _Base::remove(__val); |
|
344 // __x._Invalidate_all(); |
|
345 } |
|
346 void unique() { |
|
347 _Base::unique(); |
|
348 } |
|
349 void merge(_Self& __x) { |
|
350 _Base::merge((_Base&)__x); |
|
351 __x._Invalidate_all(); |
|
352 } |
|
353 void sort() { |
|
354 _Invalidate_all(); |
|
355 _Base::sort(); |
|
356 } |
|
357 |
|
358 #ifdef _STLP_MEMBER_TEMPLATES |
|
359 |
|
360 template <class _Predicate> |
|
361 void remove_if(_Predicate __pred) { |
|
362 _Base::remove_if(__pred); |
|
363 } |
|
364 |
|
365 template <class _BinaryPredicate> |
|
366 void unique(_BinaryPredicate __pred) { |
|
367 _Base::unique(__pred); |
|
368 } |
|
369 |
|
370 template <class _StrictWeakOrdering> |
|
371 void merge(_Self& __x, _StrictWeakOrdering __ord) { |
|
372 _Base::merge((_Base&)__x, __ord); |
|
373 __x._Invalidate_all(); |
|
374 } |
|
375 |
|
376 template <class _StrictWeakOrdering> |
|
377 void sort(_StrictWeakOrdering __comp) { |
|
378 _Invalidate_all(); |
|
379 _Base::sort(__comp); |
|
380 } |
|
381 #endif /* _STLP_MEMBER_TEMPLATES */ |
|
382 |
|
383 }; |
|
384 |
|
385 #define _STLP_TEMPLATE_HEADER template <class _Tp, class _Alloc> |
|
386 #define _STLP_TEMPLATE_CONTAINER _DBG_slist<_Tp,_Alloc> |
|
387 #define _STLP_TEMPLATE_CONTAINER_BASE _STLP_DBG_SLIST_BASE |
|
388 #include <stl/debug/_relops_cont.h> |
|
389 #undef _STLP_TEMPLATE_CONTAINER_BASE |
|
390 #undef _STLP_TEMPLATE_CONTAINER |
|
391 #undef _STLP_TEMPLATE_HEADER |
|
392 |
|
393 _STLP_END_NAMESPACE |
|
394 |
|
395 #endif /* _STLP_INTERNAL_DBG_SLIST_H */ |
|
396 |
|
397 // Local Variables: |
|
398 // mode:C++ |
|
399 // End: |