1 _list.h |
1 /* |
|
2 * |
|
3 * Copyright (c) 1994 |
|
4 * Hewlett-Packard Company |
|
5 * |
|
6 * Copyright (c) 1996,1997 |
|
7 * Silicon Graphics Computer Systems, Inc. |
|
8 * |
|
9 * Copyright (c) 1997 |
|
10 * Moscow Center for SPARC Technology |
|
11 * |
|
12 * Copyright (c) 1999 |
|
13 * Boris Fomitchev |
|
14 * |
|
15 * This material is provided "as is", with absolutely no warranty expressed |
|
16 * or implied. Any use is at your own risk. |
|
17 * |
|
18 * Permission to use or copy this software for any purpose is hereby granted |
|
19 * without fee, provided the above notices are retained on all copies. |
|
20 * Permission to modify the code and to distribute modified code is granted, |
|
21 * provided the above notices are retained, and a notice that the code was |
|
22 * modified is included with the above copyright notice. |
|
23 * |
|
24 */ |
|
25 |
|
26 /* NOTE: This is an internal header file, included by other STL headers. |
|
27 * You should not attempt to use it directly. |
|
28 */ |
|
29 |
|
30 #ifndef _STLP_INTERNAL_DBG_LIST_H |
|
31 #define _STLP_INTERNAL_DBG_LIST_H |
|
32 |
|
33 #include <stl/debug/_iterator.h> |
|
34 |
|
35 # ifndef _STLP_USE_WRAPPER_FOR_ALLOC_PARAM |
|
36 # undef _DBG_list |
|
37 # define _DBG_list list |
|
38 # endif |
|
39 |
|
40 # define _STLP_DBG_LIST_BASE \ |
|
41 __WORKAROUND_DBG_RENAME(list) <_Tp, _Alloc> |
|
42 |
|
43 _STLP_BEGIN_NAMESPACE |
|
44 |
|
45 # ifdef _STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS |
|
46 template <class _Tp, class _Alloc> |
|
47 inline _Tp* |
|
48 value_type(const _DBG_iter_base< _STLP_DBG_LIST_BASE >&) { |
|
49 return (_Tp*)0; |
|
50 } |
|
51 template <class _Tp, class _Alloc> |
|
52 inline bidirectional_iterator_tag |
|
53 iterator_category(const _DBG_iter_base< _STLP_DBG_LIST_BASE >&) { |
|
54 return bidirectional_iterator_tag(); |
|
55 } |
|
56 # endif |
|
57 |
|
58 template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) > |
|
59 class _DBG_list : public _STLP_DBG_LIST_BASE { |
|
60 |
|
61 typedef _STLP_DBG_LIST_BASE _Base; |
|
62 typedef _DBG_list<_Tp, _Alloc> _Self; |
|
63 |
|
64 public: |
|
65 __IMPORT_CONTAINER_TYPEDEFS(_Base) |
|
66 |
|
67 public: |
|
68 typedef _DBG_iter<_Base, _Nonconst_traits<value_type> > iterator; |
|
69 typedef _DBG_iter<_Base, _Const_traits<value_type> > const_iterator; |
|
70 |
|
71 _STLP_DECLARE_BIDIRECTIONAL_REVERSE_ITERATORS; |
|
72 |
|
73 protected: |
|
74 mutable __owned_list _M_iter_list; |
|
75 void _Invalidate_all() { _M_iter_list._Invalidate_all();} |
|
76 |
|
77 public: |
|
78 const _Base* _Get_base() const { return (const _Base*)this; } |
|
79 _Base* _Get_base() { return (_Base*)this; } |
|
80 explicit _DBG_list(const allocator_type& __a = allocator_type()) : |
|
81 _STLP_DBG_LIST_BASE(__a), _M_iter_list(_Get_base()) {} |
|
82 _DBG_list(size_type __n, const _Tp& __value, |
|
83 const allocator_type& __a = allocator_type()) |
|
84 : _STLP_DBG_LIST_BASE(__n, __value, __a), _M_iter_list(_Get_base()) {} |
|
85 explicit _DBG_list(size_type __n) |
|
86 : _STLP_DBG_LIST_BASE(__n), _M_iter_list(_Get_base()) {} |
|
87 |
|
88 #ifdef _STLP_MEMBER_TEMPLATES |
|
89 |
|
90 // We don't need any dispatching tricks here, because insert does all of |
|
91 // that anyway. |
|
92 # ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS |
|
93 template <class _InputIterator> |
|
94 _DBG_list(_InputIterator __first, _InputIterator __last) |
|
95 : _STLP_DBG_LIST_BASE(__first, __last, allocator_type()), _M_iter_list(_Get_base()) {} |
|
96 # endif |
|
97 template <class _InputIterator> |
|
98 _DBG_list(_InputIterator __first, _InputIterator __last, |
|
99 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL) |
|
100 : _STLP_DBG_LIST_BASE(__first, __last, __a), _M_iter_list(_Get_base()) {} |
|
101 #else /* _STLP_MEMBER_TEMPLATES */ |
|
102 |
|
103 _DBG_list(const _Tp* __first, const _Tp* __last, |
|
104 const allocator_type& __a = allocator_type()) |
|
105 : _STLP_DBG_LIST_BASE(__first, __last, __a), _M_iter_list(_Get_base()) {} |
|
106 _DBG_list(const_iterator __first, const_iterator __last, |
|
107 const allocator_type& __a = allocator_type()): |
|
108 _STLP_DBG_LIST_BASE(__first._M_iterator, __last._M_iterator, __a), |
|
109 _M_iter_list(_Get_base()) {} |
|
110 |
|
111 #endif /* _STLP_MEMBER_TEMPLATES */ |
|
112 |
|
113 _DBG_list(const _Self& __x) : |
|
114 _STLP_DBG_LIST_BASE(__x) , _M_iter_list(_Get_base()) {} |
|
115 |
|
116 _Self& operator=(const _Self& __x) { |
|
117 _Invalidate_all(); |
|
118 _Base::operator=((const _Base&)__x); |
|
119 return *this; |
|
120 } |
|
121 |
|
122 public: |
|
123 iterator begin() { return iterator(&_M_iter_list, _Base::begin()); } |
|
124 const_iterator begin() const { return const_iterator(&_M_iter_list, _Base::begin()); } |
|
125 |
|
126 iterator end() { return iterator(&_M_iter_list, _Base::end()); } |
|
127 const_iterator end() const { return const_iterator(&_M_iter_list, _Base::end()); } |
|
128 |
|
129 reverse_iterator rbegin() { return reverse_iterator(end()); } |
|
130 reverse_iterator rend() { return reverse_iterator(begin()); } |
|
131 |
|
132 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } |
|
133 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } |
|
134 |
|
135 // those are here to enforce checking |
|
136 reference front() { return *begin(); } |
|
137 const_reference front() const { return *begin(); } |
|
138 reference back() { return *(--end()); } |
|
139 const_reference back() const { return *(--end()); } |
|
140 |
|
141 void swap(_Self& __x) { |
|
142 _M_iter_list._Swap_owners(__x._M_iter_list); |
|
143 _Base::swap(__x); |
|
144 } |
|
145 |
|
146 iterator insert(iterator __position, const _Tp& __x) { |
|
147 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position)) |
|
148 return iterator(&_M_iter_list,_Base::insert(__position._M_iterator, __x) ); |
|
149 } |
|
150 |
|
151 # ifndef _STLP_NO_ANACHRONISMS |
|
152 iterator insert(iterator __position) { return insert(__position, _Tp()); } |
|
153 # endif |
|
154 |
|
155 #ifdef _STLP_MEMBER_TEMPLATES |
|
156 |
|
157 template <class _InputIterator> |
|
158 void insert(iterator __position, _InputIterator __first, _InputIterator __last) { |
|
159 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position)) |
|
160 _Base::insert(__position._M_iterator, __first, __last); |
|
161 } |
|
162 |
|
163 #else |
|
164 |
|
165 void insert(iterator __position, const _Tp* __first, const _Tp* __last) { |
|
166 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position)) |
|
167 _Base::insert(__position._M_iterator, __first, __last); |
|
168 } |
|
169 |
|
170 void insert(iterator __position, |
|
171 const_iterator __first, const_iterator __last) { |
|
172 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position)) |
|
173 _Base::insert(__position._M_iterator, __first._M_iterator, __last._M_iterator); |
|
174 } |
|
175 |
|
176 #endif /* _STLP_MEMBER_TEMPLATES */ |
|
177 |
|
178 void insert(iterator __position, size_type __n, const _Tp& __x) { |
|
179 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position)) |
|
180 _Base::insert(__position._M_iterator, __n, __x); |
|
181 } |
|
182 |
|
183 void pop_back() { |
|
184 _STLP_VERBOSE_ASSERT(!this->empty(), _StlMsg_EMPTY_CONTAINER) |
|
185 __invalidate_iterator(&_M_iter_list,end()); |
|
186 _Base::pop_back(); |
|
187 } |
|
188 |
|
189 void pop_front() { |
|
190 _STLP_VERBOSE_ASSERT(!this->empty(), _StlMsg_EMPTY_CONTAINER) |
|
191 __invalidate_iterator(&_M_iter_list,begin()); |
|
192 _Base::pop_front(); |
|
193 } |
|
194 |
|
195 iterator erase(iterator __position) { |
|
196 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position)) |
|
197 _STLP_VERBOSE_ASSERT(__position._M_iterator._M_node!=this->_M_node._M_data, |
|
198 _StlMsg_ERASE_PAST_THE_END) |
|
199 // fbp : CHECK !!! |
|
200 __invalidate_iterator(&_M_iter_list, __position); |
|
201 return iterator(&_M_iter_list,_Base::erase(__position._M_iterator)); |
|
202 } |
|
203 iterator erase(iterator __first, iterator __last) { |
|
204 while (__first != __last) |
|
205 erase(__first++); |
|
206 return __last; |
|
207 } |
|
208 |
|
209 void resize(size_type __new_size, const _Tp& __x) { |
|
210 typename _Base::iterator __i = _Base::begin(); |
|
211 size_type __len = 0; |
|
212 for ( ; __i != _Base::end() && __len < __new_size; ++__i, ++__len); |
|
213 |
|
214 if (__len == __new_size) |
|
215 erase(iterator(&_M_iter_list,__i), end()); |
|
216 else // __i == end() |
|
217 _Base::insert(_Base::end(), __new_size - __len, __x); |
|
218 } |
|
219 |
|
220 void resize(size_type __new_size) { this->resize(__new_size, _Tp()); } |
|
221 |
|
222 void remove(const _Tp& __value) { |
|
223 typename _Base::iterator __first = _Base::begin(); |
|
224 typename _Base::iterator __last = _Base::end(); |
|
225 while (__first != __last) { |
|
226 typename _Base::iterator __next = __first; |
|
227 ++__next; |
|
228 if (__value == *__first) erase(iterator(&_M_iter_list,__first)); |
|
229 __first = __next; |
|
230 } |
|
231 } |
|
232 |
|
233 void clear() { |
|
234 _Invalidate_all(); |
|
235 _Base::clear(); |
|
236 } |
|
237 |
|
238 public: |
|
239 void splice(iterator __position, _Self& __x) { |
|
240 _STLP_VERBOSE_ASSERT(&__x!=this, _StlMsg_INVALID_ARGUMENT) |
|
241 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position)) |
|
242 _Base::splice(__position._M_iterator, __x); |
|
243 __x._Invalidate_all(); |
|
244 } |
|
245 |
|
246 void splice(iterator __position, _Self& __x, iterator __i) { |
|
247 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position) && |
|
248 __check_if_owner(&__x._M_iter_list ,__i)) |
|
249 _STLP_DEBUG_CHECK(_Dereferenceable(__i)) |
|
250 // fbp : CHECK !!! |
|
251 // __invalidate_iterator(&__x._M_iter_list, __i); |
|
252 _Base::splice(__position._M_iterator, __x, __i._M_iterator); |
|
253 } |
|
254 |
|
255 void splice(iterator __position, _Self& __x, iterator __first, iterator __last) { |
|
256 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __position)) |
|
257 _STLP_VERBOSE_ASSERT(__first._Owner()==&__x._M_iter_list && __last._Owner()==&__x._M_iter_list, |
|
258 _StlMsg_NOT_OWNER) |
|
259 _Base::splice(__position._M_iterator, __x, __first._M_iterator, __last._M_iterator); |
|
260 } |
|
261 |
|
262 void merge(_Self& __x) { |
|
263 __x._Invalidate_all(); |
|
264 _Base::merge(__x); |
|
265 } |
|
266 void reverse() { |
|
267 _Invalidate_all(); |
|
268 _Base::reverse(); |
|
269 } |
|
270 void unique() { |
|
271 _Invalidate_all(); |
|
272 _Base::unique(); |
|
273 } |
|
274 void sort() { |
|
275 _Invalidate_all(); |
|
276 _Base::sort(); |
|
277 } |
|
278 |
|
279 #ifdef _STLP_MEMBER_TEMPLATES |
|
280 |
|
281 template <class _Predicate> void remove_if(_Predicate __pred) { |
|
282 _Base::remove_if(__pred); |
|
283 } |
|
284 template <class _BinaryPredicate> |
|
285 void unique(_BinaryPredicate __binary_pred) { |
|
286 _Base::unique(__binary_pred); |
|
287 } |
|
288 template <class _StrictWeakOrdering> |
|
289 void merge(_Self& __x, |
|
290 _StrictWeakOrdering __comp) { |
|
291 __x._Invalidate_all(); |
|
292 _Base::merge(__x, __comp); |
|
293 } |
|
294 |
|
295 template <class _StrictWeakOrdering> |
|
296 void sort(_StrictWeakOrdering __comp) { |
|
297 _Invalidate_all(); |
|
298 _Base::sort(__comp); |
|
299 } |
|
300 #endif /* _STLP_MEMBER_TEMPLATES */ |
|
301 |
|
302 }; |
|
303 |
|
304 #define _STLP_TEMPLATE_HEADER template <class _Tp, class _Alloc> |
|
305 #define _STLP_TEMPLATE_CONTAINER _DBG_list<_Tp,_Alloc> |
|
306 #define _STLP_TEMPLATE_CONTAINER_BASE _STLP_DBG_LIST_BASE |
|
307 #include <stl/debug/_relops_cont.h> |
|
308 #undef _STLP_TEMPLATE_CONTAINER_BASE |
|
309 #undef _STLP_TEMPLATE_CONTAINER |
|
310 #undef _STLP_TEMPLATE_HEADER |
|
311 |
|
312 _STLP_END_NAMESPACE |
|
313 |
|
314 #endif /* _STLP_INTERNAL_LIST_H */ |
|
315 |
|
316 // Local Variables: |
|
317 // mode:C++ |
|
318 // End: |