Initial import of binutils 2.22 on the new vendor branch
[dragonfly.git] / contrib / gcc-4.1 / libstdc++-v3 / include / ext / pb_assoc / detail / cc_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 cc_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 typename PB_ASSOC_CLASS_C_DEC::entry_pointer_allocator
52 PB_ASSOC_CLASS_C_DEC::s_entry_pointer_allocator;
53
54 PB_ASSOC_CLASS_T_DEC
55 template<class It>
56 void
57 PB_ASSOC_CLASS_C_DEC::
58 copy_from_range(It first_it, It last_it)
59 {
60   while (first_it != last_it)
61     insert(*(first_it++));
62 }
63
64 PB_ASSOC_CLASS_T_DEC
65 PB_ASSOC_CLASS_C_DEC::
66 PB_ASSOC_CLASS_NAME() :
67   my_ranged_hash_fn_base(Resize_Policy::get_init_size()),
68   m_a_p_entries(s_entry_pointer_allocator.allocate(
69                                                    Resize_Policy::get_init_size())),
70   m_num_e_p(Resize_Policy::get_init_size()),
71   m_num_used_e(0)
72 {
73   std::fill(m_a_p_entries, m_a_p_entries + m_num_e_p, (entry_pointer)NULL);
74
75   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
76     }
77
78 PB_ASSOC_CLASS_T_DEC
79 PB_ASSOC_CLASS_C_DEC::
80 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn) :
81   my_ranged_hash_fn_base(Resize_Policy::get_init_size(),
82                          r_hash_fn),
83   m_a_p_entries(s_entry_pointer_allocator.allocate(
84                                                    Resize_Policy::get_init_size())),
85   m_num_e_p(Resize_Policy::get_init_size()),
86   m_num_used_e(0)
87 {
88   std::fill(m_a_p_entries, m_a_p_entries + m_num_e_p, (entry_pointer)NULL);
89
90   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
91     }
92
93 PB_ASSOC_CLASS_T_DEC
94 PB_ASSOC_CLASS_C_DEC::
95 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) :
96   PB_ASSOC_HASH_EQ_FN_C_DEC(r_eq_fn),
97   my_ranged_hash_fn_base(Resize_Policy::get_init_size(),
98                          r_hash_fn),
99   m_a_p_entries(s_entry_pointer_allocator.allocate(
100                                                    Resize_Policy::get_init_size())),
101   m_num_e_p(Resize_Policy::get_init_size()),
102   m_num_used_e(0)
103 {
104   std::fill(m_a_p_entries, m_a_p_entries + m_num_e_p, (entry_pointer)NULL);
105
106   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
107     }
108
109 PB_ASSOC_CLASS_T_DEC
110 PB_ASSOC_CLASS_C_DEC::
111 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Hash_Fn& r_comb_hash_fn) :
112   PB_ASSOC_HASH_EQ_FN_C_DEC(r_eq_fn),
113   my_ranged_hash_fn_base(Resize_Policy::get_init_size(),
114                          r_hash_fn, r_comb_hash_fn),
115   m_a_p_entries(s_entry_pointer_allocator.allocate(
116                                                    Resize_Policy::get_init_size())),
117   m_num_e_p(Resize_Policy::get_init_size()),
118   m_num_used_e(0)
119 {
120   std::fill(m_a_p_entries, m_a_p_entries + m_num_e_p, (entry_pointer)NULL);
121
122   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
123     }
124
125 PB_ASSOC_CLASS_T_DEC
126 PB_ASSOC_CLASS_C_DEC::
127 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) :
128   PB_ASSOC_HASH_EQ_FN_C_DEC(r_eq_fn),
129   Resize_Policy(r_resize_policy),
130   my_ranged_hash_fn_base(Resize_Policy::get_init_size(),
131                          r_hash_fn, r_comb_hash_fn),
132   m_a_p_entries(s_entry_pointer_allocator.allocate(
133                                                    Resize_Policy::get_init_size())),
134   m_num_e_p(Resize_Policy::get_init_size()),
135   m_num_used_e(0)
136 {
137   std::fill(m_a_p_entries, m_a_p_entries + m_num_e_p, (entry_pointer)NULL);
138
139   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
140     }
141
142 PB_ASSOC_CLASS_T_DEC
143 PB_ASSOC_CLASS_C_DEC::
144 PB_ASSOC_CLASS_NAME(const PB_ASSOC_CLASS_C_DEC& r_other) :
145   PB_ASSOC_HASH_EQ_FN_C_DEC(r_other),
146   my_resize_base(r_other),
147   my_ranged_hash_fn_base(r_other),
148   m_a_p_entries(s_entry_pointer_allocator.allocate(
149                                                    r_other.m_num_e_p)),
150   m_num_e_p(r_other.m_num_e_p),
151   m_num_used_e(r_other.m_num_used_e)
152 {
153   PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
154
155     std::fill(m_a_p_entries, m_a_p_entries + m_num_e_p, (entry_pointer)NULL);
156
157   try
158     {
159       for (size_type i  = 0; i < m_num_e_p; ++i)
160         {
161           entry_pointer p_e = r_other.m_a_p_entries[i];
162
163           while (p_e != NULL)
164             {
165               constructor_insert_new_imp(
166                                          const_mapped_reference(p_e->m_value), i,
167                                          my_hash_traits_base::s_store_hash_indicator);
168
169               p_e = p_e->m_p_next;
170             }
171         }
172     }
173   catch(...)
174     {
175       deallocate_all();
176
177       throw;
178     }
179
180   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
181     }
182
183 PB_ASSOC_CLASS_T_DEC
184 PB_ASSOC_CLASS_C_DEC::
185 ~PB_ASSOC_CLASS_NAME()
186 {
187   deallocate_all();
188 }
189
190 PB_ASSOC_CLASS_T_DEC
191 void
192 PB_ASSOC_CLASS_C_DEC::
193 swap(PB_ASSOC_CLASS_C_DEC& r_other)
194 {
195   PB_ASSOC_DBG_ONLY(assert_valid());
196   PB_ASSOC_DBG_ONLY(r_other.assert_valid());
197
198   std::swap(m_a_p_entries, r_other.m_a_p_entries);
199
200   std::swap(m_num_e_p, r_other.m_num_e_p);
201
202   std::swap(m_num_used_e, r_other.m_num_used_e);
203
204   my_ranged_hash_fn_base::swap(r_other);
205
206   my_hash_eq_fn_base::swap(r_other);
207
208   my_resize_base::swap(r_other);
209
210   PB_ASSOC_DBG_ONLY(my_map_debug_base::swap(r_other));
211
212   PB_ASSOC_DBG_ONLY(assert_valid());
213   PB_ASSOC_DBG_ONLY(r_other.assert_valid());
214 }
215
216 PB_ASSOC_CLASS_T_DEC
217 void
218 PB_ASSOC_CLASS_C_DEC::
219 deallocate_all()
220 {
221   clear();
222
223   s_entry_pointer_allocator.deallocate(m_a_p_entries, m_num_e_p);
224 }
225
226 #include <ext/pb_assoc/detail/cc_ht_map_/constructor_destructor_store_hash_fn_imps.hpp>
227 #include <ext/pb_assoc/detail/cc_ht_map_/constructor_destructor_no_store_hash_fn_imps.hpp>