Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / ext / pb_ds / detail / ov_tree_map_ / constructors_destructor_fn_imps.hpp
blob0f50317b879f9fecb18b730750c9b03b35e7272a
1 // -*- C++ -*-
3 // Copyright (C) 2005, 2006 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 terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, or (at your option) any later
9 // version.
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
29 // Public License.
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
40 // warranty.
42 /**
43 * @file constructors_destructor_fn_imps.hpp
44 * Contains an implementation class for ov_tree_.
47 PB_DS_CLASS_T_DEC
48 typename PB_DS_CLASS_C_DEC::value_allocator
49 PB_DS_CLASS_C_DEC::s_value_alloc;
51 PB_DS_CLASS_T_DEC
52 typename PB_DS_CLASS_C_DEC::metadata_allocator
53 PB_DS_CLASS_C_DEC::s_metadata_alloc;
55 PB_DS_CLASS_T_DEC
56 PB_DS_CLASS_C_DEC::
57 PB_DS_OV_TREE_CLASS_NAME() :
58 m_a_values(NULL),
59 m_a_metadata(NULL),
60 m_end_it(NULL),
61 m_size(0)
62 { _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) }
64 PB_DS_CLASS_T_DEC
65 PB_DS_CLASS_C_DEC::
66 PB_DS_OV_TREE_CLASS_NAME(const Cmp_Fn& r_cmp_fn) :
67 cmp_fn_base(r_cmp_fn),
68 m_a_values(NULL),
69 m_a_metadata(NULL),
70 m_end_it(NULL),
71 m_size(0)
72 { _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) }
74 PB_DS_CLASS_T_DEC
75 PB_DS_CLASS_C_DEC::
76 PB_DS_OV_TREE_CLASS_NAME(const Cmp_Fn& r_cmp_fn, const node_update& r_node_update) :
77 cmp_fn_base(r_cmp_fn),
78 node_update(r_node_update),
79 m_a_values(NULL),
80 m_a_metadata(NULL),
81 m_end_it(NULL),
82 m_size(0)
83 { _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) }
85 PB_DS_CLASS_T_DEC
86 PB_DS_CLASS_C_DEC::
87 PB_DS_OV_TREE_CLASS_NAME(const PB_DS_CLASS_C_DEC& other) :
88 #ifdef _GLIBCXX_DEBUG
89 debug_base(other),
90 #endif
91 #ifdef PB_DS_TREE_TRACE
92 PB_DS_TREE_TRACE_BASE_C_DEC(other),
93 #endif
94 cmp_fn_base(other),
95 node_update(other),
96 m_a_values(NULL),
97 m_a_metadata(NULL),
98 m_end_it(NULL),
99 m_size(0)
101 copy_from_ordered_range(other.begin(), other.end());
102 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
105 PB_DS_CLASS_T_DEC
106 template<typename It>
107 inline void
108 PB_DS_CLASS_C_DEC::
109 copy_from_range(It first_it, It last_it)
111 #ifdef PB_DS_DATA_TRUE_INDICATOR
112 typedef
113 std::map<
114 key_type,
115 mapped_type,
116 Cmp_Fn,
117 typename Allocator::template rebind<
118 value_type>::other>
119 map_type;
120 #else
121 typedef
122 std::set<
123 key_type,
124 Cmp_Fn,
125 typename Allocator::template rebind<
126 Key>::other>
127 map_type;
128 #endif
130 map_type m(first_it, last_it);
131 copy_from_ordered_range(m.begin(), m.end());
134 PB_DS_CLASS_T_DEC
135 template<typename It>
136 void
137 PB_DS_CLASS_C_DEC::
138 copy_from_ordered_range(It first_it, It last_it)
140 const size_type len = std::distance(first_it, last_it);
141 if (len == 0)
142 return;
144 value_vector a_values = s_value_alloc.allocate(len);
145 iterator target_it = a_values;
146 It source_it = first_it;
147 It source_end_it = last_it;
149 cond_dtor<size_type> cd(a_values, target_it, len);
150 while (source_it != source_end_it)
152 new (const_cast<void* >(static_cast<const void* >(target_it)))
153 value_type(*source_it++);
155 ++target_it;
158 reallocate_metadata((node_update* )this, len);
159 cd.set_no_action();
160 m_a_values = a_values;
161 m_size = len;
162 m_end_it = m_a_values + m_size;
163 update(PB_DS_node_begin_imp(), (node_update* )this);
165 #ifdef _GLIBCXX_DEBUG
166 const_iterator dbg_it = m_a_values;
167 while (dbg_it != m_end_it)
169 debug_base::insert_new(PB_DS_V2F(*dbg_it));
170 dbg_it++;
172 PB_DS_CLASS_C_DEC::assert_valid();
173 #endif
176 PB_DS_CLASS_T_DEC
177 template<typename It>
178 void
179 PB_DS_CLASS_C_DEC::
180 copy_from_ordered_range(It first_it, It last_it, It other_first_it,
181 It other_last_it)
183 clear();
184 const size_type len = std::distance(first_it, last_it)
185 + std::distance(other_first_it, other_last_it);
187 value_vector a_values = s_value_alloc.allocate(len);
189 iterator target_it = a_values;
190 It source_it = first_it;
191 It source_end_it = last_it;
193 cond_dtor<size_type> cd(a_values, target_it, len);
194 while (source_it != source_end_it)
196 new (const_cast<void* >(static_cast<const void* >(target_it)))
197 value_type(*source_it++);
198 ++target_it;
201 source_it = other_first_it;
202 source_end_it = other_last_it;
204 while (source_it != source_end_it)
206 new (const_cast<void* >(static_cast<const void* >(target_it)))
207 value_type(*source_it++);
208 ++target_it;
211 reallocate_metadata((node_update* )this, len);
212 cd.set_no_action();
213 m_a_values = a_values;
214 m_size = len;
215 m_end_it = m_a_values + m_size;
216 update(PB_DS_node_begin_imp(), (node_update* )this);
218 #ifdef _GLIBCXX_DEBUG
219 const_iterator dbg_it = m_a_values;
220 while (dbg_it != m_end_it)
222 debug_base::insert_new(PB_DS_V2F(*dbg_it));
223 dbg_it++;
225 PB_DS_CLASS_C_DEC::assert_valid();
226 #endif
229 PB_DS_CLASS_T_DEC
230 void
231 PB_DS_CLASS_C_DEC::
232 swap(PB_DS_CLASS_C_DEC& other)
234 _GLIBCXX_DEBUG_ONLY(assert_valid();)
235 value_swap(other);
236 std::swap((Cmp_Fn& )(*this), (Cmp_Fn& )other);
237 _GLIBCXX_DEBUG_ONLY(assert_valid();)
240 PB_DS_CLASS_T_DEC
241 void
242 PB_DS_CLASS_C_DEC::
243 value_swap(PB_DS_CLASS_C_DEC& other)
245 std::swap(m_a_values, other.m_a_values);
246 std::swap(m_a_metadata, other.m_a_metadata);
247 std::swap(m_size, other.m_size);
248 std::swap(m_end_it, other.m_end_it);
249 _GLIBCXX_DEBUG_ONLY(debug_base::swap(other);)
252 PB_DS_CLASS_T_DEC
253 PB_DS_CLASS_C_DEC::
254 ~PB_DS_OV_TREE_CLASS_NAME()
256 _GLIBCXX_DEBUG_ONLY(assert_valid();)
257 cond_dtor<size_type> cd(m_a_values, m_end_it, m_size);
258 reallocate_metadata((node_update* )this, 0);
261 PB_DS_CLASS_T_DEC
262 inline void
263 PB_DS_CLASS_C_DEC::
264 update(node_iterator /*it*/, null_node_update_pointer)
267 PB_DS_CLASS_T_DEC
268 template<typename Node_Update>
269 void
270 PB_DS_CLASS_C_DEC::
271 update(node_iterator nd_it, Node_Update* p_update)
273 const_node_iterator end_it = PB_DS_node_end_imp();
274 if (nd_it == end_it)
275 return;
276 update(nd_it.get_l_child(), p_update);
277 update(nd_it.get_r_child(), p_update);
278 node_update::operator()(nd_it, end_it);