ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

_iterator.h
Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (c) 1997
00004  * Moscow Center for SPARC Technology
00005  *
00006  * Copyright (c) 1999
00007  * Boris Fomitchev
00008  *
00009  * This material is provided "as is", with absolutely no warranty expressed
00010  * or implied. Any use is at your own risk.
00011  *
00012  * Permission to use or copy this software for any purpose is hereby granted
00013  * without fee, provided the above notices are retained on all copies.
00014  * Permission to modify the code and to distribute modified code is granted,
00015  * provided the above notices are retained, and a notice that the code was
00016  * modified is included with the above copyright notice.
00017  *
00018  */
00019 
00020 #ifndef _STLP_DBG_ITERATOR_H
00021 #define _STLP_DBG_ITERATOR_H
00022 
00023 #ifndef _STLP_INTERNAL_PAIR_H
00024 #  include <stl/_pair.h>
00025 #endif
00026 
00027 #ifndef _STLP_INTERNAL_ALLOC_H
00028 #  include <stl/_alloc.h>
00029 #endif
00030 
00031 _STLP_BEGIN_NAMESPACE
00032 _STLP_MOVE_TO_PRIV_NAMESPACE
00033 
00034 //============================================================
00035 
00036 template <class _Iterator>
00037 void _Decrement(_Iterator& __it, const bidirectional_iterator_tag &)
00038 { --__it; }
00039 
00040 template <class _Iterator>
00041 void _Decrement(_Iterator& __it, const random_access_iterator_tag &)
00042 { --__it; }
00043 
00044 template <class _Iterator>
00045 void _Decrement(_Iterator& __it, const forward_iterator_tag &)
00046 { _STLP_ASSERT(0) }
00047 
00048 template <class _Iterator>
00049 void _Advance(_Iterator&, ptrdiff_t, const forward_iterator_tag &)
00050 { _STLP_ASSERT(0) }
00051 
00052 template <class _Iterator>
00053 void _Advance(_Iterator& __it, ptrdiff_t, const bidirectional_iterator_tag &)
00054 { _STLP_ASSERT(0) }
00055 
00056 template <class _Iterator>
00057 void _Advance(_Iterator& __it, ptrdiff_t __n, const random_access_iterator_tag &)
00058 { __it += __n; }
00059 
00060 template <class _Iterator>
00061 ptrdiff_t _DBG_distance(const _Iterator& __x, const _Iterator& __y, const random_access_iterator_tag &)
00062 { return __x - __y; }
00063 
00064 template <class _Iterator>
00065 ptrdiff_t _DBG_distance(const _Iterator&, const _Iterator&, const forward_iterator_tag &) {
00066   _STLP_ASSERT(0)
00067   return 0;
00068 }
00069 
00070 template <class _Iterator>
00071 ptrdiff_t _DBG_distance(const _Iterator&, const _Iterator&, const bidirectional_iterator_tag &) {
00072   _STLP_ASSERT(0)
00073   return 0;
00074 }
00075 
00076 template <class _Iterator>
00077 bool _CompareIt(const _Iterator&, const _Iterator&, const forward_iterator_tag &) {
00078   _STLP_ASSERT(0)
00079   return false;
00080 }
00081 
00082 template <class _Iterator>
00083 bool _CompareIt(const _Iterator&, const _Iterator&, const bidirectional_iterator_tag &) {
00084   _STLP_ASSERT(0)
00085   return false;
00086 }
00087 
00088 template <class _Iterator>
00089 bool _CompareIt(const _Iterator& __x, const _Iterator& __y, const random_access_iterator_tag &)
00090 { return __x < __y; }
00091 
00092 template <class _Iterator>
00093 bool _Dereferenceable(const _Iterator& __it)
00094 { return (__it._Get_container_ptr() != 0) && !(__it._M_iterator == (__it._Get_container_ptr())->end()); }
00095 
00096 template <class _Iterator>
00097 bool _Incrementable(const _Iterator& __it, ptrdiff_t __n, const forward_iterator_tag &)
00098 { return (__n == 1) && _Dereferenceable(__it); }
00099 
00100 template <class _Iterator>
00101 bool _Incrementable(const _Iterator& __it, ptrdiff_t __n, const bidirectional_iterator_tag &) {
00102   typedef typename _Iterator::_Container_type __container_type;
00103   __container_type* __c = __it._Get_container_ptr();
00104   return (__c != 0) && ((__n == 1 && __it._M_iterator != __c->end() ) ||
00105                         (__n == -1 && __it._M_iterator != __c->begin()));
00106 }
00107 
00108 template <class _Iterator>
00109 bool _Incrementable(const _Iterator& __it, ptrdiff_t __n, const random_access_iterator_tag &) {
00110   typedef typename _Iterator::_Container_type __container_type;
00111   __container_type* __c = __it._Get_container_ptr();
00112   if (__c == 0) return false;
00113   ptrdiff_t __new_pos = (__it._M_iterator - __c->begin()) + __n;
00114   return  (__new_pos >= 0) && (__STATIC_CAST(typename __container_type::size_type, __new_pos) <= __c->size());
00115 }
00116 
00117 
00118 template <class _Container>
00119 struct _DBG_iter_base : public __owned_link {
00120 public:
00121   typedef typename _Container::value_type value_type;
00122   typedef typename _Container::reference  reference;
00123   typedef typename _Container::pointer    pointer;
00124   typedef ptrdiff_t difference_type;
00125   //private:
00126   typedef typename _Container::iterator        _Nonconst_iterator;
00127   typedef typename _Container::const_iterator  _Const_iterator;
00128   typedef _Container                     _Container_type;
00129 
00130 #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
00131   typedef typename iterator_traits<_Const_iterator>::iterator_category _Iterator_category;
00132 #else
00133   typedef typename _Container::_Iterator_category  _Iterator_category;
00134 #endif
00135   typedef _Iterator_category iterator_category;
00136 
00137   _DBG_iter_base() : __owned_link(0)  {}
00138   _DBG_iter_base(const __owned_list* __c, const _Const_iterator& __it) :
00139 #if defined(__HP_aCC) && (__HP_aCC < 60000)
00140   __owned_link(__c), _M_iterator(*__REINTERPRET_CAST(const _Nonconst_iterator *, &__it)) {}
00141 #else
00142     __owned_link(__c), _M_iterator(*(const _Nonconst_iterator*)&__it) {}
00143 #endif
00144   _Container* _Get_container_ptr() const {
00145     return (_Container*)__stl_debugger::_Get_container_ptr(this);
00146   }
00147 
00148   void __increment();
00149   void __decrement();
00150   void __advance(ptrdiff_t __n);
00151 
00152 // protected:
00153   _Nonconst_iterator _M_iterator;
00154 };
00155 
00156 template <class _Container>
00157 inline void _DBG_iter_base<_Container>::__increment() {
00158   _STLP_DEBUG_CHECK(_Incrementable(*this, 1, _Iterator_category()))
00159   ++_M_iterator;
00160 }
00161 
00162 template <class _Container>
00163 inline void _DBG_iter_base<_Container>::__decrement() {
00164   _STLP_DEBUG_CHECK(_Incrementable(*this, -1, _Iterator_category()))
00165   _Decrement(_M_iterator, _Iterator_category());
00166 }
00167 
00168 template <class _Container>
00169 inline void _DBG_iter_base<_Container>::__advance(ptrdiff_t __n) {
00170   _STLP_DEBUG_CHECK(_Incrementable(*this, __n, _Iterator_category()))
00171   _Advance(_M_iterator, __n, _Iterator_category());
00172 }
00173 
00174 template <class _Container>
00175 ptrdiff_t operator-(const _DBG_iter_base<_Container>& __x,
00176                     const _DBG_iter_base<_Container>& __y ) {
00177   typedef typename _DBG_iter_base<_Container>::_Iterator_category  _Iterator_category;
00178   _STLP_DEBUG_CHECK(__check_same_owner(__x, __y))
00179   return _DBG_distance(__x._M_iterator,__y._M_iterator, _Iterator_category());
00180 }
00181 
00182 template <class _Container, class _Traits>
00183 struct _DBG_iter_mid : public _DBG_iter_base<_Container> {
00184   typedef _DBG_iter_mid<_Container, typename _Traits::_NonConstTraits> _Nonconst_self;
00185   typedef typename _Container::iterator        _Nonconst_iterator;
00186   typedef typename _Container::const_iterator  _Const_iterator;
00187 
00188   _DBG_iter_mid() {}
00189 
00190   explicit _DBG_iter_mid(const _Nonconst_self& __it) :
00191       _DBG_iter_base<_Container>(__it) {}
00192 
00193   _DBG_iter_mid(const __owned_list* __c, const _Const_iterator& __it) :
00194       _DBG_iter_base<_Container>(__c, __it) {}
00195 };
00196 
00197 template <class _Container, class _Traits>
00198 struct _DBG_iter : public _DBG_iter_mid<_Container, _Traits> {
00199   typedef _DBG_iter_base<_Container>          _Base;
00200 public:
00201   typedef typename _Base::value_type value_type;
00202   typedef typename _Base::difference_type difference_type;
00203   typedef typename _Traits::reference  reference;
00204   typedef typename _Traits::pointer    pointer;
00205 
00206   typedef typename _Base::_Nonconst_iterator _Nonconst_iterator;
00207   typedef typename _Base::_Const_iterator _Const_iterator;
00208 
00209 private:
00210   typedef _DBG_iter<_Container, _Traits>     _Self;
00211   typedef _DBG_iter_mid<_Container, typename _Traits::_NonConstTraits> _Nonconst_mid;
00212 
00213 public:
00214 
00215 #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
00216   typedef typename _Base::iterator_category iterator_category;
00217 #endif
00218   typedef typename _Base::_Iterator_category  _Iterator_category;
00219 
00220 public:
00221   _DBG_iter() {}
00222     // boris : real type of iter would be nice
00223   _DBG_iter(const __owned_list* __c, const _Const_iterator& __it) :
00224     _DBG_iter_mid<_Container, _Traits>(__c, __it) {}
00225 
00226   // This allows conversions from iterator to const_iterator without being
00227   // redundant with the copy constructor below.
00228   _DBG_iter(const _Nonconst_mid& __rhs) :
00229     _DBG_iter_mid<_Container, _Traits>(__rhs) {}
00230 
00231   _DBG_iter(const  _Self& __rhs) :
00232     _DBG_iter_mid<_Container, _Traits>(__rhs) {}
00233 
00234   // This allows conversions from iterator to const_iterator without being
00235   // redundant with the copy assignment operator below.
00236   _Self& operator=(const _Nonconst_mid& __rhs) {
00237     (_Base&)*this = __rhs;
00238     return *this;
00239   }
00240 
00241   _Self& operator=(const  _Self& __rhs) {
00242     (_Base&)*this = __rhs;
00243     return *this;
00244   }
00245 
00246   reference operator*() const;
00247 
00248   _STLP_DEFINE_ARROW_OPERATOR
00249 
00250   _Self& operator++() {
00251     this->__increment();
00252     return *this;
00253   }
00254   _Self operator++(int) {
00255     _Self __tmp = *this;
00256     this->__increment();
00257     return __tmp;
00258   }
00259   _Self& operator--() {
00260     this->__decrement();
00261     return *this;
00262   }
00263   _Self operator--(int) {
00264     _Self __tmp = *this;
00265     this->__decrement();
00266     return __tmp;
00267   }
00268 
00269   _Self& operator+=(difference_type __n) {
00270     this->__advance(__n);
00271     return *this;
00272   }
00273 
00274   _Self& operator-=(difference_type __n) {
00275     this->__advance(-__n);
00276     return *this;
00277   }
00278   _Self operator+(difference_type __n) const {
00279     _Self __tmp(*this);
00280     __tmp.__advance(__n);
00281     return __tmp;
00282   }
00283   _Self operator-(difference_type __n) const {
00284     _Self __tmp(*this);
00285     __tmp.__advance(-__n);
00286     return __tmp;
00287   }
00288   reference operator[](difference_type __n) const { return *(*this + __n); }
00289 };
00290 
00291 template <class _Container, class _Traits>
00292 inline
00293 #if defined (_STLP_NESTED_TYPE_PARAM_BUG)
00294 _STLP_TYPENAME_ON_RETURN_TYPE _Traits::reference
00295 #else
00296 _STLP_TYPENAME_ON_RETURN_TYPE _DBG_iter<_Container, _Traits>::reference
00297 #endif
00298 _DBG_iter<_Container, _Traits>::operator*() const {
00299   _STLP_DEBUG_CHECK(_Dereferenceable(*this))
00300   _STLP_DEBUG_CHECK(_Traits::_Check(*this))
00301   return *this->_M_iterator;
00302 }
00303 
00304 template <class _Container>
00305 inline bool
00306 operator==(const _DBG_iter_base<_Container>& __x, const _DBG_iter_base<_Container>& __y) {
00307   _STLP_DEBUG_CHECK(__check_same_or_null_owner(__x, __y))
00308   return __x._M_iterator == __y._M_iterator;
00309 }
00310 
00311 template <class _Container>
00312 inline bool
00313 operator<(const _DBG_iter_base<_Container>& __x, const _DBG_iter_base<_Container>& __y) {
00314   _STLP_DEBUG_CHECK(__check_same_or_null_owner(__x, __y))
00315   typedef typename _DBG_iter_base<_Container>::_Iterator_category _Category;
00316   return _CompareIt(__x._M_iterator , __y._M_iterator, _Category());
00317 }
00318 
00319 template <class _Container>
00320 inline bool
00321 operator>(const _DBG_iter_base<_Container>& __x,
00322        const _DBG_iter_base<_Container>& __y) {
00323   typedef typename _DBG_iter_base<_Container>::_Iterator_category _Category;
00324   return _CompareIt(__y._M_iterator , __x._M_iterator, _Category());
00325 }
00326 
00327 template <class _Container>
00328 inline bool
00329 operator>=(const _DBG_iter_base<_Container>& __x, const _DBG_iter_base<_Container>& __y) {
00330   _STLP_DEBUG_CHECK(__check_same_or_null_owner(__x, __y))
00331   typedef typename _DBG_iter_base<_Container>::_Iterator_category _Category;
00332   return !_CompareIt(__x._M_iterator , __y._M_iterator, _Category());
00333 }
00334 
00335 template <class _Container>
00336 inline bool
00337 operator<=(const _DBG_iter_base<_Container>& __x,
00338        const _DBG_iter_base<_Container>& __y) {
00339   typedef typename _DBG_iter_base<_Container>::_Iterator_category _Category;
00340   return !_CompareIt(__y._M_iterator , __x._M_iterator, _Category());
00341 }
00342 
00343 template <class _Container>
00344 inline bool
00345 operator!=(const _DBG_iter_base<_Container>& __x,
00346         const _DBG_iter_base<_Container>& __y) {
00347   _STLP_DEBUG_CHECK(__check_same_or_null_owner(__x, __y))
00348   return __x._M_iterator != __y._M_iterator;
00349 }
00350 
00351 //------------------------------------------
00352 
00353 template <class _Container, class _Traits>
00354 inline _DBG_iter<_Container, _Traits>
00355 operator+(ptrdiff_t __n, const _DBG_iter<_Container, _Traits>& __it) {
00356   _DBG_iter<_Container, _Traits> __tmp(__it);
00357   return __tmp += __n;
00358 }
00359 
00360 
00361 template <class _Iterator>
00362 inline _Iterator _Non_Dbg_iter(_Iterator __it)
00363 { return __it; }
00364 
00365 #if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
00366 template <class _Container, class _Traits>
00367 inline typename _DBG_iter<_Container, _Traits>::_Nonconst_iterator
00368 _Non_Dbg_iter(const _DBG_iter<_Container, _Traits>& __it)
00369 { return __it._M_iterator; }
00370 #endif
00371 
00372 /*
00373  * Helper classes to check iterator range or pointer validity
00374  * at construction time.
00375  */
00376 template <class _Container>
00377 class __construct_checker {
00378   typedef typename _Container::value_type value_type;
00379 protected:
00380   __construct_checker() {}
00381 
00382   __construct_checker(const value_type* __p) {
00383     _STLP_VERBOSE_ASSERT((__p != 0), _StlMsg_INVALID_ARGUMENT)
00384   }
00385 
00386 #if defined (_STLP_MEMBER_TEMPLATES)
00387   template <class _InputIter>
00388   __construct_checker(const _InputIter& __f, const _InputIter& __l) {
00389     typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
00390     _M_check_dispatch(__f, __l, _Integral());
00391   }
00392 
00393   template <class _Integer>
00394   void _M_check_dispatch(_Integer , _Integer, const __true_type& /*IsIntegral*/) {}
00395 
00396   template <class _InputIter>
00397   void _M_check_dispatch(const _InputIter& __f, const _InputIter& __l, const __false_type& /*IsIntegral*/) {
00398     _STLP_DEBUG_CHECK(__check_range(__f,__l))
00399   }
00400 #endif
00401 
00402 #if !defined (_STLP_MEMBER_TEMPLATES) || !defined (_STLP_NO_METHOD_SPECIALIZATION)
00403   __construct_checker(const value_type* __f, const value_type* __l) {
00404     _STLP_DEBUG_CHECK(__check_ptr_range(__f,__l))
00405   }
00406 
00407   typedef _DBG_iter_base<_Container> _IteType;
00408   __construct_checker(const _IteType& __f, const _IteType& __l) {
00409     _STLP_DEBUG_CHECK(__check_range(__f,__l))
00410   }
00411 #endif
00412 #if defined (__BORLANDC__)
00413   ~__construct_checker(){}
00414 #endif
00415 };
00416 
00417 #if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
00418 #  if defined (_STLP_NESTED_TYPE_PARAM_BUG) ||\
00419      (defined (__SUNPRO_CC) && __SUNPRO_CC < 0x600)
00420 #    define _STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS 1
00421 #  endif
00422 
00423 _STLP_MOVE_TO_STD_NAMESPACE
00424 
00425 template <class _Container>
00426 inline ptrdiff_t*
00427 distance_type(const _STLP_PRIV _DBG_iter_base<_Container>&) { return (ptrdiff_t*) 0; }
00428 
00429 #  if !defined (_STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS)
00430 template <class _Container>
00431 inline _STLP_TYPENAME_ON_RETURN_TYPE _STLP_PRIV _DBG_iter_base<_Container>::value_type*
00432 value_type(const _STLP_PRIV _DBG_iter_base<_Container>&) {
00433   typedef _STLP_TYPENAME _STLP_PRIV _DBG_iter_base<_Container>::value_type _Val;
00434   return (_Val*)0;
00435 }
00436 
00437 template <class _Container>
00438 inline _STLP_TYPENAME_ON_RETURN_TYPE _STLP_PRIV _DBG_iter_base<_Container>::_Iterator_category
00439 iterator_category(const _STLP_PRIV _DBG_iter_base<_Container>&) {
00440   typedef _STLP_TYPENAME _STLP_PRIV _DBG_iter_base<_Container>::_Iterator_category _Category;
00441   return _Category();
00442 }
00443 #  endif
00444 
00445 _STLP_MOVE_TO_PRIV_NAMESPACE
00446 
00447 #endif /* _STLP_USE_OLD_HP_ITERATOR_QUERIES */
00448 
00449 _STLP_MOVE_TO_STD_NAMESPACE
00450 
00451 _STLP_END_NAMESPACE
00452 
00453 #endif /* INTERNAL_H */
00454 
00455 // Local Variables:
00456 // mode:C++
00457 // End:

Generated on Sun May 27 2012 04:29:11 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.