constructors_destructor_fn_imps.hpp revision 169692
1327952Sdim// -*- C++ -*-
2193323Sed
3193323Sed// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4193323Sed//
5193323Sed// This file is part of the GNU ISO C++ Library.  This library is free
6193323Sed// software; you can redistribute it and/or modify it under the terms
7193323Sed// of the GNU General Public License as published by the Free Software
8193323Sed// Foundation; either version 2, or (at your option) any later
9193323Sed// version.
10193323Sed
11193323Sed// This library is distributed in the hope that it will be useful, but
12193323Sed// WITHOUT ANY WARRANTY; without even the implied warranty of
13193323Sed// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14193323Sed// General Public License for more details.
15249423Sdim
16249423Sdim// You should have received a copy of the GNU General Public License
17193323Sed// along with this library; see the file COPYING.  If not, write to
18193323Sed// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19193323Sed// MA 02111-1307, USA.
20314564Sdim
21249423Sdim// As a special exception, you may use this file as part of a free
22276479Sdim// software library without restriction.  Specifically, if other files
23344779Sdim// instantiate templates or use macros or inline functions from this
24314564Sdim// file, or you compile this file and link it with other files to
25314564Sdim// produce an executable, this file does not by itself cause the
26193323Sed// resulting executable to be covered by the GNU General Public
27193323Sed// License.  This exception does not however invalidate any other
28193323Sed// reasons why the executable file might be covered by the GNU General
29327952Sdim// Public License.
30327952Sdim
31276479Sdim// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32344779Sdim
33327952Sdim// Permission to use, copy, modify, sell, and distribute this software
34327952Sdim// is hereby granted without fee, provided that the above copyright
35288943Sdim// notice appears in all copies, and that both that copyright notice
36243830Sdim// and this permission notice appear in supporting documentation. None
37327952Sdim// of the above authors, nor IBM Haifa Research Laboratories, make any
38344779Sdim// representation about the suitability of this software for any
39218893Sdim// purpose. It is provided "as is" without express or implied
40243830Sdim// warranty.
41327952Sdim
42193323Sed/**
43309124Sdim * @file constructors_destructor_fn_imps.hpp
44344779Sdim * Contains an implementation class for left_child_next_sibling_heap_.
45226633Sdim */
46344779Sdim
47344779SdimPB_DS_CLASS_T_DEC
48344779Sdimtypename PB_DS_CLASS_C_DEC::node_allocator
49344779SdimPB_DS_CLASS_C_DEC::s_node_allocator;
50344779Sdim
51344779SdimPB_DS_CLASS_T_DEC
52344779Sdimtypename PB_DS_CLASS_C_DEC::no_throw_copies_t
53309124SdimPB_DS_CLASS_C_DEC::s_no_throw_copies_ind;
54309124Sdim
55309124SdimPB_DS_CLASS_T_DEC
56309124SdimPB_DS_CLASS_C_DEC::
57296417Sdimleft_child_next_sibling_heap_() :
58309124Sdim  m_p_root(NULL),
59193323Sed  m_size(0)
60309124Sdim{
61309124Sdim  _GLIBCXX_DEBUG_ONLY(assert_valid();)
62309124Sdim}
63309124Sdim
64276479SdimPB_DS_CLASS_T_DEC
65193323SedPB_DS_CLASS_C_DEC::
66309124Sdimleft_child_next_sibling_heap_(const Cmp_Fn& r_cmp_fn) :
67309124Sdim  Cmp_Fn(r_cmp_fn),
68344779Sdim  m_p_root(NULL),
69288943Sdim  m_size(0)
70344779Sdim{
71344779Sdim  _GLIBCXX_DEBUG_ONLY(assert_valid();)
72193323Sed}
73309124Sdim
74309124SdimPB_DS_CLASS_T_DEC
75193323SedPB_DS_CLASS_C_DEC::
76193323Sedleft_child_next_sibling_heap_(const PB_DS_CLASS_C_DEC& other)
77193323Sed: Cmp_Fn(other), m_p_root(NULL), m_size(0)
78309124Sdim{
79309124Sdim  m_size = other.m_size;
80309124Sdim  _GLIBCXX_DEBUG_ONLY(other.assert_valid();)
81309124Sdim  m_p_root = recursive_copy_node(other.m_p_root);
82193323Sed  m_size = other.m_size;
83193323Sed  _GLIBCXX_DEBUG_ONLY(assert_valid();)
84193323Sed}
85309124Sdim
86309124SdimPB_DS_CLASS_T_DEC
87193323Sedvoid
88193323SedPB_DS_CLASS_C_DEC::
89309124Sdimswap(PB_DS_CLASS_C_DEC& other)
90288943Sdim{
91288943Sdim  _GLIBCXX_DEBUG_ONLY(assert_valid();)
92288943Sdim  _GLIBCXX_DEBUG_ONLY(other.assert_valid();)
93288943Sdim  value_swap(other);
94288943Sdim  std::swap((Cmp_Fn& )(*this), (Cmp_Fn& )other);
95288943Sdim  _GLIBCXX_DEBUG_ONLY(assert_valid();)
96344779Sdim  _GLIBCXX_DEBUG_ONLY(other.assert_valid();)
97321369Sdim}
98321369Sdim
99321369SdimPB_DS_CLASS_T_DEC
100288943Sdimvoid
101296417SdimPB_DS_CLASS_C_DEC::
102344779Sdimvalue_swap(PB_DS_CLASS_C_DEC& other)
103344779Sdim{
104344779Sdim  std::swap(m_p_root, other.m_p_root);
105288943Sdim  std::swap(m_size, other.m_size);
106288943Sdim}
107288943Sdim
108288943SdimPB_DS_CLASS_T_DEC
109288943SdimPB_DS_CLASS_C_DEC::
110288943Sdim~left_child_next_sibling_heap_()
111288943Sdim{
112288943Sdim  clear();
113288943Sdim}
114288943Sdim
115288943SdimPB_DS_CLASS_T_DEC
116288943Sdimtypename PB_DS_CLASS_C_DEC::node_pointer
117288943SdimPB_DS_CLASS_C_DEC::
118288943Sdimrecursive_copy_node(const_node_pointer p_nd)
119288943Sdim{
120288943Sdim  if (p_nd == NULL)
121288943Sdim    return (NULL);
122309124Sdim
123309124Sdim  node_pointer p_ret = s_node_allocator.allocate(1);
124309124Sdim
125193323Sed  try
126288943Sdim    {
127288943Sdim      new (p_ret) node(*p_nd);
128288943Sdim    }
129288943Sdim  catch(...)
130288943Sdim    {
131288943Sdim      s_node_allocator.deallocate(p_ret, 1);
132288943Sdim      __throw_exception_again;
133193323Sed    }
134198892Srdivacky
135198892Srdivacky  p_ret->m_p_l_child = p_ret->m_p_next_sibling =
136198892Srdivacky    p_ret->m_p_prev_or_parent = NULL;
137198892Srdivacky
138344779Sdim  try
139288943Sdim    {
140288943Sdim      p_ret->m_p_l_child = recursive_copy_node(p_nd->m_p_l_child);
141193323Sed      p_ret->m_p_next_sibling = recursive_copy_node(p_nd->m_p_next_sibling);
142288943Sdim    }
143288943Sdim  catch(...)
144288943Sdim    {
145288943Sdim      clear_imp(p_ret);
146288943Sdim      __throw_exception_again;
147288943Sdim    }
148193323Sed
149193323Sed  if (p_ret->m_p_l_child != NULL)
150309124Sdim    p_ret->m_p_l_child->m_p_prev_or_parent = p_ret;
151309124Sdim
152309124Sdim  if (p_ret->m_p_next_sibling != NULL)
153309124Sdim    p_ret->m_p_next_sibling->m_p_prev_or_parent =
154276479Sdim      p_nd->m_p_next_sibling->m_p_prev_or_parent == p_nd ? p_ret : NULL;
155288943Sdim
156288943Sdim  return p_ret;
157193323Sed}
158344779Sdim
159193323Sed