libstdc++
|
00001 // -*- C++ -*- 00002 00003 // Copyright (C) 2005-2013 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 terms 00007 // of the GNU General Public License as published by the Free Software 00008 // Foundation; either version 3, or (at your option) any later 00009 // version. 00010 00011 // This library is distributed in the hope that it will be useful, but 00012 // WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 00026 00027 // Permission to use, copy, modify, sell, and distribute this software 00028 // is hereby granted without fee, provided that the above copyright 00029 // notice appears in all copies, and that both that copyright notice 00030 // and this permission notice appear in supporting documentation. None 00031 // of the above authors, nor IBM Haifa Research Laboratories, make any 00032 // representation about the suitability of this software for any 00033 // purpose. It is provided "as is" without express or implied 00034 // warranty. 00035 00036 /** 00037 * @file left_child_next_sibling_heap_/constructors_destructor_fn_imps.hpp 00038 * Contains an implementation class for left_child_next_sibling_heap_. 00039 */ 00040 00041 PB_DS_CLASS_T_DEC 00042 typename PB_DS_CLASS_C_DEC::node_allocator 00043 PB_DS_CLASS_C_DEC::s_node_allocator; 00044 00045 PB_DS_CLASS_T_DEC 00046 typename PB_DS_CLASS_C_DEC::no_throw_copies_t 00047 PB_DS_CLASS_C_DEC::s_no_throw_copies_ind; 00048 00049 PB_DS_CLASS_T_DEC 00050 PB_DS_CLASS_C_DEC:: 00051 left_child_next_sibling_heap() : 00052 m_p_root(0), 00053 m_size(0) 00054 { 00055 PB_DS_ASSERT_VALID((*this)) 00056 } 00057 00058 PB_DS_CLASS_T_DEC 00059 PB_DS_CLASS_C_DEC:: 00060 left_child_next_sibling_heap(const Cmp_Fn& r_cmp_fn) : 00061 Cmp_Fn(r_cmp_fn), 00062 m_p_root(0), 00063 m_size(0) 00064 { 00065 PB_DS_ASSERT_VALID((*this)) 00066 } 00067 00068 PB_DS_CLASS_T_DEC 00069 PB_DS_CLASS_C_DEC:: 00070 left_child_next_sibling_heap(const PB_DS_CLASS_C_DEC& other) 00071 : Cmp_Fn(other), m_p_root(0), m_size(0) 00072 { 00073 m_size = other.m_size; 00074 PB_DS_ASSERT_VALID(other) 00075 m_p_root = recursive_copy_node(other.m_p_root); 00076 m_size = other.m_size; 00077 PB_DS_ASSERT_VALID((*this)) 00078 } 00079 00080 PB_DS_CLASS_T_DEC 00081 void 00082 PB_DS_CLASS_C_DEC:: 00083 swap(PB_DS_CLASS_C_DEC& other) 00084 { 00085 PB_DS_ASSERT_VALID((*this)) 00086 PB_DS_ASSERT_VALID(other) 00087 value_swap(other); 00088 std::swap((Cmp_Fn& )(*this), (Cmp_Fn& )other); 00089 PB_DS_ASSERT_VALID((*this)) 00090 PB_DS_ASSERT_VALID(other) 00091 } 00092 00093 PB_DS_CLASS_T_DEC 00094 void 00095 PB_DS_CLASS_C_DEC:: 00096 value_swap(PB_DS_CLASS_C_DEC& other) 00097 { 00098 std::swap(m_p_root, other.m_p_root); 00099 std::swap(m_size, other.m_size); 00100 } 00101 00102 PB_DS_CLASS_T_DEC 00103 PB_DS_CLASS_C_DEC:: 00104 ~left_child_next_sibling_heap() 00105 { 00106 clear(); 00107 } 00108 00109 PB_DS_CLASS_T_DEC 00110 typename PB_DS_CLASS_C_DEC::node_pointer 00111 PB_DS_CLASS_C_DEC:: 00112 recursive_copy_node(node_const_pointer p_nd) 00113 { 00114 if (p_nd == 0) 00115 return (0); 00116 00117 node_pointer p_ret = s_node_allocator.allocate(1); 00118 00119 __try 00120 { 00121 new (p_ret) node(*p_nd); 00122 } 00123 __catch(...) 00124 { 00125 s_node_allocator.deallocate(p_ret, 1); 00126 __throw_exception_again; 00127 } 00128 00129 p_ret->m_p_l_child = p_ret->m_p_next_sibling = 00130 p_ret->m_p_prev_or_parent = 0; 00131 00132 __try 00133 { 00134 p_ret->m_p_l_child = recursive_copy_node(p_nd->m_p_l_child); 00135 p_ret->m_p_next_sibling = recursive_copy_node(p_nd->m_p_next_sibling); 00136 } 00137 __catch(...) 00138 { 00139 clear_imp(p_ret); 00140 __throw_exception_again; 00141 } 00142 00143 if (p_ret->m_p_l_child != 0) 00144 p_ret->m_p_l_child->m_p_prev_or_parent = p_ret; 00145 00146 if (p_ret->m_p_next_sibling != 0) 00147 p_ret->m_p_next_sibling->m_p_prev_or_parent = 00148 p_nd->m_p_next_sibling->m_p_prev_or_parent == p_nd ? p_ret : 0; 00149 00150 return p_ret; 00151 } 00152