1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/debug/_iterator.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,484 @@
1.4 +/*
1.5 + *
1.6 + * Copyright (c) 1997
1.7 + * Moscow Center for SPARC Technology
1.8 + *
1.9 + * Copyright (c) 1999
1.10 + * Boris Fomitchev
1.11 + *
1.12 + * This material is provided "as is", with absolutely no warranty expressed
1.13 + * or implied. Any use is at your own risk.
1.14 + *
1.15 + * Permission to use or copy this software for any purpose is hereby granted
1.16 + * without fee, provided the above notices are retained on all copies.
1.17 + * Permission to modify the code and to distribute modified code is granted,
1.18 + * provided the above notices are retained, and a notice that the code was
1.19 + * modified is included with the above copyright notice.
1.20 + *
1.21 + */
1.22 +
1.23 +#ifndef _STLP_DBG_ITERATOR_H
1.24 +#define _STLP_DBG_ITERATOR_H
1.25 +
1.26 +#ifndef _STLP_INTERNAL_PAIR_H
1.27 +# include <stl/_pair.h>
1.28 +#endif
1.29 +
1.30 +#ifndef _STLP_INTERNAL_ALLOC_H
1.31 +# include <stl/_alloc.h>
1.32 +#endif
1.33 +
1.34 +#define _STLP_DBG_ALLOCATOR_SELECT( _Tp ) _STLP_DEFAULT_ALLOCATOR_SELECT( _Tp )
1.35 +
1.36 +_STLP_BEGIN_NAMESPACE
1.37 +
1.38 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.39 +
1.40 +//============================================================
1.41 +
1.42 +template <class _Iterator>
1.43 +void _Decrement(_Iterator& __it, const bidirectional_iterator_tag &)
1.44 +{ --__it; }
1.45 +
1.46 +template <class _Iterator>
1.47 +void _Decrement(_Iterator& __it, const random_access_iterator_tag &)
1.48 +{ --__it; }
1.49 +
1.50 +template <class _Iterator>
1.51 +void _Decrement(_Iterator& __it, const forward_iterator_tag &)
1.52 +{ _STLP_ASSERT(0) }
1.53 +
1.54 +template <class _Iterator>
1.55 +void _Advance(_Iterator&, ptrdiff_t, const forward_iterator_tag &)
1.56 +{ _STLP_ASSERT(0) }
1.57 +
1.58 +template <class _Iterator>
1.59 +void _Advance(_Iterator& __it, ptrdiff_t, const bidirectional_iterator_tag &)
1.60 +{ _STLP_ASSERT(0) }
1.61 +
1.62 +template <class _Iterator>
1.63 +void _Advance(_Iterator& __it, ptrdiff_t __n, const random_access_iterator_tag &)
1.64 +{ __it += __n; }
1.65 +
1.66 +template <class _Iterator>
1.67 +ptrdiff_t _DBG_distance(const _Iterator& __x, const _Iterator& __y, const random_access_iterator_tag &)
1.68 +{ return __x - __y; }
1.69 +
1.70 +template <class _Iterator>
1.71 +ptrdiff_t _DBG_distance(const _Iterator&, const _Iterator&, const forward_iterator_tag &) {
1.72 + _STLP_ASSERT(0)
1.73 + return 0;
1.74 +}
1.75 +
1.76 +template <class _Iterator>
1.77 +ptrdiff_t _DBG_distance(const _Iterator&, const _Iterator&, const bidirectional_iterator_tag &) {
1.78 + _STLP_ASSERT(0)
1.79 + return 0;
1.80 +}
1.81 +
1.82 +template <class _Iterator>
1.83 +bool _CompareIt(const _Iterator&, const _Iterator&, const forward_iterator_tag &) {
1.84 + _STLP_ASSERT(0)
1.85 + return false;
1.86 +}
1.87 +
1.88 +template <class _Iterator>
1.89 +bool _CompareIt(const _Iterator&, const _Iterator&, const bidirectional_iterator_tag &) {
1.90 + _STLP_ASSERT(0)
1.91 + return false;
1.92 +}
1.93 +
1.94 +template <class _Iterator>
1.95 +bool _CompareIt(const _Iterator& __x, const _Iterator& __y, const random_access_iterator_tag &)
1.96 +{ return __x < __y; }
1.97 +
1.98 +template <class _Iterator>
1.99 +bool _Dereferenceable(const _Iterator& __it)
1.100 +{ return (__it._Get_container_ptr() != 0) && !(__it._M_iterator == (__it._Get_container_ptr())->end()); }
1.101 +
1.102 +template <class _Iterator>
1.103 +bool _Incrementable(const _Iterator& __it, ptrdiff_t __n, const forward_iterator_tag &)
1.104 +{ return (__n == 1) && _Dereferenceable(__it); }
1.105 +
1.106 +template <class _Iterator>
1.107 +bool _Incrementable(const _Iterator& __it, ptrdiff_t __n, const bidirectional_iterator_tag &) {
1.108 + typedef typename _Iterator::_Container_type __container_type;
1.109 + __container_type* __c = __it._Get_container_ptr();
1.110 + return (__c != 0) && ((__n == 1 && __it._M_iterator != __c->end() ) ||
1.111 + (__n == -1 && __it._M_iterator != __c->begin()));
1.112 +}
1.113 +
1.114 +template <class _Iterator>
1.115 +bool _Incrementable(const _Iterator& __it, ptrdiff_t __n, const random_access_iterator_tag &) {
1.116 + typedef typename _Iterator::_Container_type __container_type;
1.117 + __container_type* __c = __it._Get_container_ptr();
1.118 + if (__c == 0) return false;
1.119 + ptrdiff_t __new_pos = (__it._M_iterator - __c->begin()) + __n;
1.120 + return (__new_pos >= 0) && (__STATIC_CAST(typename __container_type::size_type, __new_pos) <= __c->size());
1.121 +}
1.122 +
1.123 +
1.124 +template <class _Container>
1.125 +struct _DBG_iter_base : public __owned_link {
1.126 +public:
1.127 + typedef typename _Container::value_type value_type;
1.128 + typedef typename _Container::reference reference;
1.129 + typedef typename _Container::pointer pointer;
1.130 + typedef ptrdiff_t difference_type;
1.131 + //private:
1.132 + typedef typename _Container::iterator _Nonconst_iterator;
1.133 + typedef typename _Container::const_iterator _Const_iterator;
1.134 + typedef _Container _Container_type;
1.135 +
1.136 +#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
1.137 + typedef typename iterator_traits<_Const_iterator>::iterator_category _Iterator_category;
1.138 +#else
1.139 + typedef typename _Container::_Iterator_category _Iterator_category;
1.140 +#endif
1.141 + typedef _Iterator_category iterator_category;
1.142 +
1.143 + _DBG_iter_base() : __owned_link(0) {}
1.144 + _DBG_iter_base(const __owned_list* __c, const _Const_iterator& __it) :
1.145 +#if defined(__HP_aCC) && (__HP_aCC < 60000)
1.146 + __owned_link(__c), _M_iterator(*__REINTERPRET_CAST(const _Nonconst_iterator *, &__it)) {}
1.147 +#else
1.148 + __owned_link(__c), _M_iterator(*(const _Nonconst_iterator*)&__it) {}
1.149 +#endif
1.150 + _Container* _Get_container_ptr() const {
1.151 + return (_Container*)__stl_debugger::_Get_container_ptr(this);
1.152 + }
1.153 +
1.154 + void __increment();
1.155 + void __decrement();
1.156 + void __advance(ptrdiff_t __n);
1.157 +
1.158 +// protected:
1.159 + _Nonconst_iterator _M_iterator;
1.160 +};
1.161 +
1.162 +template <class _Container>
1.163 +inline void _DBG_iter_base<_Container>::__increment() {
1.164 + _STLP_DEBUG_CHECK(_Incrementable(*this, 1, _Iterator_category()))
1.165 + ++_M_iterator;
1.166 +}
1.167 +
1.168 +template <class _Container>
1.169 +inline void _DBG_iter_base<_Container>::__decrement() {
1.170 + _STLP_DEBUG_CHECK(_Incrementable(*this, -1, _Iterator_category()))
1.171 + _Decrement(_M_iterator, _Iterator_category());
1.172 +}
1.173 +
1.174 +template <class _Container>
1.175 +inline void _DBG_iter_base<_Container>::__advance(ptrdiff_t __n) {
1.176 + _STLP_DEBUG_CHECK(_Incrementable(*this, __n, _Iterator_category()))
1.177 + _Advance(_M_iterator, __n, _Iterator_category());
1.178 +}
1.179 +
1.180 +template <class _Container>
1.181 +ptrdiff_t operator-(const _DBG_iter_base<_Container>& __x,
1.182 + const _DBG_iter_base<_Container>& __y ) {
1.183 + typedef typename _DBG_iter_base<_Container>::_Iterator_category _Iterator_category;
1.184 + _STLP_DEBUG_CHECK(__check_same_owner(__x, __y))
1.185 + return _DBG_distance(__x._M_iterator,__y._M_iterator, _Iterator_category());
1.186 +}
1.187 +
1.188 +template <class _Container, class _Traits>
1.189 +struct _DBG_iter_mid : public _DBG_iter_base<_Container> {
1.190 + typedef _DBG_iter_mid<_Container, typename _Traits::_NonConstTraits> _Nonconst_self;
1.191 + typedef typename _Container::iterator _Nonconst_iterator;
1.192 + typedef typename _Container::const_iterator _Const_iterator;
1.193 +
1.194 + _DBG_iter_mid() {}
1.195 +
1.196 + explicit _DBG_iter_mid(const _Nonconst_self& __it) :
1.197 + _DBG_iter_base<_Container>(__it) {}
1.198 +
1.199 + _DBG_iter_mid(const __owned_list* __c, const _Const_iterator& __it) :
1.200 + _DBG_iter_base<_Container>(__c, __it) {}
1.201 +};
1.202 +
1.203 +template <class _Container, class _Traits>
1.204 +struct _DBG_iter : public _DBG_iter_mid<_Container, _Traits> {
1.205 + typedef _DBG_iter_base<_Container> _Base;
1.206 +public:
1.207 + typedef typename _Base::value_type value_type;
1.208 + typedef typename _Base::difference_type difference_type;
1.209 + typedef typename _Traits::reference reference;
1.210 + typedef typename _Traits::pointer pointer;
1.211 +
1.212 + typedef typename _Base::_Nonconst_iterator _Nonconst_iterator;
1.213 + typedef typename _Base::_Const_iterator _Const_iterator;
1.214 +
1.215 +private:
1.216 + typedef _DBG_iter<_Container, _Traits> _Self;
1.217 + typedef _DBG_iter_mid<_Container, typename _Traits::_NonConstTraits> _Nonconst_mid;
1.218 +
1.219 +public:
1.220 +
1.221 +#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
1.222 + typedef typename _Base::iterator_category iterator_category;
1.223 +#endif
1.224 + typedef typename _Base::_Iterator_category _Iterator_category;
1.225 +
1.226 +public:
1.227 + _DBG_iter() {}
1.228 + // boris : real type of iter would be nice
1.229 + _DBG_iter(const __owned_list* __c, const _Const_iterator& __it) :
1.230 + _DBG_iter_mid<_Container, _Traits>(__c, __it) {}
1.231 +
1.232 + // This allows conversions from iterator to const_iterator without being
1.233 + // redundant with the copy constructor below.
1.234 + _DBG_iter(const _Nonconst_mid& __rhs) :
1.235 + _DBG_iter_mid<_Container, _Traits>(__rhs) {}
1.236 +
1.237 + _DBG_iter(const _Self& __rhs) :
1.238 + _DBG_iter_mid<_Container, _Traits>(__rhs) {}
1.239 +
1.240 + // This allows conversions from iterator to const_iterator without being
1.241 + // redundant with the copy assignment operator below.
1.242 + _Self& operator=(const _Nonconst_mid& __rhs) {
1.243 + (_Base&)*this = __rhs;
1.244 + return *this;
1.245 + }
1.246 +
1.247 + _Self& operator=(const _Self& __rhs) {
1.248 + (_Base&)*this = __rhs;
1.249 + return *this;
1.250 + }
1.251 +
1.252 + reference operator*() const;
1.253 +
1.254 + _STLP_DEFINE_ARROW_OPERATOR
1.255 +
1.256 + _Self& operator++() {
1.257 + this->__increment();
1.258 + return *this;
1.259 + }
1.260 + _Self operator++(int) {
1.261 + _Self __tmp = *this;
1.262 + this->__increment();
1.263 + return __tmp;
1.264 + }
1.265 + _Self& operator--() {
1.266 + this->__decrement();
1.267 + return *this;
1.268 + }
1.269 + _Self operator--(int) {
1.270 + _Self __tmp = *this;
1.271 + this->__decrement();
1.272 + return __tmp;
1.273 + }
1.274 +
1.275 + _Self& operator+=(difference_type __n) {
1.276 + this->__advance(__n);
1.277 + return *this;
1.278 + }
1.279 +
1.280 + _Self& operator-=(difference_type __n) {
1.281 + this->__advance(-__n);
1.282 + return *this;
1.283 + }
1.284 + _Self operator+(difference_type __n) const {
1.285 + _Self __tmp(*this);
1.286 + __tmp.__advance(__n);
1.287 + return __tmp;
1.288 + }
1.289 + _Self operator-(difference_type __n) const {
1.290 + _Self __tmp(*this);
1.291 + __tmp.__advance(-__n);
1.292 + return __tmp;
1.293 + }
1.294 + reference operator[](difference_type __n) const { return *(*this + __n); }
1.295 +};
1.296 +
1.297 +template <class _Container, class _Traits>
1.298 +inline
1.299 +#if defined (_STLP_NESTED_TYPE_PARAM_BUG)
1.300 +_STLP_TYPENAME_ON_RETURN_TYPE _Traits::reference
1.301 +#else
1.302 +_STLP_TYPENAME_ON_RETURN_TYPE _DBG_iter<_Container, _Traits>::reference
1.303 +#endif
1.304 +_DBG_iter<_Container, _Traits>::operator*() const {
1.305 + _STLP_DEBUG_CHECK(_Dereferenceable(*this))
1.306 + _STLP_DEBUG_CHECK(_Traits::_Check(*this))
1.307 + return *this->_M_iterator;
1.308 +}
1.309 +
1.310 +template <class _Container>
1.311 +inline bool
1.312 +operator==(const _DBG_iter_base<_Container>& __x, const _DBG_iter_base<_Container>& __y) {
1.313 + _STLP_DEBUG_CHECK(__check_same_or_null_owner(__x, __y))
1.314 + return __x._M_iterator == __y._M_iterator;
1.315 +}
1.316 +
1.317 +template <class _Container>
1.318 +inline bool
1.319 +operator<(const _DBG_iter_base<_Container>& __x, const _DBG_iter_base<_Container>& __y) {
1.320 + _STLP_DEBUG_CHECK(__check_same_or_null_owner(__x, __y))
1.321 + typedef typename _DBG_iter_base<_Container>::_Iterator_category _Category;
1.322 + return _CompareIt(__x._M_iterator , __y._M_iterator, _Category());
1.323 +}
1.324 +
1.325 +template <class _Container>
1.326 +inline bool
1.327 +operator>(const _DBG_iter_base<_Container>& __x,
1.328 + const _DBG_iter_base<_Container>& __y) {
1.329 + typedef typename _DBG_iter_base<_Container>::_Iterator_category _Category;
1.330 + return _CompareIt(__y._M_iterator , __x._M_iterator, _Category());
1.331 +}
1.332 +
1.333 +template <class _Container>
1.334 +inline bool
1.335 +operator>=(const _DBG_iter_base<_Container>& __x, const _DBG_iter_base<_Container>& __y) {
1.336 + _STLP_DEBUG_CHECK(__check_same_or_null_owner(__x, __y))
1.337 + typedef typename _DBG_iter_base<_Container>::_Iterator_category _Category;
1.338 + return !_CompareIt(__x._M_iterator , __y._M_iterator, _Category());
1.339 +}
1.340 +
1.341 +template <class _Container>
1.342 +inline bool
1.343 +operator<=(const _DBG_iter_base<_Container>& __x,
1.344 + const _DBG_iter_base<_Container>& __y) {
1.345 + typedef typename _DBG_iter_base<_Container>::_Iterator_category _Category;
1.346 + return !_CompareIt(__y._M_iterator , __x._M_iterator, _Category());
1.347 +}
1.348 +
1.349 +template <class _Container>
1.350 +inline bool
1.351 +operator!=(const _DBG_iter_base<_Container>& __x,
1.352 + const _DBG_iter_base<_Container>& __y) {
1.353 + _STLP_DEBUG_CHECK(__check_same_or_null_owner(__x, __y))
1.354 + return __x._M_iterator != __y._M_iterator;
1.355 +}
1.356 +
1.357 +//------------------------------------------
1.358 +
1.359 +template <class _Container, class _Traits>
1.360 +inline _DBG_iter<_Container, _Traits>
1.361 +operator+(ptrdiff_t __n, const _DBG_iter<_Container, _Traits>& __it) {
1.362 + _DBG_iter<_Container, _Traits> __tmp(__it);
1.363 + return __tmp += __n;
1.364 +}
1.365 +
1.366 +
1.367 +template <class _Iterator>
1.368 +inline _Iterator _Non_Dbg_iter(_Iterator __it)
1.369 +{ return __it; }
1.370 +
1.371 +#if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
1.372 +template <class _Container, class _Traits>
1.373 +inline typename _DBG_iter<_Container, _Traits>::_Nonconst_iterator
1.374 +_Non_Dbg_iter(_DBG_iter<_Container, _Traits> __it)
1.375 +{ return __it._M_iterator; }
1.376 +#endif
1.377 +
1.378 +/*
1.379 + * Helper classes to check iterator range or pointer validity
1.380 + * at construction time.
1.381 + */
1.382 +template <class _Container>
1.383 +class __construct_checker {
1.384 + typedef typename _Container::value_type value_type;
1.385 +protected:
1.386 + __construct_checker() {}
1.387 +
1.388 + __construct_checker(const value_type* __p) {
1.389 + _STLP_VERBOSE_ASSERT((__p != 0), _StlMsg_INVALID_ARGUMENT)
1.390 + }
1.391 +
1.392 +#if defined (_STLP_MEMBER_TEMPLATES)
1.393 + template <class _InputIter>
1.394 + __construct_checker(const _InputIter& __f, const _InputIter& __l) {
1.395 + typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
1.396 + _M_check_dispatch(__f, __l, _Integral());
1.397 + }
1.398 +
1.399 + template <class _Integer>
1.400 + void _M_check_dispatch(_Integer , _Integer, const __true_type& /*IsIntegral*/) {}
1.401 +
1.402 + template <class _InputIter>
1.403 + void _M_check_dispatch(const _InputIter& __f, const _InputIter& __l, const __false_type& /*IsIntegral*/) {
1.404 + _STLP_DEBUG_CHECK(__check_range(__f,__l))
1.405 + }
1.406 +#endif
1.407 +
1.408 +#if !defined (_STLP_MEMBER_TEMPLATES) || !defined (_STLP_NO_METHOD_SPECIALIZATION)
1.409 + __construct_checker(const value_type* __f, const value_type* __l) {
1.410 + _STLP_DEBUG_CHECK(__check_ptr_range(__f,__l))
1.411 + }
1.412 +
1.413 + typedef _DBG_iter_base<_Container> _IteType;
1.414 + __construct_checker(const _IteType& __f, const _IteType& __l) {
1.415 + _STLP_DEBUG_CHECK(__check_range(__f,__l))
1.416 + }
1.417 +#endif
1.418 +};
1.419 +
1.420 +#if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
1.421 +//Construct checker used by all exported containers.
1.422 +template <class _Container>
1.423 +class __msvc6_construct_checker {
1.424 + typedef typename _Container::value_type value_type;
1.425 +protected:
1.426 + __msvc6_construct_checker() {}
1.427 +
1.428 + __msvc6_construct_checker(const value_type* __p) {
1.429 + _STLP_VERBOSE_ASSERT((__p != 0), _StlMsg_INVALID_ARGUMENT)
1.430 + }
1.431 +
1.432 + __msvc6_construct_checker(const value_type* __f, const value_type* __l) {
1.433 + _STLP_DEBUG_CHECK(__check_ptr_range(__f,__l))
1.434 + }
1.435 +
1.436 + typedef _DBG_iter_base<_Container> _IteType;
1.437 + __msvc6_construct_checker(const _IteType& __f, const _IteType& __l) {
1.438 + _STLP_DEBUG_CHECK(__check_range(__f,__l))
1.439 + }
1.440 +};
1.441 +# define _STLP_CONSTRUCT_CHECKER __msvc6_construct_checker
1.442 +#else
1.443 +# define _STLP_CONSTRUCT_CHECKER __construct_checker
1.444 +#endif
1.445 +
1.446 +#if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
1.447 +# if defined (_STLP_NESTED_TYPE_PARAM_BUG) ||\
1.448 + (defined (__SUNPRO_CC) && __SUNPRO_CC < 0x600) ||\
1.449 + (defined (_STLP_MSVC) && (_STLP_MSVC < 1100))
1.450 +# define _STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS 1
1.451 +# endif
1.452 +
1.453 +_STLP_MOVE_TO_STD_NAMESPACE
1.454 +
1.455 +template <class _Container>
1.456 +inline ptrdiff_t*
1.457 +distance_type(const _STLP_PRIV _DBG_iter_base<_Container>&) { return (ptrdiff_t*) 0; }
1.458 +
1.459 +# if !defined (_STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS)
1.460 +template <class _Container>
1.461 +inline _STLP_TYPENAME_ON_RETURN_TYPE _STLP_PRIV _DBG_iter_base<_Container>::value_type*
1.462 +value_type(const _STLP_PRIV _DBG_iter_base<_Container>&) {
1.463 + typedef typename _STLP_PRIV _DBG_iter_base<_Container>::value_type _Val;
1.464 + return (_Val*)0;
1.465 +}
1.466 +
1.467 +template <class _Container>
1.468 +inline _STLP_TYPENAME_ON_RETURN_TYPE _STLP_PRIV _DBG_iter_base<_Container>::_Iterator_category
1.469 +iterator_category(const _STLP_PRIV _DBG_iter_base<_Container>&) {
1.470 + typedef typename _STLP_PRIV _DBG_iter_base<_Container>::_Iterator_category _Category;
1.471 + return _Category();
1.472 +}
1.473 +# endif
1.474 +
1.475 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.476 +
1.477 +#endif /* _STLP_USE_OLD_HP_ITERATOR_QUERIES */
1.478 +
1.479 +_STLP_MOVE_TO_STD_NAMESPACE
1.480 +
1.481 +_STLP_END_NAMESPACE
1.482 +
1.483 +#endif /* INTERNAL_H */
1.484 +
1.485 +// Local Variables:
1.486 +// mode:C++
1.487 +// End: