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