3 // Copyright (C) 2005 Free Software Foundation, Inc.
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)
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.
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,
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.
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
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.
41 * @file constructors_destructor_fn_imps.hpp
42 * Contains an implementation class for ov_tree_.
46 typename PB_ASSOC_CLASS_C_DEC::value_allocator
47 PB_ASSOC_CLASS_C_DEC::s_alloc;
50 PB_ASSOC_CLASS_C_DEC::
51 PB_ASSOC_OV_TREE_CLASS_NAME() :
56 update(node_begin(), (Node_Updator* )this);
58 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
62 PB_ASSOC_CLASS_C_DEC::
63 PB_ASSOC_OV_TREE_CLASS_NAME(const Cmp_Fn& r_cmp_fn) :
64 my_cmp_fn_base(r_cmp_fn),
69 update(node_begin(), (Node_Updator* )this);
71 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
75 PB_ASSOC_CLASS_C_DEC::
76 PB_ASSOC_OV_TREE_CLASS_NAME(const Cmp_Fn& r_cmp_fn, const Node_Updator& r_node_updator) :
77 my_cmp_fn_base(r_cmp_fn),
78 Node_Updator(r_node_updator),
83 update(node_begin(), (Node_Updator* )this);
85 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
89 PB_ASSOC_CLASS_C_DEC::
90 PB_ASSOC_OV_TREE_CLASS_NAME(const PB_ASSOC_CLASS_C_DEC& r_other) :
91 my_cmp_fn_base(r_other),
96 copy_from_ordered_range(r_other.begin(), r_other.end());
98 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
104 PB_ASSOC_CLASS_C_DEC::
105 copy_from_range(It first_it, It last_it)
109 is_set_type = is_same_type<Data, null_data_type>::value
118 typename Allocator::template rebind<
124 typename Allocator::template rebind<
125 std::pair<const Key, Data> >::other> >::type
128 map_type m(first_it, last_it);
130 copy_from_ordered_range(m.begin(), m.end());
136 PB_ASSOC_CLASS_C_DEC::
137 copy_from_ordered_range(It first_it, It last_it)
141 const size_type size = std::distance(first_it, last_it);
143 pointer a_values = s_alloc.allocate(size);
145 iterator target_it = a_values;
146 It source_it = first_it;
147 It source_end_it = last_it;
149 cond_dtor cd(a_values, target_it, size);
151 while (source_it != source_end_it)
153 new (const_cast<void* >(
154 static_cast<const void* >(target_it)))
155 value_type(*source_it++);
162 m_a_values = a_values;
166 m_end_it = m_a_values + m_size;
168 update(node_begin(), (Node_Updator* )this);
170 #ifdef PB_ASSOC_OV_TREE_DEBUG_
171 const_iterator dbg_it = m_a_values;
173 while (dbg_it != m_end_it)
175 my_map_debug_base::insert_new(PB_ASSOC_V2F(*dbg_it));
180 PB_ASSOC_CLASS_C_DEC::assert_valid();
181 #endif // #ifdef PB_ASSOC_OV_TREE_DEBUG_
187 PB_ASSOC_CLASS_C_DEC::
188 copy_from_ordered_range(It first_it, It last_it, It other_first_it, It other_last_it)
192 const size_type size =
193 std::distance(first_it, last_it) +
194 std::distance(other_first_it, other_last_it);
196 pointer a_values = s_alloc.allocate(size);
198 iterator target_it = a_values;
199 It source_it = first_it;
200 It source_end_it = last_it;
202 cond_dtor cd(a_values, target_it, size);
204 while (source_it != source_end_it)
206 new (const_cast<void* >(
207 static_cast<const void* >(target_it)))
208 value_type(*source_it++);
213 source_it = other_first_it;
214 source_end_it = other_last_it;
216 while (source_it != source_end_it)
218 new (const_cast<void* >(
219 static_cast<const void* >(target_it)))
220 value_type(*source_it++);
227 m_a_values = a_values;
231 m_end_it = m_a_values + m_size;
233 update(node_begin(), (Node_Updator* )this);
235 #ifdef PB_ASSOC_OV_TREE_DEBUG_
236 const_iterator dbg_it = m_a_values;
238 while (dbg_it != m_end_it)
240 my_map_debug_base::insert_new(PB_ASSOC_V2F(*dbg_it));
245 PB_ASSOC_CLASS_C_DEC::assert_valid();
246 #endif // #ifdef PB_ASSOC_OV_TREE_DEBUG_
251 PB_ASSOC_CLASS_C_DEC::
252 swap(PB_ASSOC_CLASS_C_DEC& r_other)
254 PB_ASSOC_DBG_ONLY(assert_valid();)
256 std::swap(m_a_values, r_other.m_a_values);
258 std::swap(m_size, r_other.m_size);
260 std::swap(m_end_it, r_other.m_end_it);
262 std::swap((Cmp_Fn& )(*this), (Cmp_Fn& )r_other);
264 Node_Updator::swap(r_other);
266 PB_ASSOC_DBG_ONLY(my_map_debug_base::swap(r_other);)
268 PB_ASSOC_DBG_ONLY(assert_valid();)
272 PB_ASSOC_CLASS_C_DEC::
273 ~PB_ASSOC_OV_TREE_CLASS_NAME()
275 PB_ASSOC_DBG_ONLY(assert_valid();)
277 cond_dtor cd(m_a_values, m_end_it, m_size);