constructor_destructor_fn_imps.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 
00046 PB_ASSOC_CLASS_T_DEC
00047 typename PB_ASSOC_CLASS_C_DEC::entry_allocator
00048 PB_ASSOC_CLASS_C_DEC::s_entry_allocator;
00049 
00050 PB_ASSOC_CLASS_T_DEC
00051 typename PB_ASSOC_CLASS_C_DEC::entry_pointer_allocator
00052 PB_ASSOC_CLASS_C_DEC::s_entry_pointer_allocator;
00053 
00054 PB_ASSOC_CLASS_T_DEC
00055 template<class It>
00056 void
00057 PB_ASSOC_CLASS_C_DEC::
00058 copy_from_range(It first_it, It last_it)
00059 {
00060   while (first_it != last_it)
00061     insert(*(first_it++));
00062 }
00063 
00064 PB_ASSOC_CLASS_T_DEC
00065 PB_ASSOC_CLASS_C_DEC::
00066 PB_ASSOC_CLASS_NAME() :
00067   my_ranged_hash_fn_base(Resize_Policy::get_init_size()),
00068   m_a_p_entries(s_entry_pointer_allocator.allocate(
00069                            Resize_Policy::get_init_size())),
00070   m_num_e_p(Resize_Policy::get_init_size()),
00071   m_num_used_e(0)
00072 {
00073   std::fill(m_a_p_entries, m_a_p_entries + m_num_e_p, (entry_pointer)NULL);
00074 
00075   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
00076     }
00077 
00078 PB_ASSOC_CLASS_T_DEC
00079 PB_ASSOC_CLASS_C_DEC::
00080 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn) :
00081   my_ranged_hash_fn_base(Resize_Policy::get_init_size(),
00082              r_hash_fn),
00083   m_a_p_entries(s_entry_pointer_allocator.allocate(
00084                            Resize_Policy::get_init_size())),
00085   m_num_e_p(Resize_Policy::get_init_size()),
00086   m_num_used_e(0)
00087 {
00088   std::fill(m_a_p_entries, m_a_p_entries + m_num_e_p, (entry_pointer)NULL);
00089 
00090   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
00091     }
00092 
00093 PB_ASSOC_CLASS_T_DEC
00094 PB_ASSOC_CLASS_C_DEC::
00095 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) :
00096   PB_ASSOC_HASH_EQ_FN_C_DEC(r_eq_fn),
00097   my_ranged_hash_fn_base(Resize_Policy::get_init_size(),
00098              r_hash_fn),
00099   m_a_p_entries(s_entry_pointer_allocator.allocate(
00100                            Resize_Policy::get_init_size())),
00101   m_num_e_p(Resize_Policy::get_init_size()),
00102   m_num_used_e(0)
00103 {
00104   std::fill(m_a_p_entries, m_a_p_entries + m_num_e_p, (entry_pointer)NULL);
00105 
00106   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
00107     }
00108 
00109 PB_ASSOC_CLASS_T_DEC
00110 PB_ASSOC_CLASS_C_DEC::
00111 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Hash_Fn& r_comb_hash_fn) :
00112   PB_ASSOC_HASH_EQ_FN_C_DEC(r_eq_fn),
00113   my_ranged_hash_fn_base(Resize_Policy::get_init_size(),
00114              r_hash_fn, r_comb_hash_fn),
00115   m_a_p_entries(s_entry_pointer_allocator.allocate(
00116                            Resize_Policy::get_init_size())),
00117   m_num_e_p(Resize_Policy::get_init_size()),
00118   m_num_used_e(0)
00119 {
00120   std::fill(m_a_p_entries, m_a_p_entries + m_num_e_p, (entry_pointer)NULL);
00121 
00122   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
00123     }
00124 
00125 PB_ASSOC_CLASS_T_DEC
00126 PB_ASSOC_CLASS_C_DEC::
00127 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Hash_Fn& r_comb_hash_fn, const Resize_Policy& r_resize_policy) :
00128   PB_ASSOC_HASH_EQ_FN_C_DEC(r_eq_fn),
00129   Resize_Policy(r_resize_policy),
00130   my_ranged_hash_fn_base(Resize_Policy::get_init_size(),
00131              r_hash_fn, r_comb_hash_fn),
00132   m_a_p_entries(s_entry_pointer_allocator.allocate(
00133                            Resize_Policy::get_init_size())),
00134   m_num_e_p(Resize_Policy::get_init_size()),
00135   m_num_used_e(0)
00136 {
00137   std::fill(m_a_p_entries, m_a_p_entries + m_num_e_p, (entry_pointer)NULL);
00138 
00139   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
00140     }
00141 
00142 PB_ASSOC_CLASS_T_DEC
00143 PB_ASSOC_CLASS_C_DEC::
00144 PB_ASSOC_CLASS_NAME(const PB_ASSOC_CLASS_C_DEC& r_other) :
00145   PB_ASSOC_HASH_EQ_FN_C_DEC(r_other),
00146   my_resize_base(r_other),
00147   my_ranged_hash_fn_base(r_other),
00148   m_a_p_entries(s_entry_pointer_allocator.allocate(
00149                            r_other.m_num_e_p)),
00150   m_num_e_p(r_other.m_num_e_p),
00151   m_num_used_e(r_other.m_num_used_e)
00152 {
00153   PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
00154 
00155     std::fill(m_a_p_entries, m_a_p_entries + m_num_e_p, (entry_pointer)NULL);
00156 
00157   try
00158     {
00159       for (size_type i  = 0; i < m_num_e_p; ++i)
00160     {
00161       entry_pointer p_e = r_other.m_a_p_entries[i];
00162 
00163       while (p_e != NULL)
00164         {
00165           constructor_insert_new_imp(
00166                      const_mapped_reference(p_e->m_value), i,
00167                      my_hash_traits_base::s_store_hash_indicator);
00168 
00169           p_e = p_e->m_p_next;
00170         }
00171     }
00172     }
00173   catch(...)
00174     {
00175       deallocate_all();
00176 
00177       throw;
00178     }
00179 
00180   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
00181     }
00182 
00183 PB_ASSOC_CLASS_T_DEC
00184 PB_ASSOC_CLASS_C_DEC::
00185 ~PB_ASSOC_CLASS_NAME()
00186 {
00187   deallocate_all();
00188 }
00189 
00190 PB_ASSOC_CLASS_T_DEC
00191 void
00192 PB_ASSOC_CLASS_C_DEC::
00193 swap(PB_ASSOC_CLASS_C_DEC& r_other)
00194 {
00195   PB_ASSOC_DBG_ONLY(assert_valid());
00196   PB_ASSOC_DBG_ONLY(r_other.assert_valid());
00197 
00198   std::swap(m_a_p_entries, r_other.m_a_p_entries);
00199 
00200   std::swap(m_num_e_p, r_other.m_num_e_p);
00201 
00202   std::swap(m_num_used_e, r_other.m_num_used_e);
00203 
00204   my_ranged_hash_fn_base::swap(r_other);
00205 
00206   my_hash_eq_fn_base::swap(r_other);
00207 
00208   my_resize_base::swap(r_other);
00209 
00210   PB_ASSOC_DBG_ONLY(my_map_debug_base::swap(r_other));
00211 
00212   PB_ASSOC_DBG_ONLY(assert_valid());
00213   PB_ASSOC_DBG_ONLY(r_other.assert_valid());
00214 }
00215 
00216 PB_ASSOC_CLASS_T_DEC
00217 void
00218 PB_ASSOC_CLASS_C_DEC::
00219 deallocate_all()
00220 {
00221   clear();
00222 
00223   s_entry_pointer_allocator.deallocate(m_a_p_entries, m_num_e_p);
00224 }
00225 
00226 #include <ext/pb_assoc/detail/cc_ht_map_/constructor_destructor_store_hash_fn_imps.hpp>
00227 #include <ext/pb_assoc/detail/cc_ht_map_/constructor_destructor_no_store_hash_fn_imps.hpp>

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