00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _GLIBCXX_DEBUG_SAFE_ITERATOR_TCC
00036 #define _GLIBCXX_DEBUG_SAFE_ITERATOR_TCC 1
00037
00038 namespace __gnu_debug
00039 {
00040 template<typename _Iterator, typename _Sequence>
00041 bool
00042 _Safe_iterator<_Iterator, _Sequence>::
00043 _M_can_advance(const difference_type& __n) const
00044 {
00045 typedef typename _Sequence::const_iterator const_iterator;
00046
00047 if (this->_M_singular())
00048 return false;
00049 if (__n == 0)
00050 return true;
00051 if (__n < 0)
00052 {
00053 const_iterator __begin =
00054 static_cast<const _Sequence*>(_M_sequence)->begin();
00055 std::pair<difference_type, _Distance_precision> __dist =
00056 this->_M_get_distance(__begin, *this);
00057 bool __ok = ((__dist.second == __dp_exact && __dist.first >= -__n)
00058 || (__dist.second != __dp_exact && __dist.first > 0));
00059 return __ok;
00060 }
00061 else
00062 {
00063 const_iterator __end =
00064 static_cast<const _Sequence*>(_M_sequence)->end();
00065 std::pair<difference_type, _Distance_precision> __dist =
00066 this->_M_get_distance(*this, __end);
00067 bool __ok = ((__dist.second == __dp_exact && __dist.first >= __n)
00068 || (__dist.second != __dp_exact && __dist.first > 0));
00069 return __ok;
00070 }
00071 }
00072
00073 template<typename _Iterator, typename _Sequence>
00074 template<typename _Other>
00075 bool
00076 _Safe_iterator<_Iterator, _Sequence>::
00077 _M_valid_range(const _Safe_iterator<_Other, _Sequence>& __rhs) const
00078 {
00079 if (!_M_can_compare(__rhs))
00080 return false;
00081
00082
00083
00084 std::pair<difference_type, _Distance_precision> __dist =
00085 this->_M_get_distance(*this, __rhs);
00086 switch (__dist.second) {
00087 case __dp_equality:
00088 if (__dist.first == 0)
00089 return true;
00090 break;
00091
00092 case __dp_sign:
00093 case __dp_exact:
00094 return __dist.first >= 0;
00095 }
00096
00097
00098
00099 if (_M_is_begin() || __rhs._M_is_end())
00100 return true;
00101 else if (_M_is_end() || __rhs._M_is_begin())
00102 return false;
00103
00104
00105 return true;
00106 }
00107
00108 template<typename _Iterator, typename _Sequence>
00109 void
00110 _Safe_iterator<_Iterator, _Sequence>::
00111 _M_invalidate()
00112 {
00113 __gnu_cxx::__scoped_lock sentry(this->_M_get_mutex());
00114 _M_invalidate_single();
00115 }
00116
00117 template<typename _Iterator, typename _Sequence>
00118 void
00119 _Safe_iterator<_Iterator, _Sequence>::
00120 _M_invalidate_single()
00121 {
00122 typedef typename _Sequence::iterator iterator;
00123 typedef typename _Sequence::const_iterator const_iterator;
00124
00125 if (!this->_M_singular())
00126 {
00127 for (_Safe_iterator_base* __iter = _M_sequence->_M_iterators;
00128 __iter; __iter = __iter->_M_next)
00129 {
00130 iterator* __victim = static_cast<iterator*>(__iter);
00131 if (this->base() == __victim->base())
00132 __victim->_M_version = 0;
00133 }
00134
00135 for (_Safe_iterator_base* __iter2 = _M_sequence->_M_const_iterators;
00136 __iter2; __iter2 = __iter2->_M_next)
00137 {
00138 const_iterator* __victim = static_cast<const_iterator*>(__iter2);
00139 if (__victim->base() == this->base())
00140 __victim->_M_version = 0;
00141 }
00142 _M_version = 0;
00143 }
00144 }
00145 }
00146
00147 #endif
00148