ReactOS  0.4.13-dev-73-gcfe54aa
_iterator.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 1997
4  * Moscow Center for SPARC Technology
5  *
6  * Copyright (c) 1999
7  * Boris Fomitchev
8  *
9  * This material is provided "as is", with absolutely no warranty expressed
10  * or implied. Any use is at your own risk.
11  *
12  * Permission to use or copy this software for any purpose is hereby granted
13  * without fee, provided the above notices are retained on all copies.
14  * Permission to modify the code and to distribute modified code is granted,
15  * provided the above notices are retained, and a notice that the code was
16  * modified is included with the above copyright notice.
17  *
18  */
19 
20 #ifndef _STLP_DBG_ITERATOR_H
21 #define _STLP_DBG_ITERATOR_H
22 
23 #ifndef _STLP_INTERNAL_PAIR_H
24 # include <stl/_pair.h>
25 #endif
26 
27 #ifndef _STLP_INTERNAL_ALLOC_H
28 # include <stl/_alloc.h>
29 #endif
30 
33 
34 //============================================================
35 
36 template <class _Iterator>
37 void _Decrement(_Iterator& __it, const bidirectional_iterator_tag &)
38 { --__it; }
39 
40 template <class _Iterator>
41 void _Decrement(_Iterator& __it, const random_access_iterator_tag &)
42 { --__it; }
43 
44 template <class _Iterator>
45 void _Decrement(_Iterator& __it, const forward_iterator_tag &)
46 { _STLP_ASSERT(0) }
47 
48 template <class _Iterator>
49 void _Advance(_Iterator&, ptrdiff_t, const forward_iterator_tag &)
50 { _STLP_ASSERT(0) }
51 
52 template <class _Iterator>
54 { _STLP_ASSERT(0) }
55 
56 template <class _Iterator>
58 { __it += __n; }
59 
60 template <class _Iterator>
61 ptrdiff_t _DBG_distance(const _Iterator& __x, const _Iterator& __y, const random_access_iterator_tag &)
62 { return __x - __y; }
63 
64 template <class _Iterator>
65 ptrdiff_t _DBG_distance(const _Iterator&, const _Iterator&, const forward_iterator_tag &) {
66  _STLP_ASSERT(0)
67  return 0;
68 }
69 
70 template <class _Iterator>
71 ptrdiff_t _DBG_distance(const _Iterator&, const _Iterator&, const bidirectional_iterator_tag &) {
72  _STLP_ASSERT(0)
73  return 0;
74 }
75 
76 template <class _Iterator>
77 bool _CompareIt(const _Iterator&, const _Iterator&, const forward_iterator_tag &) {
78  _STLP_ASSERT(0)
79  return false;
80 }
81 
82 template <class _Iterator>
83 bool _CompareIt(const _Iterator&, const _Iterator&, const bidirectional_iterator_tag &) {
84  _STLP_ASSERT(0)
85  return false;
86 }
87 
88 template <class _Iterator>
89 bool _CompareIt(const _Iterator& __x, const _Iterator& __y, const random_access_iterator_tag &)
90 { return __x < __y; }
91 
92 template <class _Iterator>
93 bool _Dereferenceable(const _Iterator& __it)
94 { return (__it._Get_container_ptr() != 0) && !(__it._M_iterator == (__it._Get_container_ptr())->end()); }
95 
96 template <class _Iterator>
97 bool _Incrementable(const _Iterator& __it, ptrdiff_t __n, const forward_iterator_tag &)
98 { return (__n == 1) && _Dereferenceable(__it); }
99 
100 template <class _Iterator>
101 bool _Incrementable(const _Iterator& __it, ptrdiff_t __n, const bidirectional_iterator_tag &) {
102  typedef typename _Iterator::_Container_type __container_type;
103  __container_type* __c = __it._Get_container_ptr();
104  return (__c != 0) && ((__n == 1 && __it._M_iterator != __c->end() ) ||
105  (__n == -1 && __it._M_iterator != __c->begin()));
106 }
107 
108 template <class _Iterator>
109 bool _Incrementable(const _Iterator& __it, ptrdiff_t __n, const random_access_iterator_tag &) {
110  typedef typename _Iterator::_Container_type __container_type;
111  __container_type* __c = __it._Get_container_ptr();
112  if (__c == 0) return false;
113  ptrdiff_t __new_pos = (__it._M_iterator - __c->begin()) + __n;
114  return (__new_pos >= 0) && (__STATIC_CAST(typename __container_type::size_type, __new_pos) <= __c->size());
115 }
116 
117 
118 template <class _Container>
119 struct _DBG_iter_base : public __owned_link {
120 public:
121  typedef typename _Container::value_type value_type;
123  typedef typename _Container::pointer pointer;
125  //private:
126  typedef typename _Container::iterator _Nonconst_iterator;
127  typedef typename _Container::const_iterator _Const_iterator;
128  typedef _Container _Container_type;
129 
130 #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
132 #else
133  typedef typename _Container::_Iterator_category _Iterator_category;
134 #endif
136 
137  _DBG_iter_base() : __owned_link(0) {}
138  _DBG_iter_base(const __owned_list* __c, const _Const_iterator& __it) :
139 #if defined(__HP_aCC) && (__HP_aCC < 60000)
141 #else
142  __owned_link(__c), _M_iterator(*(const _Nonconst_iterator*)&__it) {}
143 #endif
144  _Container* _Get_container_ptr() const {
145  return (_Container*)__stl_debugger::_Get_container_ptr(this);
146  }
147 
148  void __increment();
149  void __decrement();
150  void __advance(ptrdiff_t __n);
151 
152 // protected:
154 };
155 
156 template <class _Container>
159  ++_M_iterator;
160 }
161 
162 template <class _Container>
165  _Decrement(_M_iterator, _Iterator_category());
166 }
167 
168 template <class _Container>
171  _Advance(_M_iterator, __n, _Iterator_category());
172 }
173 
174 template <class _Container>
176  const _DBG_iter_base<_Container>& __y ) {
177  typedef typename _DBG_iter_base<_Container>::_Iterator_category _Iterator_category;
178  _STLP_DEBUG_CHECK(__check_same_owner(__x, __y))
179  return _DBG_distance(__x._M_iterator,__y._M_iterator, _Iterator_category());
180 }
181 
182 template <class _Container, class _Traits>
183 struct _DBG_iter_mid : public _DBG_iter_base<_Container> {
185  typedef typename _Container::iterator _Nonconst_iterator;
186  typedef typename _Container::const_iterator _Const_iterator;
187 
189 
190  explicit _DBG_iter_mid(const _Nonconst_self& __it) :
191  _DBG_iter_base<_Container>(__it) {}
192 
193  _DBG_iter_mid(const __owned_list* __c, const _Const_iterator& __it) :
194  _DBG_iter_base<_Container>(__c, __it) {}
195 };
196 
197 template <class _Container, class _Traits>
198 struct _DBG_iter : public _DBG_iter_mid<_Container, _Traits> {
200 public:
201  typedef typename _Base::value_type value_type;
203  typedef typename _Traits::reference reference;
204  typedef typename _Traits::pointer pointer;
205 
208 
209 private:
212 
213 public:
214 
215 #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
217 #endif
219 
220 public:
222  // boris : real type of iter would be nice
223  _DBG_iter(const __owned_list* __c, const _Const_iterator& __it) :
224  _DBG_iter_mid<_Container, _Traits>(__c, __it) {}
225 
226  // This allows conversions from iterator to const_iterator without being
227  // redundant with the copy constructor below.
228  _DBG_iter(const _Nonconst_mid& __rhs) :
229  _DBG_iter_mid<_Container, _Traits>(__rhs) {}
230 
231  _DBG_iter(const _Self& __rhs) :
232  _DBG_iter_mid<_Container, _Traits>(__rhs) {}
233 
234  // This allows conversions from iterator to const_iterator without being
235  // redundant with the copy assignment operator below.
236  _Self& operator=(const _Nonconst_mid& __rhs) {
237  (_Base&)*this = __rhs;
238  return *this;
239  }
240 
241  _Self& operator=(const _Self& __rhs) {
242  (_Base&)*this = __rhs;
243  return *this;
244  }
245 
246  reference operator*() const;
247 
249 
251  this->__increment();
252  return *this;
253  }
254  _Self operator++(int) {
255  _Self __tmp = *this;
256  this->__increment();
257  return __tmp;
258  }
260  this->__decrement();
261  return *this;
262  }
263  _Self operator--(int) {
264  _Self __tmp = *this;
265  this->__decrement();
266  return __tmp;
267  }
268 
270  this->__advance(__n);
271  return *this;
272  }
273 
275  this->__advance(-__n);
276  return *this;
277  }
279  _Self __tmp(*this);
280  __tmp.__advance(__n);
281  return __tmp;
282  }
284  _Self __tmp(*this);
285  __tmp.__advance(-__n);
286  return __tmp;
287  }
288  reference operator[](difference_type __n) const { return *(*this + __n); }
289 };
290 
291 template <class _Container, class _Traits>
292 inline
293 #if defined (_STLP_NESTED_TYPE_PARAM_BUG)
295 #else
297 #endif
300  _STLP_DEBUG_CHECK(_Traits::_Check(*this))
301  return *this->_M_iterator;
302 }
303 
304 template <class _Container>
305 inline bool
307  _STLP_DEBUG_CHECK(__check_same_or_null_owner(__x, __y))
308  return __x._M_iterator == __y._M_iterator;
309 }
310 
311 template <class _Container>
312 inline bool
314  _STLP_DEBUG_CHECK(__check_same_or_null_owner(__x, __y))
315  typedef typename _DBG_iter_base<_Container>::_Iterator_category _Category;
316  return _CompareIt(__x._M_iterator , __y._M_iterator, _Category());
317 }
318 
319 template <class _Container>
320 inline bool
322  const _DBG_iter_base<_Container>& __y) {
323  typedef typename _DBG_iter_base<_Container>::_Iterator_category _Category;
324  return _CompareIt(__y._M_iterator , __x._M_iterator, _Category());
325 }
326 
327 template <class _Container>
328 inline bool
330  _STLP_DEBUG_CHECK(__check_same_or_null_owner(__x, __y))
331  typedef typename _DBG_iter_base<_Container>::_Iterator_category _Category;
332  return !_CompareIt(__x._M_iterator , __y._M_iterator, _Category());
333 }
334 
335 template <class _Container>
336 inline bool
338  const _DBG_iter_base<_Container>& __y) {
339  typedef typename _DBG_iter_base<_Container>::_Iterator_category _Category;
340  return !_CompareIt(__y._M_iterator , __x._M_iterator, _Category());
341 }
342 
343 template <class _Container>
344 inline bool
346  const _DBG_iter_base<_Container>& __y) {
347  _STLP_DEBUG_CHECK(__check_same_or_null_owner(__x, __y))
348  return __x._M_iterator != __y._M_iterator;
349 }
350 
351 //------------------------------------------
352 
353 template <class _Container, class _Traits>
357  return __tmp += __n;
358 }
359 
360 
361 template <class _Iterator>
362 inline _Iterator _Non_Dbg_iter(_Iterator __it)
363 { return __it; }
364 
365 #if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
366 template <class _Container, class _Traits>
369 { return __it._M_iterator; }
370 #endif
371 
372 /*
373  * Helper classes to check iterator range or pointer validity
374  * at construction time.
375  */
376 template <class _Container>
378  typedef typename _Container::value_type value_type;
379 protected:
381 
383  _STLP_VERBOSE_ASSERT((__p != 0), _StlMsg_INVALID_ARGUMENT)
384  }
385 
386 #if defined (_STLP_MEMBER_TEMPLATES)
387  template <class _InputIter>
388  __construct_checker(const _InputIter& __f, const _InputIter& __l) {
389  typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
390  _M_check_dispatch(__f, __l, _Integral());
391  }
392 
393  template <class _Integer>
394  void _M_check_dispatch(_Integer , _Integer, const __true_type& /*IsIntegral*/) {}
395 
396  template <class _InputIter>
397  void _M_check_dispatch(const _InputIter& __f, const _InputIter& __l, const __false_type& /*IsIntegral*/) {
398  _STLP_DEBUG_CHECK(__check_range(__f,__l))
399  }
400 #endif
401 
402 #if !defined (_STLP_MEMBER_TEMPLATES) || !defined (_STLP_NO_METHOD_SPECIALIZATION)
403  __construct_checker(const value_type* __f, const value_type* __l) {
404  _STLP_DEBUG_CHECK(__check_ptr_range(__f,__l))
405  }
406 
408  __construct_checker(const _IteType& __f, const _IteType& __l) {
409  _STLP_DEBUG_CHECK(__check_range(__f,__l))
410  }
411 #endif
412 #if defined (__BORLANDC__)
414 #endif
415 };
416 
417 #if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
418 # if defined (_STLP_NESTED_TYPE_PARAM_BUG) ||\
419  (defined (__SUNPRO_CC) && __SUNPRO_CC < 0x600)
420 # define _STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS 1
421 # endif
422 
424 
425 template <class _Container>
426 inline ptrdiff_t*
427 distance_type(const _STLP_PRIV _DBG_iter_base<_Container>&) { return (ptrdiff_t*) 0; }
428 
429 # if !defined (_STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS)
430 template <class _Container>
432 value_type(const _STLP_PRIV _DBG_iter_base<_Container>&) {
434  return (_Val*)0;
435 }
436 
437 template <class _Container>
439 iterator_category(const _STLP_PRIV _DBG_iter_base<_Container>&) {
441  return _Category();
442 }
443 # endif
444 
446 
447 #endif /* _STLP_USE_OLD_HP_ITERATOR_QUERIES */
448 
450 
452 
453 #endif /* INTERNAL_H */
454 
455 // Local Variables:
456 // mode:C++
457 // End:
_Base::value_type value_type
Definition: _iterator.h:201
_DBG_iter_mid< _Container, typename _Traits::_NonConstTraits > _Nonconst_self
Definition: _iterator.h:184
_Container::_Iterator_category _Iterator_category
Definition: _iterator.h:133
bool operator==(const _DBG_iter_base< _Container > &__x, const _DBG_iter_base< _Container > &__y)
Definition: _iterator.h:306
_DBG_iter_base< _Container > _Base
Definition: _iterator.h:199
_Self & operator=(const _Nonconst_mid &__rhs)
Definition: _iterator.h:236
_DBG_iter_mid(const _Nonconst_self &__it)
Definition: _iterator.h:190
_Self operator--(int)
Definition: _iterator.h:263
_DBG_iter< _Container, _Traits > _Self
Definition: _iterator.h:210
_Container::value_type value_type
Definition: _iterator.h:121
return __n
Definition: _algo.h:75
bool _Incrementable(const _Iterator &__it, ptrdiff_t __n, const forward_iterator_tag &)
Definition: _iterator.h:97
void __decrement()
Definition: _iterator.h:163
GLsizei const GLvoid * pointer
Definition: glext.h:5848
_Self & operator+=(difference_type __n)
Definition: _iterator.h:269
#define _STLP_TYPENAME
Definition: features.h:612
#define __STATIC_CAST(__x, __y)
Definition: features.h:585
_DBG_iter_mid(const __owned_list *__c, const _Const_iterator &__it)
Definition: _iterator.h:193
bool operator!=(const _DBG_iter_base< _Container > &__x, const _DBG_iter_base< _Container > &__y)
Definition: _iterator.h:345
bool operator>=(const _DBG_iter_base< _Container > &__x, const _DBG_iter_base< _Container > &__y)
Definition: _iterator.h:329
_Self & operator=(const _Self &__rhs)
Definition: _iterator.h:241
bool _Dereferenceable(const _Iterator &__it)
Definition: _iterator.h:93
_Container::iterator _Nonconst_iterator
Definition: _iterator.h:126
_DBG_iter_base(const __owned_list *__c, const _Const_iterator &__it)
Definition: _iterator.h:138
_Iterator_category iterator_category
Definition: _iterator.h:135
_DBG_iter_mid< _Container, typename _Traits::_NonConstTraits > _Nonconst_mid
Definition: _iterator.h:211
ptrdiff_t operator-(const _DBG_iter_base< _Container > &__x, const _DBG_iter_base< _Container > &__y)
Definition: _iterator.h:175
GLuint GLuint end
Definition: gl.h:1545
#define __c
Definition: schilyio.h:209
_Container::pointer pointer
Definition: _iterator.h:123
#define _STLP_MOVE_TO_PRIV_NAMESPACE
Definition: features.h:524
_DBG_iter_base< _Container > _IteType
Definition: _iterator.h:407
_DBG_iter< _Container, _Traits > operator+(ptrdiff_t __n, const _DBG_iter< _Container, _Traits > &__it)
Definition: _iterator.h:355
void __advance(ptrdiff_t __n)
Definition: _iterator.h:169
_Traits::reference reference
Definition: _iterator.h:203
_Self operator+(difference_type __n) const
Definition: _iterator.h:278
_Self & operator-=(difference_type __n)
Definition: _iterator.h:274
_Container::reference reference
Definition: _iterator.h:122
__construct_checker(const _IteType &__f, const _IteType &__l)
Definition: _iterator.h:408
_Iterator _Non_Dbg_iter(_Iterator __it)
Definition: _iterator.h:362
ptrdiff_t _DBG_distance(const _Iterator &__x, const _Iterator &__y, const random_access_iterator_tag &)
Definition: _iterator.h:61
_STLP_DEFINE_ARROW_OPERATOR _Self & operator++()
Definition: _iterator.h:250
bool operator<(const _DBG_iter_base< _Container > &__x, const _DBG_iter_base< _Container > &__y)
Definition: _iterator.h:313
#define _STLP_MOVE_TO_STD_NAMESPACE
Definition: features.h:525
_Base::_Nonconst_iterator _Nonconst_iterator
Definition: _iterator.h:206
if(!(yy_init))
Definition: macro.lex.yy.c:714
__construct_checker(const value_type *__p)
Definition: _iterator.h:382
void __increment()
Definition: _iterator.h:157
_Self operator-(difference_type __n) const
Definition: _iterator.h:283
_Base::_Const_iterator _Const_iterator
Definition: _iterator.h:207
_Base::difference_type difference_type
Definition: _iterator.h:202
_STLP_BEGIN_NAMESPACE _STLP_MOVE_TO_PRIV_NAMESPACE void _Decrement(_Iterator &__it, const bidirectional_iterator_tag &)
Definition: _iterator.h:37
_STLP_MOVE_TO_PRIV_NAMESPACE const _InputIterator const input_iterator_tag &_InputIterator __it(__first)
bool _CompareIt(const _Iterator &, const _Iterator &, const forward_iterator_tag &)
Definition: _iterator.h:77
_Container::const_iterator _Const_iterator
Definition: _iterator.h:186
__construct_checker(const value_type *__f, const value_type *__l)
Definition: _iterator.h:403
GLint reference
Definition: glext.h:11729
#define _STLP_PRIV
Definition: _dm.h:70
_Container::value_type value_type
Definition: _iterator.h:378
_DBG_iter(const _Self &__rhs)
Definition: _iterator.h:231
#define _STLP_DEBUG_CHECK(expr)
Definition: _debug.h:440
#define __REINTERPRET_CAST(__x, __y)
Definition: features.h:586
_In_ int _Val
Definition: memory.h:91
bool operator>(const _DBG_iter_base< _Container > &__x, const _DBG_iter_base< _Container > &__y)
Definition: _iterator.h:321
_Container::iterator _Nonconst_iterator
Definition: _iterator.h:185
#define _STLP_END_NAMESPACE
Definition: features.h:503
_Nonconst_iterator _M_iterator
Definition: _iterator.h:153
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
reference operator *() const
Definition: _iterator.h:298
#define _STLP_ASSERT(expr)
Definition: _debug.h:165
#define _STLP_DEFINE_ARROW_OPERATOR
#define _STLP_TYPENAME_ON_RETURN_TYPE
Definition: features.h:600
_DBG_iter(const __owned_list *__c, const _Const_iterator &__it)
Definition: _iterator.h:223
_Self operator++(int)
Definition: _iterator.h:254
_Container::const_iterator _Const_iterator
Definition: _iterator.h:127
#define const
Definition: zconf.h:230
_DBG_iter(const _Nonconst_mid &__rhs)
Definition: _iterator.h:228
_Container * _Get_container_ptr() const
Definition: _iterator.h:144
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
_Base::_Iterator_category _Iterator_category
Definition: _iterator.h:218
_Container _Container_type
Definition: _iterator.h:128
_Traits::pointer pointer
Definition: _iterator.h:204
bool operator<=(const _DBG_iter_base< _Container > &__x, const _DBG_iter_base< _Container > &__y)
Definition: _iterator.h:337
_Iterator::iterator_category iterator_category
reference operator[](difference_type __n) const
Definition: _iterator.h:288
ptrdiff_t difference_type
Definition: _iterator.h:124
void _Advance(_Iterator &, ptrdiff_t, const forward_iterator_tag &)
Definition: _iterator.h:49
_Self & operator--()
Definition: _iterator.h:259
#define _STLP_VERBOSE_ASSERT(expr, diagnostic)
Definition: _debug.h:439