debug/unordered_map

Go to the documentation of this file.
00001 // Debugging unordered_map/unordered_multimap implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2003, 2004, 2005, 2006, 2007
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 2, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // You should have received a copy of the GNU General Public License along
00018 // with this library; see the file COPYING.  If not, write to the Free
00019 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00020 // USA.
00021 
00022 // As a special exception, you may use this file as part of a free software
00023 // library without restriction.  Specifically, if other files instantiate
00024 // templates or use macros or inline functions from this file, or you compile
00025 // this file and link it with other files to produce an executable, this
00026 // file does not by itself cause the resulting executable to be covered by
00027 // the GNU General Public License.  This exception does not however
00028 // invalidate any other reasons why the executable file might be covered by
00029 // the GNU General Public License.
00030 
00031 /** @file debug/unordered_map
00032  *  This file is a GNU debug extension to the Standard C++ Library.
00033  */
00034 
00035 #ifndef _GLIBCXX_DEBUG_UNORDERED_MAP
00036 #define _GLIBCXX_DEBUG_UNORDERED_MAP 1
00037 
00038 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00039 # include <unordered_map>
00040 #else
00041 # include <c++0x_warning.h>
00042 #endif
00043 #include <debug/safe_association.h>
00044 #include <debug/safe_iterator.h>
00045 
00046 #define _GLIBCXX_BASE unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>
00047 #define _GLIBCXX_STD_BASE _GLIBCXX_STD_D::_GLIBCXX_BASE
00048 
00049 namespace std
00050 {
00051 namespace __debug
00052 {
00053   template<typename _Key, typename _Tp,
00054        typename _Hash  = std::hash<_Key>,
00055        typename _Pred = std::equal_to<_Key>,
00056        typename _Alloc =  std::allocator<_Key> >
00057     class unordered_map
00058     : public __gnu_debug::_Safe_association<_GLIBCXX_STD_BASE>,
00059       public __gnu_debug::_Safe_sequence<_GLIBCXX_BASE>
00060     {
00061       typedef typename _GLIBCXX_STD_BASE _Base;
00062       typedef __gnu_debug::_Safe_association<_Base> _Safe_assoc;
00063       typedef __gnu_debug::_Safe_sequence<unordered_map> _Safe_base;
00064 
00065     public:
00066       typedef typename _Safe_assoc::size_type       size_type;
00067       typedef typename _Safe_assoc::hasher          hasher;
00068       typedef typename _Safe_assoc::key_equal       key_equal;
00069       typedef typename _Safe_assoc::allocator_type allocator_type;
00070 
00071       explicit
00072       unordered_map(size_type __n = 10,
00073             const hasher& __hf = hasher(),
00074             const key_equal& __eql = key_equal(),
00075             const allocator_type& __a = allocator_type())
00076       : _Safe_assoc(__n, __hf, __eql, __a)
00077       { }
00078 
00079       template<typename _InputIterator>
00080         unordered_map(_InputIterator __f, _InputIterator __l, 
00081               size_type __n = 10,
00082               const hasher& __hf = hasher(), 
00083               const key_equal& __eql = key_equal(), 
00084               const allocator_type& __a = allocator_type())
00085     : _Safe_assoc(__f, __l, __n, __hf, __eql, __a)
00086         { }
00087 
00088       unordered_map(const _Safe_assoc& __x) 
00089       : _Safe_assoc(__x), _Safe_base() { }
00090 
00091       unordered_map(unordered_map&& __x) 
00092       : _Safe_assoc(std::forward<_Safe_assoc>(__x)), _Safe_base() { }
00093 
00094       unordered_map&
00095       operator=(unordered_map&& __x)
00096       {
00097         // NB: DR 675.
00098     clear();
00099     swap(__x);
00100     return *this;
00101       }
00102 
00103       void
00104       swap(unordered_map&& __x)
00105       {
00106     _Safe_assoc::swap(__x);
00107     _Safe_base::_M_swap(__x);
00108       }
00109 
00110       void
00111       clear()
00112       {
00113     _Base::clear();
00114     this->_M_invalidate_all();
00115       }
00116 
00117     private:
00118       void
00119       _M_invalidate_all()
00120       {
00121     typedef typename _Base::const_iterator _Base_const_iterator;
00122     typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
00123     this->_M_invalidate_if(_Not_equal(this->_M_base().end()));
00124       }
00125     };
00126 
00127   template<typename _Key, typename _Tp, typename _Hash,
00128        typename _Pred, typename _Alloc>
00129     inline void
00130     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
00131      unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
00132     { __x.swap(__y); }
00133 
00134   template<typename _Key, typename _Tp, typename _Hash,
00135        typename _Pred, typename _Alloc>
00136     inline void
00137     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
00138      unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
00139     { __x.swap(__y); }
00140 
00141   template<typename _Key, typename _Tp, typename _Hash,
00142        typename _Pred, typename _Alloc>
00143     inline void
00144     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
00145      unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
00146     { __x.swap(__y); }
00147 
00148 #undef _GLIBCXX_BASE
00149 #undef _GLIBCXX_STD_BASE
00150 #define _GLIBCXX_STD_BASE _GLIBCXX_STD_D::_GLIBCXX_BASE
00151 #define _GLIBCXX_BASE unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>
00152 
00153   template<typename _Key, typename _Tp,
00154        typename _Hash  = std::hash<_Key>,
00155        typename _Pred = std::equal_to<_Key>,
00156        typename _Alloc =  std::allocator<_Key> >
00157     class unordered_multimap
00158     : public __gnu_debug::_Safe_association<_GLIBCXX_STD_BASE>,
00159       public __gnu_debug::_Safe_sequence<_GLIBCXX_BASE>
00160     {
00161       typedef typename _GLIBCXX_STD_BASE _Base;
00162       typedef __gnu_debug::_Safe_association<_Base> _Safe_assoc;
00163       typedef __gnu_debug::_Safe_sequence<unordered_multimap> _Safe_base;
00164 
00165     public:
00166       typedef typename _Safe_assoc::size_type       size_type;
00167       typedef typename _Safe_assoc::hasher          hasher;
00168       typedef typename _Safe_assoc::key_equal       key_equal;
00169       typedef typename _Safe_assoc::allocator_type allocator_type;
00170 
00171       explicit
00172       unordered_multimap(size_type __n = 10,
00173             const hasher& __hf = hasher(),
00174             const key_equal& __eql = key_equal(),
00175             const allocator_type& __a = allocator_type())
00176       : _Safe_assoc(__n, __hf, __eql, __a)
00177       { }
00178 
00179       template<typename _InputIterator>
00180         unordered_multimap(_InputIterator __f, _InputIterator __l, 
00181               size_type __n = 10,
00182               const hasher& __hf = hasher(), 
00183               const key_equal& __eql = key_equal(), 
00184               const allocator_type& __a = allocator_type())
00185     : _Safe_assoc(__f, __l, __n, __hf, __eql, __a)
00186         { }
00187 
00188       unordered_multimap(const _Safe_assoc& __x) 
00189       : _Safe_assoc(__x), _Safe_base() { }
00190 
00191       unordered_multimap(unordered_multimap&& __x) 
00192       : _Safe_assoc(std::forward<_Safe_assoc>(__x)), _Safe_base() { }
00193 
00194       unordered_multimap&
00195       operator=(unordered_multimap&& __x)
00196       {
00197         // NB: DR 675.
00198     clear();
00199     swap(__x);
00200     return *this;
00201       }
00202 
00203       void
00204       swap(unordered_multimap&& __x)
00205       {
00206     _Safe_assoc::swap(__x);
00207     _Safe_base::_M_swap(__x);
00208       }
00209 
00210       void
00211       clear()
00212       {
00213     _Base::clear();
00214     this->_M_invalidate_all();
00215       }
00216 
00217     private:
00218       void
00219       _M_invalidate_all()
00220       {
00221     typedef typename _Base::const_iterator _Base_const_iterator;
00222     typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
00223     this->_M_invalidate_if(_Not_equal(this->_M_base().end()));
00224       }
00225     };
00226 
00227   template<typename _Key, typename _Tp, typename _Hash,
00228        typename _Pred, typename _Alloc>
00229     inline void
00230     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
00231      unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
00232     { __x.swap(__y); }
00233 
00234   template<typename _Key, typename _Tp, typename _Hash,
00235        typename _Pred, typename _Alloc>
00236     inline void
00237     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
00238      unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
00239     { __x.swap(__y); }
00240 
00241   template<typename _Key, typename _Tp, typename _Hash,
00242        typename _Pred, typename _Alloc>
00243     inline void
00244     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
00245      unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
00246     { __x.swap(__y); }
00247 
00248 } // namespace __debug
00249 } // namespace std
00250 
00251 #undef _GLIBCXX_BASE
00252 #undef _GLIBCXX_STD_BASE
00253 
00254 #endif

Generated on Wed Mar 26 00:43:21 2008 for libstdc++ by  doxygen 1.5.1