ReactOS  0.4.13-dev-100-gc8611ae
_vector.h
Go to the documentation of this file.
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_VECTOR_H
31 #define _STLP_INTERNAL_DBG_VECTOR_H
32 
33 #ifndef _STLP_DBG_ITERATOR_H
34 # include <stl/debug/_iterator.h>
35 #endif
36 
37 #define _STLP_NON_DBG_VECTOR _STLP_PRIV _STLP_NON_DBG_NAME(vector) <_Tp, _Alloc>
38 
40 
41 #if defined (_STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS)
42 template <class _Tp, class _Alloc>
43 inline _Tp*
45 { return (_Tp*)0; }
46 template <class _Tp, class _Alloc>
48 iterator_category(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_VECTOR >&)
49 { return random_access_iterator_tag(); }
50 #endif
51 
53 
54 template <class _Tp, class _NcIt>
56 
57 template <class _Tp, class _NcIt>
60  typedef _Tp value_type;
61  typedef _Tp& reference;
62  typedef _Tp* pointer;
65 };
66 
67 template <class _Tp, class _NcIt>
68 struct _Vector_const_traits {
70  typedef _Tp value_type;
71  typedef const _Tp& reference;
72  typedef const _Tp* pointer;
75 };
76 
84 };
85 
88  typedef _Bit_const_iterator::value_type value_type;
93 };
94 
96 
97 template <class _Tp, _STLP_DFL_TMPL_PARAM(_Alloc, allocator<_Tp>) >
98 class vector :
99 #if !defined (__DMC__)
100  private
101 #endif
102  _STLP_PRIV __construct_checker< _STLP_NON_DBG_VECTOR >
103 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
104  , public __stlport_class<vector<_Tp, _Alloc> >
105 #endif
106 {
107 private:
112  _STLP_PRIV __owned_list _M_iter_list;
113 
114 public:
116 
117  typedef _STLP_PRIV _DBG_iter<_Base,
118  _STLP_PRIV _DbgTraits<_STLP_PRIV _Vector_nonconst_traits<value_type, typename _Base::iterator> > > iterator;
119 
120  typedef _STLP_PRIV _DBG_iter<_Base,
121  _STLP_PRIV _DbgTraits<_STLP_PRIV _Vector_const_traits<value_type, typename _Base::iterator> > > const_iterator;
122 
123 private:
125  { _M_iter_list._Invalidate_all(); }
127  { _STLP_PRIV __invalidate_iterator(&_M_iter_list, __it); }
128  void _Invalidate_iterators(const iterator& __first, const iterator& __last)
129  { _STLP_PRIV __invalidate_range(&_M_iter_list, __first, __last); }
130 
132  if (size() + __nb > capacity())
133  _Invalidate_all();
134  }
135  void _Compare_Capacity (size_type __old_capacity) {
136  if (capacity() > __old_capacity) {
137  _Invalidate_all();
138  }
139  }
140 
141 public:
143 
144  allocator_type get_allocator() const { return _M_non_dbg_impl.get_allocator(); }
145 
150 
152  const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
154  const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
155 
156  size_type size() const { return _M_non_dbg_impl.size(); }
157  size_type max_size() const { return _M_non_dbg_impl.max_size(); }
158  size_type capacity() const { return _M_non_dbg_impl.capacity(); }
159  bool empty() const { return _M_non_dbg_impl.empty(); }
160 
162  _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
163  return _M_non_dbg_impl[__n];
164  }
165 
167  _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
168  return _M_non_dbg_impl[__n];
169  }
170 
173 
174  explicit vector(const allocator_type& __a = allocator_type())
176 
177 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
178  explicit vector(size_type __n, const _Tp& __x = _Tp(),
179 #else
180  vector(size_type __n, const _Tp& __x,
181 #endif
182  const allocator_type& __a = allocator_type())
184 
185 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
186  explicit vector(size_type __n)
188 #endif
189 
190  vector(const _Self& __x)
192 
193 #if !defined (_STLP_NO_MOVE_SEMANTIC)
197 # if defined (_STLP_NO_EXTENSIONS) || (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
198  src.get()._M_iter_list._Invalidate_all();
199 # else
200  src.get()._M_iter_list._Set_owner(_M_iter_list);
201 # endif
202  }
203 #endif
204 
205 #if defined (_STLP_MEMBER_TEMPLATES)
206  template <class _InputIterator>
207  vector(_InputIterator __first, _InputIterator __last,
209  : _ConstructCheck(__first, __last),
212 
213 # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
214  template <class _InputIterator>
215  vector(_InputIterator __first, _InputIterator __last)
216  : _ConstructCheck(__first, __last),
219 # endif
220 #else
221  vector(const _Tp* __first, const _Tp* __last,
222  const allocator_type& __a = allocator_type())
223  : _ConstructCheck(__first, __last), _M_non_dbg_impl(__first, __last, __a),
225 
226  // mysterious VC++ bug ?
228  const allocator_type& __a = allocator_type())
229  : _ConstructCheck(__first, __last),
230  _M_non_dbg_impl(__first._M_iterator, __last._M_iterator, __a),
232 #endif /* _STLP_MEMBER_TEMPLATES */
233 
234  _Self& operator=(const _Self& __x) {
235  if (this != &__x) {
236  _Invalidate_all();
238  }
239  return *this;
240  }
241 
243  if (capacity() < __n)
244  _Invalidate_all();
245  _M_non_dbg_impl.reserve(__n);
246  }
247 
249  _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
250  return *begin();
251  }
253  _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
254  return *begin();
255  }
257  _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
258  return *(--end());
259  }
261  _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
262  return *(--end());
263  }
264 
265  void swap(_Self& __x) {
266  _M_iter_list._Swap_owners(__x._M_iter_list);
268  }
269 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
270  void _M_swap_workaround(_Self& __x) { swap(__x); }
271 #endif
272 
273 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
274  iterator insert(iterator __pos, const _Tp& __x = _Tp()) {
275 #else
276  iterator insert(iterator __pos, const _Tp& __x) {
277 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
278  _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
279  _Check_Overflow(1);
280  return iterator(&_M_iter_list, _M_non_dbg_impl.insert(__pos._M_iterator, __x));
281  }
282 
283 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
284  iterator insert(iterator __pos)
285  { return insert(__pos, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
286 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
287 
288 #if defined (_STLP_MEMBER_TEMPLATES)
289  // Check whether it's an integral type. If so, it's not an iterator.
290  template <class _InputIterator>
291  void insert(iterator __pos,
292  _InputIterator __first, _InputIterator __last) {
293  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
294  _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
295  size_type __old_capacity = capacity();
296  _M_non_dbg_impl.insert(__pos._M_iterator,
298  _Compare_Capacity(__old_capacity);
299  }
300 #endif
301 #if !defined (_STLP_MEMBER_TEMPLATES)
302  void insert (iterator __pos,
303  const value_type *__first, const value_type *__last) {
304  _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first,__last))
305  _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
306  size_type __old_capacity = capacity();
307  _M_non_dbg_impl.insert(__pos._M_iterator, __first, __last);
308  _Compare_Capacity(__old_capacity);
309  }
310 #endif
311 
312 #if !defined (_STLP_MEMBER_TEMPLATES) || !defined (_STLP_NO_METHOD_SPECIALIZATION)
313  void insert(iterator __pos,
315  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first,__last))
316  _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
317  //Sequence requirements 23.1.1 Table 67:
318  _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first));
319  size_type __old_capacity = capacity();
320  _M_non_dbg_impl.insert(__pos._M_iterator, __first._M_iterator, __last._M_iterator);
321  _Compare_Capacity(__old_capacity);
322  }
323  void insert(iterator __pos,
324  iterator __first, iterator __last) {
325  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first,__last))
326  _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
327  //Sequence requirements 23.1.1 Table 67:
328  _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first));
329  size_type __old_capacity = capacity();
330  _M_non_dbg_impl.insert(__pos._M_iterator, __first._M_iterator, __last._M_iterator);
331  _Compare_Capacity(__old_capacity);
332  }
333 #endif
334 
335  void insert (iterator __pos, size_type __n, const _Tp& __x){
336  _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
338  _M_non_dbg_impl.insert(__pos._M_iterator, __n, __x);
339  }
340 
341  void pop_back() {
342  _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
344  _M_non_dbg_impl.pop_back();
345  }
348  _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
349  _Invalidate_iterators(__pos, end());
350  return iterator(&_M_iter_list, _M_non_dbg_impl.erase(__pos._M_iterator));
351  }
353  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last, begin(), end()))
354  _Invalidate_iterators(__first, end());
355  return iterator(&_M_iter_list, _M_non_dbg_impl.erase(__first._M_iterator, __last._M_iterator));
356  }
357 
358 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
359  void resize(size_type __new_size, const _Tp& __x = _STLP_DEFAULT_CONSTRUCTED(_Tp)) {
360 #else
361  void resize(size_type __new_size, const _Tp& __x) {
362 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
363  if (__new_size > capacity()) {
364  _Invalidate_all();
365  }
366  else if (__new_size < size()) {
367  _Invalidate_iterators(begin() + __new_size, end());
368  }
369  _M_non_dbg_impl.resize(__new_size, __x);
370  }
371 
372 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
373  void resize(size_type __new_size) { resize(__new_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
374 #endif
375 
376 #if defined (_STLP_MEMBER_TEMPLATES)
377  template <class _InputIterator>
378  void assign(_InputIterator __first, _InputIterator __last) {
379  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first,__last))
380  _Invalidate_all();
382  }
383 #else
384 private:
385  void _M_assign(const value_type *__first, const value_type *__last) {
386  _Invalidate_all();
387  _M_non_dbg_impl.assign(__first, __last);
388  }
389 public:
390  void assign(const value_type *__first, const value_type *__last) {
391  _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first,__last))
392  _M_assign(__first, __last);
393  }
394 
396  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first,__last))
397  _M_assign(__first._M_iterator, __last._M_iterator);
398  }
399 #endif
400 
401 public:
402  void assign(size_type __n, const _Tp& __val) {
403  _Invalidate_all();
404  _M_non_dbg_impl.assign(__n, __val);
405  }
406 
407  void clear() {
408  _Invalidate_all();
409  _M_non_dbg_impl.clear();
410  }
411  void push_back(const _Tp& __x) {
412  _Check_Overflow(1);
413  _M_non_dbg_impl.push_back(__x);
414  }
415 };
416 
418 
419 #undef _STLP_NON_DBG_VECTOR
420 
421 #endif /* _STLP_DBG_VECTOR_H */
422 
423 // Local Variables:
424 // mode:C++
425 // End:
void assign(const_iterator __first, const_iterator __last)
Definition: _vector.h:395
vector(const _Tp *__first, const _Tp *__last, const allocator_type &__a=allocator_type())
Definition: _vector.h:221
const_reference front() const
Definition: _vector.h:252
_Bit_iterator::value_type value_type
Definition: _vector.h:79
_STLP_PRIV _Vector_base< CTestInfo, _Alloc > _Base
Definition: _vector.h:115
void insert(iterator __pos, iterator __first, iterator __last)
Definition: _vector.h:323
iterator erase(iterator __first, iterator __last)
Definition: _vector.h:352
return __n
Definition: _algo.h:75
iterator end()
Definition: _vector.h:148
size_type max_size() const
Definition: _vector.h:157
#define random_access_iterator_tag
Definition: _abbrevs.h:28
GLsizei const GLvoid * pointer
Definition: glext.h:5848
reverse_iterator rend()
Definition: _vector.h:153
void _Invalidate_iterator(const iterator &__it)
Definition: _vector.h:126
#define reverse_iterator
Definition: _abbrevs.h:34
void resize(size_type __new_size, const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:359
const_iterator end() const
Definition: _vector.h:149
_Vector_nonconst_traits< _Tp, _NcIt > _NonConstTraits
Definition: _vector.h:74
const _Tp * pointer
Definition: _vector.h:72
void insert(iterator __pos, const value_type *__first, const value_type *__last)
Definition: _vector.h:302
void _Invalidate_all()
Definition: _vector.h:124
bool _Dereferenceable(const _Iterator &__it)
Definition: _iterator.h:93
void _M_assign(const value_type *__first, const value_type *__last)
Definition: _vector.h:385
_Bit_const_iterator::reference reference
Definition: _vector.h:89
vector(__move_source< _Self > src)
Definition: _vector.h:194
_Self & operator=(const _Self &__x)
Definition: _vector.h:234
vector(const_iterator __first, const_iterator __last, const allocator_type &__a=allocator_type())
Definition: _vector.h:227
const_reference at(size_type __n) const
Definition: _vector.h:172
_Vector_nonconst_traits< _Tp, _NcIt > _NonConstTraits
Definition: _vector.h:64
bool empty() const
Definition: _vector.h:159
_Vector_const_traits< _Tp, _NcIt > _ConstTraits
Definition: _vector.h:73
#define _STLP_MOVE_TO_PRIV_NAMESPACE
Definition: features.h:524
void _Compare_Capacity(size_type __old_capacity)
Definition: _vector.h:135
vector(const _Self &__x)
Definition: _vector.h:190
_STLP_NON_DBG_VECTOR _Base
Definition: _vector.h:108
_Bit_const_iterator::pointer pointer
Definition: _vector.h:90
_Bit_iterator::reference reference
Definition: _vector.h:80
void reserve(size_type __n)
Definition: _vector.h:242
iterator insert(iterator __pos, const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.c:223
const_reverse_iterator rbegin() const
Definition: _vector.h:152
_Bit_const_iterator::value_type value_type
Definition: _vector.h:88
#define _STLP_DEFAULT_CONSTRUCTED(_TTp)
Definition: _construct.h:265
_STLP_PRIV _DBG_iter< _Base, _STLP_PRIV _DbgTraits< _STLP_PRIV _Vector_const_traits< value_type, typename _Base::iterator > > > const_iterator
Definition: _vector.h:121
vector(size_type __n, const _Tp &__x=_Tp(), const allocator_type &__a=allocator_type())
Definition: _vector.h:178
_STLP_PRIV _DBG_iter< _Base, _STLP_PRIV _DbgTraits< _STLP_PRIV _Vector_nonconst_traits< value_type, typename _Base::iterator > > > iterator
Definition: _vector.h:118
#define _STLP_NON_DBG_VECTOR
Definition: _vector.h:37
value_type * iterator
Definition: _vector.h:124
_STLP_INLINE_LOOP _InputIter __last
Definition: _algo.h:68
#define __IMPORT_CONTAINER_TYPEDEFS(_Super)
Definition: features.h:750
_Iterator _Non_Dbg_iter(_Iterator __it)
Definition: _iterator.h:362
typedef bool(CARDLIBPROC *pCanDragProc)(CardRegion &stackobj
const_reference operator[](size_type __n) const
Definition: _vector.h:166
_Vector_const_traits< bool, _Bit_iterator > _ConstTraits
Definition: _vector.h:82
_Vector_nonconst_traits< bool, _Bit_iterator > _NonConstTraits
Definition: _vector.h:92
#define _STLP_MOVE_TO_STD_NAMESPACE
Definition: features.h:525
void get(int argc, const char *argv[])
Definition: cmds.c:480
const_iterator begin() const
Definition: _vector.h:147
vector< _Tp, _Alloc > _Self
Definition: _vector.h:109
iterator insert(iterator __pos, const _Tp &__x=_Tp())
Definition: _vector.h:274
allocator_type get_allocator() const
Definition: _vector.h:144
const_reference back() const
Definition: _vector.h:260
#define _STLP_ALLOCATOR_TYPE_DFL
Definition: features.h:691
_STLP_INLINE_LOOP _InputIter const _Tp & __val
Definition: _algobase.h:656
reference at(size_type __n)
Definition: _vector.h:171
void assign(const value_type *__first, const value_type *__last)
Definition: _vector.h:390
void pop_back()
Definition: _vector.h:341
_STLP_MOVE_TO_PRIV_NAMESPACE const _InputIterator const input_iterator_tag &_InputIterator __it(__first)
_Vector_nonconst_traits< bool, _Bit_iterator > _NonConstTraits
Definition: _vector.h:83
vector(const allocator_type &__a=allocator_type())
Definition: _vector.h:174
iterator erase(iterator __pos)
Definition: _vector.h:346
_Base _M_non_dbg_impl
Definition: _vector.h:111
iterator begin()
Definition: _vector.h:146
_STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS
Definition: _vector.h:133
GLint reference
Definition: glext.h:11729
#define _STLP_PRIV
Definition: _dm.h:70
void _Invalidate_iterators(const iterator &__first, const iterator &__last)
Definition: _vector.h:128
void _Check_Overflow(size_type __nb)
Definition: _vector.h:131
reference front()
Definition: _vector.h:248
#define _STLP_DEBUG_CHECK(expr)
Definition: _debug.h:440
GLenum src
Definition: glext.h:6340
const _Tp & reference
Definition: _vector.h:71
#define _STLP_TEMPLATE_NULL
Definition: features.h:652
_STLP_PRIV __construct_checker< _STLP_NON_DBG_VECTOR > _ConstructCheck
Definition: _vector.h:110
void assign(size_type __n, const _Tp &__val)
Definition: _vector.h:315
const value_type * const_iterator
Definition: _vector.h:125
_Vector_const_traits< _Tp, _NcIt > _ConstTraits
Definition: _vector.h:63
#define _STLP_END_NAMESPACE
Definition: features.h:503
reference back()
Definition: _vector.h:256
_Base::allocator_type allocator_type
Definition: _vector.h:119
const_reverse_iterator rend() const
Definition: _vector.h:154
void insert(iterator __pos, size_type __n, const _Tp &__x)
Definition: _vector.h:335
size_type size() const
Definition: _vector.h:192
size_type capacity() const
Definition: _vector.h:199
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
void push_back(const _Tp &__x)
Definition: _vector.h:411
reverse_iterator rbegin()
Definition: _vector.h:151
_Vector_const_traits< bool, _Bit_iterator > _ConstTraits
Definition: _vector.h:91
_Nonconst_traits< _Tp > _BaseT
Definition: _vector.h:59
_STLP_PRIV __owned_list _M_iter_list
Definition: _vector.h:112
void swap(_Self &__x)
Definition: _vector.h:265
void clear()
Definition: _vector.h:407
void insert(iterator __pos, const_iterator __first, const_iterator __last)
Definition: _vector.h:313
_Const_traits< _Tp > _BaseT
Definition: _vector.h:69
reference operator[](size_type __n)
Definition: _vector.h:161
#define _STLP_VERBOSE_ASSERT(expr, diagnostic)
Definition: _debug.h:439