map_debug_base.hpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005 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 2, 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 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
00031 
00032 // Permission to use, copy, modify, sell, and distribute this software
00033 // is hereby granted without fee, provided that the above copyright
00034 // notice appears in all copies, and that both that copyright notice and
00035 // this permission notice appear in supporting documentation. None of
00036 // the above authors, nor IBM Haifa Research Laboratories, make any
00037 // representation about the suitability of this software for any
00038 // purpose. It is provided "as is" without express or implied warranty.
00039 
00045 #ifndef MAP_DEBUG_BASE_HPP
00046 #define MAP_DEBUG_BASE_HPP
00047 
00048 #ifdef PB_ASSOC_USE_MAP_DEBUG_BASE
00049 
00050 #include <assert.h>
00051 #include <utility>
00052 #include <set>
00053 #include <pb_assoc/testsuite/regression/res_mng/dbg_ex_allocator_base.hpp>
00054 
00055 namespace pb_assoc
00056 {
00057 
00058   namespace detail
00059   {
00060 
00061 #ifdef PB_ASSOC_MAP_DEBUG_BASE_DEBUG
00062 #define PB_ASSOC_DBG_ASSERT(X) assert(X)
00063 #define PB_ASSOC_DBG_VERIFY(X) assert(X)
00064 #define PB_ASSOC_DBG_ONLY(X) X
00065 #else // #ifdef PB_ASSOC_MAP_DEBUG_BASE_DEBUG
00066 #define PB_ASSOC_DBG_ASSERT(X)
00067 #define PB_ASSOC_DBG_VERIFY(X) {if((X)==0);}
00068 #define PB_ASSOC_DBG_ONLY(X) ;
00069 #endif // #ifdef PB_ASSOC_MAP_DEBUG_BASE_DEBUG
00070 
00071 #define PB_ASSOC_CLASS_T_DEC \
00072     template<typename Key, class Eq_Fn>
00073 
00074 #define PB_ASSOC_CLASS_C_DEC \
00075     map_debug_base< \
00076         Key, \
00077         Eq_Fn>
00078 
00079     template<typename Key, class Eq_Fn>
00080     class map_debug_base
00081     {
00082     private:
00083       typedef typename std::allocator<Key> key_allocator;
00084 
00085       typedef typename key_allocator::size_type size_type;
00086 
00087       typedef typename key_allocator::const_reference const_key_reference;
00088 
00089     protected:
00090       map_debug_base();
00091 
00092       map_debug_base(const PB_ASSOC_CLASS_C_DEC& r_other);
00093 
00094       ~map_debug_base();
00095 
00096       inline void
00097       insert_new(const_key_reference r_key);
00098 
00099       inline void
00100       insert_existing(const_key_reference r_key);
00101 
00102       inline void
00103       erase_existing(const_key_reference r_key);
00104 
00105       void
00106       clear();
00107 
00108       inline void
00109       check_key_exists(const_key_reference r_key) const;
00110 
00111       inline void
00112       check_key_does_not_exist(const_key_reference r_key) const;
00113 
00114       inline void
00115       check_size(size_type size) const;
00116 
00117       void
00118       swap(PB_ASSOC_CLASS_C_DEC& r_other);
00119 
00120     private:
00121       typedef std::set<Key> key_set;
00122 
00123     private:
00124       key_set m_key_set;
00125     };
00126 
00127     PB_ASSOC_CLASS_T_DEC
00128     PB_ASSOC_CLASS_C_DEC::
00129     map_debug_base()
00130     {
00131 
00132     }
00133 
00134     PB_ASSOC_CLASS_T_DEC
00135     PB_ASSOC_CLASS_C_DEC::
00136     map_debug_base(const PB_ASSOC_CLASS_C_DEC& r_other) :
00137       m_key_set(r_other.m_key_set)
00138     { }
00139 
00140     PB_ASSOC_CLASS_T_DEC
00141     PB_ASSOC_CLASS_C_DEC::
00142     ~map_debug_base()
00143     { }
00144 
00145     PB_ASSOC_CLASS_T_DEC
00146     inline void
00147     PB_ASSOC_CLASS_C_DEC::
00148     insert_new(const_key_reference r_key)
00149     {
00150       const double orig_throw_prob =
00151     pb_assoc::detail::test::dbg_ex_allocator_base().get_throw_prob();
00152 
00153       pb_assoc::detail::test::dbg_ex_allocator_base().
00154     set_throw_prob(0);
00155 
00156       if (m_key_set.find(r_key) != m_key_set.end())
00157     abort();
00158 
00159       try
00160     {
00161       m_key_set.insert(r_key);
00162     }
00163       catch(...)
00164     {
00165       pb_assoc::detail::test::dbg_ex_allocator_base().
00166         set_throw_prob(orig_throw_prob);
00167 
00168       throw;
00169     }
00170 
00171       pb_assoc::detail::test::dbg_ex_allocator_base().
00172     set_throw_prob(orig_throw_prob);
00173     }
00174 
00175     PB_ASSOC_CLASS_T_DEC
00176     inline void
00177     PB_ASSOC_CLASS_C_DEC::
00178     erase_existing(const_key_reference r_key)
00179     {
00180       if (m_key_set.find(r_key) == m_key_set.end())
00181     abort();
00182 
00183       m_key_set.erase(r_key);
00184 
00185       if (m_key_set.find(r_key) != m_key_set.end())
00186     abort();
00187     }
00188 
00189     PB_ASSOC_CLASS_T_DEC
00190     void
00191     PB_ASSOC_CLASS_C_DEC::
00192     clear()
00193     {
00194       m_key_set.clear();
00195     }
00196 
00197     PB_ASSOC_CLASS_T_DEC
00198     inline void
00199     PB_ASSOC_CLASS_C_DEC::
00200     check_key_exists(const_key_reference r_key) const
00201     {
00202       if (m_key_set.find(r_key) == m_key_set.end())
00203     abort();
00204     }
00205 
00206     PB_ASSOC_CLASS_T_DEC
00207     inline void
00208     PB_ASSOC_CLASS_C_DEC::
00209     check_key_does_not_exist(const_key_reference r_key) const
00210     {
00211       if (m_key_set.find(r_key) != m_key_set.end())
00212     abort();
00213     }
00214 
00215     PB_ASSOC_CLASS_T_DEC
00216     inline void
00217     PB_ASSOC_CLASS_C_DEC::
00218     check_size(size_type size) const
00219     {
00220       const size_type key_set_size = m_key_set.size();
00221 
00222       if (size != key_set_size)
00223     abort();
00224     }
00225 
00226     PB_ASSOC_CLASS_T_DEC
00227     void
00228     PB_ASSOC_CLASS_C_DEC::
00229     swap(PB_ASSOC_CLASS_C_DEC& r_other)
00230     {
00231       m_key_set.swap(r_other.m_key_set);
00232     }
00233 
00234 #undef PB_ASSOC_CLASS_T_DEC
00235 #undef PB_ASSOC_CLASS_C_DEC
00236 
00237 #undef PB_ASSOC_DBG_ASSERT
00238 #undef PB_ASSOC_DBG_VERIFY
00239 #undef PB_ASSOC_DBG_ONLY
00240 
00241   } // namespace detail
00242 
00243 } // namespace pb_assoc
00244 
00245 #endif // #ifdef PB_ASSOC_USE_MAP_DEBUG_BASE
00246 
00247 #endif // #ifndef MAP_DEBUG_BASE_HPP
00248 

Generated on Tue Feb 2 16:56:15 2010 for GNU C++ STL by  doxygen 1.4.7