libstdc++
|
00001 // Debugging iterator implementation (out of line) -*- C++ -*- 00002 00003 // Copyright (C) 2011-2019 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file debug/safe_local_iterator.tcc 00026 * This file is a GNU debug extension to the Standard C++ Library. 00027 */ 00028 00029 #ifndef _GLIBCXX_DEBUG_SAFE_LOCAL_ITERATOR_TCC 00030 #define _GLIBCXX_DEBUG_SAFE_LOCAL_ITERATOR_TCC 1 00031 00032 namespace __gnu_debug 00033 { 00034 template<typename _Iterator, typename _Sequence> 00035 typename _Distance_traits<_Iterator>::__type 00036 _Safe_local_iterator<_Iterator, _Sequence>:: 00037 _M_get_distance_to(const _Safe_local_iterator& __rhs) const 00038 { 00039 if (base() == __rhs.base()) 00040 return { 0, __dp_exact }; 00041 00042 if (_M_is_begin()) 00043 { 00044 if (__rhs._M_is_end()) 00045 return 00046 { 00047 _M_get_sequence()->bucket_size(bucket()), 00048 __dp_exact 00049 }; 00050 00051 return { 1, __dp_sign }; 00052 } 00053 00054 if (_M_is_end()) 00055 { 00056 if (__rhs._M_is_begin()) 00057 return 00058 { 00059 -_M_get_sequence()->bucket_size(bucket()), 00060 __dp_exact 00061 }; 00062 00063 return { -1, __dp_sign }; 00064 } 00065 00066 if (__rhs._M_is_begin()) 00067 return { -1, __dp_sign }; 00068 00069 if (__rhs._M_is_end()) 00070 return { 1, __dp_sign }; 00071 00072 return { 1, __dp_equality }; 00073 } 00074 00075 template<typename _Iterator, typename _Sequence> 00076 bool 00077 _Safe_local_iterator<_Iterator, _Sequence>:: 00078 _M_valid_range(const _Safe_local_iterator& __rhs, 00079 std::pair<difference_type, _Distance_precision>& __dist) const 00080 { 00081 if (!_M_can_compare(__rhs)) 00082 return false; 00083 00084 if (bucket() != __rhs.bucket()) 00085 return false; 00086 00087 /* Determine if we can order the iterators without the help of 00088 the container */ 00089 __dist = _M_get_distance_to(__rhs); 00090 switch (__dist.second) 00091 { 00092 case __dp_equality: 00093 if (__dist.first == 0) 00094 return true; 00095 break; 00096 00097 case __dp_sign: 00098 case __dp_exact: 00099 return __dist.first >= 0; 00100 } 00101 00102 // Assume that this is a valid range; we can't check anything else 00103 return true; 00104 } 00105 } // namespace __gnu_debug 00106 00107 #endif