gcc41 removal: Part 1 of 2: makefiles
[dragonfly.git] / contrib / gcc-4.1 / libstdc++-v3 / include / ext / pb_assoc / detail / gp_ht_map_ / constructor_destructor_fn_imps.hpp
1 // -*- C++ -*-
2
3 // Copyright (C) 2005 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
31
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
39
40 /**
41  * @file constructor_destructor_fn_imps.hpp
42  * Contains implementations of gp_ht_map_'s constructors, destructor,
43  *      and related functions.
44  */
45
46 PB_ASSOC_CLASS_T_DEC
47 typename PB_ASSOC_CLASS_C_DEC::entry_allocator
48 PB_ASSOC_CLASS_C_DEC::s_entry_allocator;
49
50 PB_ASSOC_CLASS_T_DEC
51 template<class It>
52 void
53 PB_ASSOC_CLASS_C_DEC::
54 copy_from_range(It first_it, It last_it)
55 {
56   while (first_it != last_it)
57     insert(*(first_it++));
58 }
59
60 PB_ASSOC_CLASS_T_DEC
61 PB_ASSOC_CLASS_C_DEC::
62 PB_ASSOC_CLASS_NAME() :
63   my_ranged_probe_fn_base(Resize_Policy::get_init_size()),
64   m_a_entries(s_entry_allocator.allocate(
65                                          Resize_Policy::get_init_size())),
66   m_num_e(Resize_Policy::get_init_size()),
67   m_num_used_e(0)
68 {
69   initialize();
70
71   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
72     }
73
74 PB_ASSOC_CLASS_T_DEC
75 PB_ASSOC_CLASS_C_DEC::
76 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn)  :
77   my_ranged_probe_fn_base(Resize_Policy::get_init_size(), r_hash_fn),
78   m_a_entries(s_entry_allocator.allocate(
79                                          Resize_Policy::get_init_size())),
80   m_num_e(Resize_Policy::get_init_size()),
81   m_num_used_e(0)
82 {
83   initialize();
84
85   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
86     }
87
88 PB_ASSOC_CLASS_T_DEC
89 PB_ASSOC_CLASS_C_DEC::
90 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) :
91   my_hash_eq_fn_base(r_eq_fn),
92   my_ranged_probe_fn_base(Resize_Policy::get_init_size(), r_hash_fn),
93   m_a_entries(s_entry_allocator.allocate(
94                                          Resize_Policy::get_init_size())),
95   m_num_e(Resize_Policy::get_init_size()),
96   m_num_used_e(0)
97 {
98   initialize();
99
100   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
101     }
102
103 PB_ASSOC_CLASS_T_DEC
104 PB_ASSOC_CLASS_C_DEC::
105 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Probe_Fn& r_comb_hash_fn) :
106   my_hash_eq_fn_base(r_eq_fn),
107   my_ranged_probe_fn_base(Resize_Policy::get_init_size(),
108                           r_hash_fn, r_comb_hash_fn),
109   m_a_entries(s_entry_allocator.allocate(
110                                          Resize_Policy::get_init_size())),
111   m_num_e(Resize_Policy::get_init_size()),
112   m_num_used_e(0)
113 {
114   initialize();
115
116   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
117     }
118
119 PB_ASSOC_CLASS_T_DEC
120 PB_ASSOC_CLASS_C_DEC::
121 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Probe_Fn& r_comb_hash_fn, const Probe_Fn& r_probe_fn) :
122   my_hash_eq_fn_base(r_eq_fn),
123   my_ranged_probe_fn_base(Resize_Policy::get_init_size(),
124                           r_hash_fn, r_comb_hash_fn, r_probe_fn),
125   m_a_entries(s_entry_allocator.allocate(
126                                          Resize_Policy::get_init_size())),
127   m_num_e(Resize_Policy::get_init_size()),
128   m_num_used_e(0)
129 {
130   initialize();
131
132   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
133     }
134
135 PB_ASSOC_CLASS_T_DEC
136 PB_ASSOC_CLASS_C_DEC::
137 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Probe_Fn& r_comb_hash_fn, const Probe_Fn& r_probe_fn, const Resize_Policy& r_resize_policy) :
138   my_hash_eq_fn_base(r_eq_fn),
139   my_resize_base(r_resize_policy),
140   my_ranged_probe_fn_base(Resize_Policy::get_init_size(),
141                           r_hash_fn, r_comb_hash_fn, r_probe_fn),
142   m_a_entries(s_entry_allocator.allocate(
143                                          Resize_Policy::get_init_size())),
144   m_num_e(Resize_Policy::get_init_size()),
145   m_num_used_e(0)
146 {
147   initialize();
148
149   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_r_valid();)
150     }
151
152 PB_ASSOC_CLASS_T_DEC
153 PB_ASSOC_CLASS_C_DEC::
154 PB_ASSOC_CLASS_NAME(const PB_ASSOC_CLASS_C_DEC& r_other) :
155   my_hash_eq_fn_base(r_other),
156   my_resize_base(r_other),
157   my_ranged_probe_fn_base(r_other),
158   m_a_entries(s_entry_allocator.allocate(
159                                          r_other.m_num_e)),
160   m_num_e(r_other.m_num_e),
161   m_num_used_e(r_other.m_num_used_e)
162 {
163   initialize();
164
165   try
166     {
167       for (size_type i = 0; i < m_num_e; ++i)
168         {
169           entry_pointer p_e =& r_other.m_a_entries[i];
170           if (p_e->m_stat == VALID_ENTRY_STATUS)
171             constructor_insert_new_imp((const_mapped_reference)p_e->m_value,
172                                        i,
173                                        my_hash_traits_base::s_store_hash_indicator);
174         }
175     }
176   catch(...)
177     {
178       deallocate_all();
179
180       throw;
181     }
182
183   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
184     }
185
186 PB_ASSOC_CLASS_T_DEC
187 PB_ASSOC_CLASS_C_DEC::
188 ~PB_ASSOC_CLASS_NAME()
189 {
190   deallocate_all();
191 }
192
193 PB_ASSOC_CLASS_T_DEC
194 void
195 PB_ASSOC_CLASS_C_DEC::
196 swap(PB_ASSOC_CLASS_C_DEC& r_other)
197 {
198   PB_ASSOC_DBG_ONLY(assert_valid());
199   PB_ASSOC_DBG_ONLY(r_other.assert_valid());
200
201   std::swap(m_a_entries, r_other.m_a_entries);
202
203   std::swap(m_num_e, r_other.m_num_e);
204
205   std::swap(m_num_used_e, r_other.m_num_used_e);
206
207   my_ranged_probe_fn_base::swap(r_other);
208
209   my_hash_eq_fn_base::swap(r_other);
210
211   my_resize_base::swap(r_other);
212
213   PB_ASSOC_DBG_ONLY(my_cntnr_debug_base::swap(r_other));
214
215   PB_ASSOC_DBG_ONLY(assert_valid());
216   PB_ASSOC_DBG_ONLY(r_other.assert_valid());
217 }
218
219 PB_ASSOC_CLASS_T_DEC
220 void
221 PB_ASSOC_CLASS_C_DEC::
222 deallocate_all()
223 {
224   clear();
225
226   erase_all_valid_entries(m_a_entries, m_num_e);
227
228   s_entry_allocator.deallocate(m_a_entries, m_num_e);
229 }
230
231 PB_ASSOC_CLASS_T_DEC
232 void
233 PB_ASSOC_CLASS_C_DEC::
234 erase_all_valid_entries(entry_array a_entries_resized, size_type size)
235 {
236   for (size_type pos = 0; pos < size; ++pos)
237     {
238       entry_pointer p_e =& a_entries_resized[pos];
239
240       if (p_e->m_stat == VALID_ENTRY_STATUS)
241         p_e->m_value.~value_type();
242     }
243 }
244
245 PB_ASSOC_CLASS_T_DEC
246 void
247 PB_ASSOC_CLASS_C_DEC::
248 initialize()
249 {
250   for (size_type i = 0; i < m_num_e; ++i)
251     m_a_entries[i].m_stat = (entry_status)EMPTY_ENTRY_STATUS;
252 }
253
254 #include <ext/pb_assoc/detail/gp_ht_map_/constructor_destructor_store_hash_fn_imps.hpp>
255 #include <ext/pb_assoc/detail/gp_ht_map_/constructor_destructor_no_store_hash_fn_imps.hpp>