libstdc++
|
00001 // Safe container implementation -*- C++ -*- 00002 00003 // Copyright (C) 2011 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_unordered_container.tcc 00026 * This file is a GNU debug extension to the Standard C++ Library. 00027 */ 00028 00029 #ifndef _GLIBCXX_DEBUG_SAFE_UNORDERED_CONTAINER_TCC 00030 #define _GLIBCXX_DEBUG_SAFE_UNORDERED_CONTAINER_TCC 1 00031 00032 namespace __gnu_debug 00033 { 00034 template<typename _Container> 00035 template<typename _Predicate> 00036 void 00037 _Safe_unordered_container<_Container>:: 00038 _M_invalidate_if(_Predicate __pred) 00039 { 00040 typedef typename _Container::iterator iterator; 00041 typedef typename _Container::const_iterator const_iterator; 00042 00043 __gnu_cxx::__scoped_lock sentry(this->_M_get_mutex()); 00044 for (_Safe_iterator_base* __iter = _M_iterators; __iter;) 00045 { 00046 iterator* __victim = static_cast<iterator*>(__iter); 00047 __iter = __iter->_M_next; 00048 if (!__victim->_M_singular() && __pred(__victim->base())) 00049 { 00050 __victim->_M_invalidate(); 00051 } 00052 } 00053 00054 for (_Safe_iterator_base* __iter2 = _M_const_iterators; __iter2;) 00055 { 00056 const_iterator* __victim = static_cast<const_iterator*>(__iter2); 00057 __iter2 = __iter2->_M_next; 00058 if (!__victim->_M_singular() && __pred(__victim->base())) 00059 { 00060 __victim->_M_invalidate(); 00061 } 00062 } 00063 } 00064 00065 00066 template<typename _Container> 00067 template<typename _Predicate> 00068 void 00069 _Safe_unordered_container<_Container>:: 00070 _M_invalidate_local_if(_Predicate __pred) 00071 { 00072 typedef typename _Container::local_iterator local_iterator; 00073 typedef typename _Container::const_local_iterator const_local_iterator; 00074 00075 __gnu_cxx::__scoped_lock sentry(this->_M_get_mutex()); 00076 for (_Safe_iterator_base* __iter = _M_local_iterators; __iter;) 00077 { 00078 local_iterator* __victim = static_cast<local_iterator*>(__iter); 00079 __iter = __iter->_M_next; 00080 if (!__victim->_M_singular() && __pred(__victim->base())) 00081 { 00082 __victim->_M_invalidate(); 00083 } 00084 } 00085 00086 for (_Safe_iterator_base* __iter2 = _M_const_local_iterators; __iter2;) 00087 { 00088 const_local_iterator* __victim = 00089 static_cast<const_local_iterator*>(__iter2); 00090 __iter2 = __iter2->_M_next; 00091 if (!__victim->_M_singular() && __pred(__victim->base())) 00092 { 00093 __victim->_M_invalidate(); 00094 } 00095 } 00096 } 00097 00098 } // namespace __gnu_debug 00099 00100 #endif