Dead
[official-gcc.git] / gomp-20050608-branch / libstdc++-v3 / include / debug / safe_iterator.tcc
blobc5d49e0f2997a8247bf3f900346f820a464ae377
1 // Debugging iterator implementation (out of line) -*- C++ -*-
3 // Copyright (C) 2003, 2004, 2005
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library.  This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING.  If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction.  Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License.  This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
31 /** @file safe_iterator.tcc
32  *  This is an internal header file, included by other library headers.
33  *  You should not attempt to use it directly.
34  */
36 #ifndef _GLIBCXX_DEBUG_SAFE_ITERATOR_TCC
37 #define _GLIBCXX_DEBUG_SAFE_ITERATOR_TCC 1
39 namespace std
41 namespace __gnu_debug
43   template<typename _Iterator, typename _Sequence>
44     bool
45     _Safe_iterator<_Iterator, _Sequence>::
46     _M_can_advance(const difference_type& __n) const
47     {
48       typedef typename _Sequence::const_iterator const_iterator;
50       if (this->_M_singular())
51         return false;
52       if (__n == 0)
53         return true;
54       if (__n < 0)
55         {
56           const_iterator __begin =
57             static_cast<const _Sequence*>(_M_sequence)->begin();
58           pair<difference_type, _Distance_precision> __dist =
59             this->_M_get_distance(__begin, *this);
60           bool __ok =  (__dist.second == __dp_exact && __dist.first >= -__n
61                         || __dist.second != __dp_exact && __dist.first > 0);
62           return __ok;
63         }
64       else
65         {
66           const_iterator __end =
67             static_cast<const _Sequence*>(_M_sequence)->end();
68           pair<difference_type, _Distance_precision> __dist =
69             this->_M_get_distance(*this, __end);
70           bool __ok = (__dist.second == __dp_exact && __dist.first >= __n
71                        || __dist.second != __dp_exact && __dist.first > 0);
72           return __ok;
73         }
74     }
76   template<typename _Iterator, typename _Sequence>
77     template<typename _Other>
78       bool
79       _Safe_iterator<_Iterator, _Sequence>::
80       _M_valid_range(const _Safe_iterator<_Other, _Sequence>& __rhs) const
81       {
82         if (!_M_can_compare(__rhs))
83           return false;
85         /* Determine if we can order the iterators without the help of
86            the container */
87         pair<difference_type, _Distance_precision> __dist =
88           this->_M_get_distance(*this, __rhs);
89         switch (__dist.second) {
90         case __dp_equality:
91           if (__dist.first == 0)
92             return true;
93           break;
95         case __dp_sign:
96         case __dp_exact:
97           return __dist.first >= 0;
98         }
100         /* We can only test for equality, but check if one of the
101            iterators is at an extreme. */
102         if (_M_is_begin() || __rhs._M_is_end())
103           return true;
104         else if (_M_is_end() || __rhs._M_is_begin())
105           return false;
107         // Assume that this is a valid range; we can't check anything else
108         return true;
109       }
111   template<typename _Iterator, typename _Sequence>
112     void
113     _Safe_iterator<_Iterator, _Sequence>::
114     _M_invalidate()
115     {
116       typedef typename _Sequence::iterator iterator;
117       typedef typename _Sequence::const_iterator const_iterator;
119       if (!this->_M_singular())
120         {
121           for (_Safe_iterator_base* iter = _M_sequence->_M_iterators; iter; )
122             {
123               iterator* __victim = static_cast<iterator*>(iter);
124               iter = iter->_M_next;
125               if (this->base() == __victim->base())
126                 __victim->_M_version = 0;
127             }
128           for (_Safe_iterator_base* iter2 = _M_sequence->_M_const_iterators;
129                iter2; /* increment in loop */)
130             {
131               const_iterator* __victim = static_cast<const_iterator*>(iter2);
132               iter2 = iter2->_M_next;
133               if (this->base() == __victim->base())
134                 __victim->_M_version = 0;
135             }
136           _M_version = 0;
137         }
138     }
139 } // namespace __gnu_debug
140 } // namespace std
142 #endif