constructors_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 
00045 PB_ASSOC_CLASS_T_DEC
00046 typename PB_ASSOC_CLASS_C_DEC::value_allocator
00047 PB_ASSOC_CLASS_C_DEC::s_alloc;
00048 
00049 PB_ASSOC_CLASS_T_DEC
00050 PB_ASSOC_CLASS_C_DEC::
00051 PB_ASSOC_OV_TREE_CLASS_NAME() :
00052   m_a_values(NULL),
00053   m_end_it(NULL),
00054   m_size(0)
00055 {
00056   update(node_begin(), (Node_Updator* )this);
00057 
00058   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
00059     }
00060 
00061 PB_ASSOC_CLASS_T_DEC
00062 PB_ASSOC_CLASS_C_DEC::
00063 PB_ASSOC_OV_TREE_CLASS_NAME(const Cmp_Fn& r_cmp_fn) :
00064   my_cmp_fn_base(r_cmp_fn),
00065   m_a_values(NULL),
00066   m_end_it(NULL),
00067   m_size(0)
00068 {
00069   update(node_begin(), (Node_Updator* )this);
00070 
00071   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
00072     }
00073 
00074 PB_ASSOC_CLASS_T_DEC
00075 PB_ASSOC_CLASS_C_DEC::
00076 PB_ASSOC_OV_TREE_CLASS_NAME(const Cmp_Fn& r_cmp_fn, const Node_Updator& r_node_updator) :
00077   my_cmp_fn_base(r_cmp_fn),
00078   Node_Updator(r_node_updator),
00079   m_a_values(NULL),
00080   m_end_it(NULL),
00081   m_size(0)
00082 {
00083   update(node_begin(), (Node_Updator* )this);
00084 
00085   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
00086     }
00087 
00088 PB_ASSOC_CLASS_T_DEC
00089 PB_ASSOC_CLASS_C_DEC::
00090 PB_ASSOC_OV_TREE_CLASS_NAME(const PB_ASSOC_CLASS_C_DEC& r_other) :
00091   my_cmp_fn_base(r_other),
00092   m_a_values(NULL),
00093   m_end_it(NULL),
00094   m_size(0)
00095 {
00096   copy_from_ordered_range(r_other.begin(), r_other.end());
00097 
00098   PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
00099     }
00100 
00101 PB_ASSOC_CLASS_T_DEC
00102 template<class It>
00103 inline void
00104 PB_ASSOC_CLASS_C_DEC::
00105 copy_from_range(It first_it, It last_it)
00106 {
00107   enum
00108     {
00109       is_set_type = is_same_type<Data, null_data_type>::value
00110     };
00111 
00112   typedef
00113     typename cond_type<
00114     is_set_type,
00115     std::set<
00116     Key,
00117     Cmp_Fn,
00118     typename Allocator::template rebind<
00119     Key>::other>,
00120     std::map<
00121     Key,
00122     Data,
00123     Cmp_Fn,
00124     typename Allocator::template rebind<
00125     std::pair<const Key, Data> >::other> >::type
00126     map_type;
00127 
00128   map_type m(first_it, last_it);
00129 
00130   copy_from_ordered_range(m.begin(), m.end());
00131 }
00132 
00133 PB_ASSOC_CLASS_T_DEC
00134 template<class It>
00135 void
00136 PB_ASSOC_CLASS_C_DEC::
00137 copy_from_ordered_range(It first_it, It last_it)
00138 {
00139   clear();
00140 
00141   const size_type size = std::distance(first_it, last_it);
00142 
00143   pointer a_values = s_alloc.allocate(size);
00144 
00145   iterator target_it = a_values;
00146   It source_it = first_it;
00147   It source_end_it = last_it;
00148 
00149   cond_dtor cd(a_values, target_it, size);
00150 
00151   while (source_it != source_end_it)
00152     {
00153       new (const_cast<void* >(
00154                   static_cast<const void* >(target_it)))
00155     value_type(*source_it++);
00156 
00157       ++target_it;
00158     }
00159 
00160   cd.set_no_action();
00161 
00162   m_a_values = a_values;
00163 
00164   m_size = size;
00165 
00166   m_end_it = m_a_values + m_size;
00167 
00168   update(node_begin(), (Node_Updator* )this);
00169 
00170 #ifdef PB_ASSOC_OV_TREE_DEBUG_
00171   const_iterator dbg_it = m_a_values;
00172 
00173   while (dbg_it != m_end_it)
00174     {
00175       my_map_debug_base::insert_new(PB_ASSOC_V2F(*dbg_it));
00176 
00177       dbg_it++;
00178     }
00179 
00180   PB_ASSOC_CLASS_C_DEC::assert_valid();
00181 #endif // #ifdef PB_ASSOC_OV_TREE_DEBUG_
00182 }
00183 
00184 PB_ASSOC_CLASS_T_DEC
00185 template<class It>
00186 void
00187 PB_ASSOC_CLASS_C_DEC::
00188 copy_from_ordered_range(It first_it, It last_it, It other_first_it, It other_last_it)
00189 {
00190   clear();
00191 
00192   const size_type size =
00193     std::distance(first_it, last_it) +
00194     std::distance(other_first_it, other_last_it);
00195 
00196   pointer a_values = s_alloc.allocate(size);
00197 
00198   iterator target_it = a_values;
00199   It source_it = first_it;
00200   It source_end_it = last_it;
00201 
00202   cond_dtor cd(a_values, target_it, size);
00203 
00204   while (source_it != source_end_it)
00205     {
00206       new (const_cast<void* >(
00207                   static_cast<const void* >(target_it)))
00208     value_type(*source_it++);
00209 
00210       ++target_it;
00211     }
00212 
00213   source_it = other_first_it;
00214   source_end_it = other_last_it;
00215 
00216   while (source_it != source_end_it)
00217     {
00218       new (const_cast<void* >(
00219                   static_cast<const void* >(target_it)))
00220     value_type(*source_it++);
00221 
00222       ++target_it;
00223     }
00224 
00225   cd.set_no_action();
00226 
00227   m_a_values = a_values;
00228 
00229   m_size = size;
00230 
00231   m_end_it = m_a_values + m_size;
00232 
00233   update(node_begin(), (Node_Updator* )this);
00234 
00235 #ifdef PB_ASSOC_OV_TREE_DEBUG_
00236   const_iterator dbg_it = m_a_values;
00237 
00238   while (dbg_it != m_end_it)
00239     {
00240       my_map_debug_base::insert_new(PB_ASSOC_V2F(*dbg_it));
00241 
00242       dbg_it++;
00243     }
00244 
00245   PB_ASSOC_CLASS_C_DEC::assert_valid();
00246 #endif // #ifdef PB_ASSOC_OV_TREE_DEBUG_
00247 }
00248 
00249 PB_ASSOC_CLASS_T_DEC
00250 void
00251 PB_ASSOC_CLASS_C_DEC::
00252 swap(PB_ASSOC_CLASS_C_DEC& r_other)
00253 {
00254   PB_ASSOC_DBG_ONLY(assert_valid();)
00255 
00256     std::swap(m_a_values, r_other.m_a_values);
00257 
00258   std::swap(m_size, r_other.m_size);
00259 
00260   std::swap(m_end_it, r_other.m_end_it);
00261 
00262   std::swap((Cmp_Fn& )(*this), (Cmp_Fn& )r_other);
00263 
00264   Node_Updator::swap(r_other);
00265 
00266   PB_ASSOC_DBG_ONLY(my_map_debug_base::swap(r_other);)
00267 
00268     PB_ASSOC_DBG_ONLY(assert_valid();)
00269     }
00270 
00271 PB_ASSOC_CLASS_T_DEC
00272 PB_ASSOC_CLASS_C_DEC::
00273 ~PB_ASSOC_OV_TREE_CLASS_NAME()
00274 {
00275   PB_ASSOC_DBG_ONLY(assert_valid();)
00276 
00277     cond_dtor cd(m_a_values, m_end_it, m_size);
00278 }

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