]> git.buserror.net Git - polintos/scott/priv.git/blob - include/c++/stl/stl/debug/_deque.h
Add STLport 5.1.4
[polintos/scott/priv.git] / include / c++ / stl / stl / debug / _deque.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_DEQUE_H
31 #define _STLP_INTERNAL_DBG_DEQUE_H
32
33 #ifndef _STLP_DBG_ITERATOR_H
34 #  include <stl/debug/_iterator.h>
35 #endif
36
37 #define _STLP_NON_DBG_DEQUE _STLP_PRIV _STLP_NON_DBG_NAME(deque) <_Tp,_Alloc>
38
39 _STLP_BEGIN_NAMESPACE
40
41 #if defined (_STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS)
42 template <class _Tp, class _Alloc>
43 inline _Tp* value_type(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_DEQUE >&)
44 { return (_Tp*)0; }
45 template <class _Tp, class _Alloc>
46 inline random_access_iterator_tag iterator_category(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_DEQUE >&)
47 { return random_access_iterator_tag(); }
48 #endif
49
50 template <class _Tp, _STLP_DBG_ALLOCATOR_SELECT(_Tp) >
51 class deque :
52 #if !defined (__DMC__)
53              private
54 #endif
55                      _STLP_PRIV __construct_checker<_STLP_NON_DBG_DEQUE >
56 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
57             , public __stlport_class<deque<_Tp, _Alloc> >
58 #endif
59 {
60   typedef deque<_Tp,_Alloc> _Self;
61   typedef _STLP_NON_DBG_DEQUE _Base;
62   typedef _STLP_PRIV __construct_checker<_STLP_NON_DBG_DEQUE > _ConstructCheck;
63
64 public:
65   // Basic types
66   __IMPORT_CONTAINER_TYPEDEFS(_Base)
67
68   // Iterators
69   typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _DbgTraits<_Nonconst_traits<value_type> > > iterator;
70   typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _DbgTraits<_Const_traits<value_type> > >    const_iterator;
71
72   _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
73
74 protected:
75   _Base _M_non_dbg_impl;
76   _STLP_PRIV __owned_list _M_iter_list;
77
78   void _Invalidate_all()
79   { _M_iter_list._Invalidate_all(); }
80   void _Invalidate_iterator(const iterator& __it)
81   { _STLP_PRIV __invalidate_iterator(&_M_iter_list,__it); }
82   void _Invalidate_iterators(const iterator& __first, const iterator& __last)
83   { _STLP_PRIV __invalidate_range(&_M_iter_list, __first, __last); }
84
85 public:
86   // Basic accessors
87   allocator_type get_allocator() const { return _M_non_dbg_impl.get_allocator(); }
88
89   iterator begin() { return iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
90   iterator end() { return iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
91   const_iterator begin() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
92   const_iterator end() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
93
94   reverse_iterator rbegin() { return reverse_iterator(end()); }
95   reverse_iterator rend() { return reverse_iterator(begin()); }
96   const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
97   const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
98
99   reference operator[](size_type __n) {
100     _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
101     return _M_non_dbg_impl[__n];
102   }
103   const_reference operator[](size_type __n) const {
104     _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
105     return _M_non_dbg_impl[__n];
106   }
107
108   reference at(size_type __n) { return _M_non_dbg_impl.at(__n); }
109   const_reference at(size_type __n) const { return _M_non_dbg_impl.at(__n); }
110
111   reference front() {
112     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
113     return *begin();
114   }
115   const_reference front() const {
116     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
117     return *begin();
118   }
119   reference back() {
120     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
121     return *(--end());
122   }
123   const_reference back() const {
124     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
125     return *(--end());
126   }
127
128   // Constructor, destructor.
129   explicit deque(const allocator_type& __a = allocator_type()) :
130     _M_non_dbg_impl(__a), _M_iter_list(&_M_non_dbg_impl) {}
131   deque(const _Self& __x) :
132     _ConstructCheck(__x), _M_non_dbg_impl(__x._M_non_dbg_impl),
133     _M_iter_list(&_M_non_dbg_impl) {}
134
135 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
136   explicit deque(size_type __n, const value_type& __x = _Tp(),
137 #else
138   deque(size_type __n, param_type __x,
139 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
140             const allocator_type& __a = allocator_type()) :
141     _M_non_dbg_impl(__n, __x, __a), _M_iter_list(&_M_non_dbg_impl) {}
142 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
143   explicit deque(size_type __n) :
144     _M_non_dbg_impl(__n), _M_iter_list(&_M_non_dbg_impl) {}
145 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
146
147   deque(__move_source<_Self> src)
148     : _M_non_dbg_impl(__move_source<_Base>(src.get()._M_non_dbg_impl)),
149       _M_iter_list(&_M_non_dbg_impl) {
150 #if defined (_STLP_NO_EXTENSIONS) || (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
151     src.get()._M_iter_list._Invalidate_all();
152 #else
153     src.get()._M_iter_list._Set_owner(_M_iter_list);
154 #endif
155   }
156
157 #if defined (_STLP_MEMBER_TEMPLATES)
158   template <class _InputIterator>
159   deque(_InputIterator __first, _InputIterator __last,
160         const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
161     : _ConstructCheck(__first, __last),
162       _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last), __a),
163       _M_iter_list(&_M_non_dbg_impl) {
164     }
165 #  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
166   template <class _InputIterator>
167   deque(_InputIterator __first, _InputIterator __last)
168     : _ConstructCheck(__first, __last),
169       _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last)),
170       _M_iter_list(&_M_non_dbg_impl) {
171     }
172 #  endif
173 #else
174   deque(const value_type* __first, const value_type* __last,
175         const allocator_type& __a = allocator_type())
176     : _ConstructCheck(__first, __last),
177       _M_non_dbg_impl(__first, __last, __a),
178       _M_iter_list(&_M_non_dbg_impl) {
179     }
180
181   deque(const_iterator __first, const_iterator __last,
182         const allocator_type& __a = allocator_type())
183     : _ConstructCheck(__first, __last),
184       _M_non_dbg_impl(__first._M_iterator, __last._M_iterator, __a),
185       _M_iter_list(&_M_non_dbg_impl) {
186     }
187 #endif
188
189   _Self& operator=(const _Self& __x) {
190     if (this != &__x) {
191       _Invalidate_all();
192       _M_non_dbg_impl = __x._M_non_dbg_impl;
193     }
194     return *this;
195   }
196
197   bool empty() const { return _M_non_dbg_impl.empty(); }
198   size_type size() const { return _M_non_dbg_impl.size(); }
199   size_type max_size() const { return _M_non_dbg_impl.max_size(); }
200
201   void swap(_Self& __x) {
202     _M_iter_list._Swap_owners(__x._M_iter_list);
203     _M_non_dbg_impl.swap(__x._M_non_dbg_impl);
204   }
205
206 public:
207   void assign(size_type __n, const _Tp& __val) {
208     _Invalidate_all();
209     _M_non_dbg_impl.assign(__n, __val);
210   }
211
212 #if defined (_STLP_MEMBER_TEMPLATES)
213   template <class _InputIterator>
214   void assign(_InputIterator __first, _InputIterator __last) {
215     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
216     _Invalidate_all();
217     _M_non_dbg_impl.assign(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
218   }
219 #else
220   void assign(const_iterator __first, const_iterator __last) {
221     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
222     _Invalidate_all();
223     _M_non_dbg_impl.assign(__first._M_iterator, __last._M_iterator);
224   }
225   void assign(const value_type *__first, const value_type *__last) {
226     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first, __last))
227     _Invalidate_all();
228     _M_non_dbg_impl.assign(__first, __last);
229   }
230 #endif
231
232 public:                         // push_* and pop_*
233
234 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
235   void push_back(const value_type& __t = _Tp()) {
236 #else
237   void push_back(const value_type& __t) {
238 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
239     _Invalidate_all();
240     _M_non_dbg_impl.push_back(__t);
241   }
242
243 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
244   void push_back() {
245     _Invalidate_all();
246     _M_non_dbg_impl.push_back();
247   }
248 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
249
250 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
251   void push_front(const value_type& __t = _Tp()) {
252 #else
253   void push_front(const value_type& __t) {
254 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
255     _Invalidate_all();
256     _M_non_dbg_impl.push_front(__t);
257   }
258
259 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
260   void push_front() {
261     _Invalidate_all();
262     _M_non_dbg_impl.push_front();
263   }
264 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
265
266   void pop_back() {
267     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
268     _Invalidate_iterator(end());
269     _M_non_dbg_impl.pop_back();
270   }
271
272   void pop_front() {
273     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
274     _Invalidate_iterator(begin());
275     _M_non_dbg_impl.pop_front();
276   }
277
278 public:                         // Insert
279
280 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
281   iterator insert(iterator __pos, const value_type& __x = _Tp()) {
282 #else
283   iterator insert(iterator __pos, const value_type& __x) {
284 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
285     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
286     _Invalidate_all();
287     return iterator(&_M_iter_list, _M_non_dbg_impl.insert(__pos._M_iterator, __x));
288   }
289
290 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
291   iterator insert(iterator __pos) {
292     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
293     _Invalidate_all();
294     return iterator(&_M_iter_list, _M_non_dbg_impl.insert(__pos._M_iterator));
295   }
296 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
297
298   void insert(iterator __pos, size_type __n, const value_type& __x) {
299     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
300     if (__n != 0) _Invalidate_all();
301     _M_non_dbg_impl.insert(__pos._M_iterator, __n, __x);
302   }
303
304 #if defined (_STLP_MEMBER_TEMPLATES)
305   template <class _InputIterator>
306   void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
307     typedef typename _AreSameUnCVTypes<_InputIterator, iterator>::_Ret _IsNonConstIterator;
308     typedef typename _AreSameUnCVTypes<_InputIterator, const_iterator>::_Ret _IsConstIterator;
309     typedef typename _Lor2<_IsNonConstIterator, _IsConstIterator>::_Ret _DoCheck;
310     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
311     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
312     //Sequence requirements 23.1.1 Table 67:
313     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first, _DoCheck()));
314     _M_non_dbg_impl.insert(__pos._M_iterator,
315                            _STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
316     //dums: because of self insertion iterators must be invalidated after insertion.
317     if (__first != __last) _Invalidate_all();
318   }
319 #else
320   void insert(iterator __pos,
321               const value_type* __first, const value_type* __last) {
322     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
323     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first, __last))
324     _M_non_dbg_impl.insert(__pos._M_iterator, __first, __last);
325     //dums: because of self insertion iterators must be invalidated after insertion.
326     if (__first != __last) _Invalidate_all();
327   }
328   void insert(iterator __pos,
329               const_iterator __first, const_iterator __last) {
330     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
331     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
332     //Sequence requirements 23.1.1 Table 67:
333     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first, __true_type()));
334     _M_non_dbg_impl.insert(__pos._M_iterator, __first._M_iterator, __last._M_iterator);
335     //dums: because of self insertion iterators must be invalidated after insertion.
336     if (__first != __last) _Invalidate_all();
337   }
338 #endif
339
340 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
341   void resize(size_type __new_size, const value_type& __x = _Tp()) {
342 #else
343   void resize(size_type __new_size, const value_type& __x) {
344 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
345     if (__new_size != size()) {
346       if ((__new_size > size()) || (__new_size < size() - 1))
347         _Invalidate_all();
348       else
349         _Invalidate_iterator(end());
350     }
351     _M_non_dbg_impl.resize(__new_size, __x);
352   }
353
354 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
355   void resize(size_type new_size) { resize(new_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
356 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
357
358   // Erase
359   iterator erase(iterator __pos) {
360     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
361     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
362     if (__pos._M_iterator == _M_non_dbg_impl.begin())
363       _Invalidate_iterator(__pos);
364     else {
365       typename _Base::iterator __tmp = --(_M_non_dbg_impl.end());
366       if (__pos._M_iterator == __tmp)
367         _Invalidate_iterator(__pos);
368       else
369         _Invalidate_all();
370     }
371     return iterator (&_M_iter_list, _M_non_dbg_impl.erase(__pos._M_iterator));
372   }
373
374   iterator erase(iterator __first, iterator __last) {
375     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last, begin(), end()))
376     if (!empty()) {
377       if (__first._M_iterator == _M_non_dbg_impl.begin() ||
378           __last._M_iterator == _M_non_dbg_impl.end())
379         _Invalidate_iterators(__first, __last);
380       else
381         _Invalidate_all();
382     }
383     return iterator (&_M_iter_list, _M_non_dbg_impl.erase(__first._M_iterator, __last._M_iterator));
384   }
385
386   void clear() {
387     _Invalidate_all();
388     _M_non_dbg_impl.clear();
389   }
390 };
391
392 _STLP_END_NAMESPACE
393
394 #undef _STLP_NON_DBG_DEQUE
395
396 #endif /* _STLP_INTERNAL_DEQUE_H */
397
398 // Local Variables:
399 // mode:C++
400 // End: