1171568Sscottl// -*- C++ -*- 2211095Sdes 3171568Sscottl// Copyright (C) 2005, 2006 Free Software Foundation, Inc. 4171568Sscottl// 5171568Sscottl// This file is part of the GNU ISO C++ Library. This library is free 6171568Sscottl// software; you can redistribute it and/or modify it under the terms 7171568Sscottl// of the GNU General Public License as published by the Free Software 8171568Sscottl// Foundation; either version 2, or (at your option) any later 9171568Sscottl// version. 10171568Sscottl 11171568Sscottl// This library is distributed in the hope that it will be useful, but 12171568Sscottl// WITHOUT ANY WARRANTY; without even the implied warranty of 13171568Sscottl// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14171568Sscottl// General Public License for more details. 15171568Sscottl 16171568Sscottl// You should have received a copy of the GNU General Public License 17171568Sscottl// along with this library; see the file COPYING. If not, write to 18171568Sscottl// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, 19171568Sscottl// MA 02111-1307, USA. 20171568Sscottl 21171568Sscottl// As a special exception, you may use this file as part of a free 22171568Sscottl// software library without restriction. Specifically, if other files 23171568Sscottl// instantiate templates or use macros or inline functions from this 24171568Sscottl// file, or you compile this file and link it with other files to 25171568Sscottl// produce an executable, this file does not by itself cause the 26171568Sscottl// resulting executable to be covered by the GNU General Public 27171568Sscottl// License. This exception does not however invalidate any other 28171568Sscottl// reasons why the executable file might be covered by the GNU General 29211095Sdes// Public License. 30171568Sscottl 31171568Sscottl// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 32171568Sscottl 33171568Sscottl// Permission to use, copy, modify, sell, and distribute this software 34171568Sscottl// is hereby granted without fee, provided that the above copyright 35171568Sscottl// notice appears in all copies, and that both that copyright notice 36171568Sscottl// and this permission notice appear in supporting documentation. None 37171568Sscottl// of the above authors, nor IBM Haifa Research Laboratories, make any 38171568Sscottl// representation about the suitability of this software for any 39171568Sscottl// purpose. It is provided "as is" without express or implied 40211095Sdes// warranty. 41171568Sscottl 42171568Sscottl/** 43171568Sscottl * @file constructor_destructor_fn_imps.hpp 44171568Sscottl * Contains implementations of PB_DS_CLASS_NAME. 45171568Sscottl */ 46171568Sscottl 47171568SscottlPB_DS_CLASS_T_DEC 48171568Sscottltypename PB_DS_CLASS_C_DEC::entry_allocator 49171568SscottlPB_DS_CLASS_C_DEC::s_entry_allocator; 50171568Sscottl 51171568SscottlPB_DS_CLASS_T_DEC 52171568SscottlEq_Fn PB_DS_CLASS_C_DEC::s_eq_fn; 53171568Sscottl 54171568SscottlPB_DS_CLASS_T_DEC 55171568Sscottlnull_lu_metadata PB_DS_CLASS_C_DEC::s_null_lu_metadata; 56171568Sscottl 57171568SscottlPB_DS_CLASS_T_DEC 58171568SscottlUpdate_Policy PB_DS_CLASS_C_DEC::s_update_policy; 59171568Sscottl 60171568SscottlPB_DS_CLASS_T_DEC 61171568Sscottltype_to_type< 62171568Sscottl typename PB_DS_CLASS_C_DEC::update_metadata> PB_DS_CLASS_C_DEC::s_metadata_type_indicator; 63171568Sscottl 64171568SscottlPB_DS_CLASS_T_DEC 65171568Sscottltemplate<typename It> 66171568Sscottlvoid 67171568SscottlPB_DS_CLASS_C_DEC:: 68171568Sscottlcopy_from_range(It first_it, It last_it) 69171568Sscottl{ 70171568Sscottl while (first_it != last_it) 71171568Sscottl insert(*(first_it++)); 72171568Sscottl} 73171568Sscottl 74171568SscottlPB_DS_CLASS_T_DEC 75171568SscottlPB_DS_CLASS_C_DEC:: 76171568SscottlPB_DS_CLASS_NAME() : m_p_l(NULL) 77171568Sscottl{ _GLIBCXX_DEBUG_ONLY(assert_valid();) } 78171568Sscottl 79171568SscottlPB_DS_CLASS_T_DEC 80171568Sscottltemplate<typename It> 81171568SscottlPB_DS_CLASS_C_DEC:: 82171568SscottlPB_DS_CLASS_NAME(It first_it, It last_it) : m_p_l(NULL) 83171568Sscottl{ 84171568Sscottl copy_from_range(first_it, last_it); 85171568Sscottl _GLIBCXX_DEBUG_ONLY(assert_valid();); 86171568Sscottl} 87171568Sscottl 88171568SscottlPB_DS_CLASS_T_DEC 89171568SscottlPB_DS_CLASS_C_DEC:: 90171568SscottlPB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC& other) : 91171568Sscottl#ifdef _GLIBCXX_DEBUG 92171568Sscottl map_debug_base(), 93171568Sscottl#endif 94171568Sscottlm_p_l(NULL) 95171568Sscottl{ 96171568Sscottl try 97171568Sscottl { 98171568Sscottl for (const_iterator it = other.begin(); it != other.end(); ++it) 99171568Sscottl { 100171568Sscottl entry_pointer p_l = allocate_new_entry(*it, 101171568Sscottl PB_DS_TYPES_TRAITS_C_DEC::m_no_throw_copies_indicator); 102171568Sscottl 103171568Sscottl p_l->m_p_next = m_p_l; 104171568Sscottl m_p_l = p_l; 105171568Sscottl } 106171568Sscottl } 107171568Sscottl catch(...) 108171568Sscottl { 109171568Sscottl deallocate_all(); 110171568Sscottl __throw_exception_again; 111171568Sscottl } 112171568Sscottl _GLIBCXX_DEBUG_ONLY(assert_valid();) 113171568Sscottl} 114171568Sscottl 115171568SscottlPB_DS_CLASS_T_DEC 116171568Sscottlvoid 117171568SscottlPB_DS_CLASS_C_DEC:: 118171568Sscottlswap(PB_DS_CLASS_C_DEC& other) 119171568Sscottl{ 120171568Sscottl _GLIBCXX_DEBUG_ONLY(assert_valid();) 121171568Sscottl _GLIBCXX_DEBUG_ONLY(other.assert_valid();) 122171568Sscottl _GLIBCXX_DEBUG_ONLY(map_debug_base::swap(other);) 123171568Sscottl std::swap(m_p_l, other.m_p_l); 124171568Sscottl _GLIBCXX_DEBUG_ONLY(assert_valid();) 125171568Sscottl _GLIBCXX_DEBUG_ONLY(other.assert_valid();) 126171568Sscottl} 127171568Sscottl 128171568SscottlPB_DS_CLASS_T_DEC 129171568Sscottlvoid 130171568SscottlPB_DS_CLASS_C_DEC:: 131171568Sscottldeallocate_all() 132171568Sscottl{ 133171568Sscottl entry_pointer p_l = m_p_l; 134171568Sscottl while (p_l != NULL) 135171568Sscottl { 136171568Sscottl entry_pointer p_next_l = p_l->m_p_next; 137171568Sscottl actual_erase_entry(p_l); 138171568Sscottl p_l = p_next_l; 139171568Sscottl } 140171568Sscottl m_p_l = NULL; 141171568Sscottl} 142171568Sscottl 143171568SscottlPB_DS_CLASS_T_DEC 144171568SscottlPB_DS_CLASS_C_DEC:: 145171568Sscottl~PB_DS_CLASS_NAME() 146171568Sscottl{ deallocate_all(); } 147171568Sscottl 148171568Sscottl