split_join_branch_bag.hpp revision 225736
1122715Sbde// -*- C++ -*- 2122715Sbde 3122715Sbde// Copyright (C) 2005, 2006 Free Software Foundation, Inc. 4122715Sbde// 5122715Sbde// This file is part of the GNU ISO C++ Library. This library is free 685909Simp// software; you can redistribute it and/or modify it under the terms 788893Simp// of the GNU General Public License as published by the Free Software 888893Simp// Foundation; either version 2, or (at your option) any later 988969Simp// version. 1085909Simp 11115572Sphk// This library is distributed in the hope that it will be useful, but 12115572Sphk// WITHOUT ANY WARRANTY; without even the implied warranty of 13115572Sphk// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14115572Sphk// General Public License for more details. 15124108Simp 16115572Sphk// You should have received a copy of the GNU General Public License 17111211Sru// along with this library; see the file COPYING. If not, write to 1885909Simp// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, 19111802Sru// MA 02111-1307, USA. 20111802Sru 21111211Sru// As a special exception, you may use this file as part of a free 22111211Sru// software library without restriction. Specifically, if other files 23111211Sru// instantiate templates or use macros or inline functions from this 24111211Sru// file, or you compile this file and link it with other files to 25111802Sru// produce an executable, this file does not by itself cause the 26111802Sru// resulting executable to be covered by the GNU General Public 27111211Sru// License. This exception does not however invalidate any other 28111211Sru// reasons why the executable file might be covered by the GNU General 2985909Simp// Public License. 30137596Simp 31137596Simp// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 32142424Simp 33142424Simp// Permission to use, copy, modify, sell, and distribute this software 34142424Simp// is hereby granted without fee, provided that the above copyright 35142424Simp// notice appears in all copies, and that both that copyright notice 36142424Simp// and this permission notice appear in supporting documentation. None 37137596Simp// of the above authors, nor IBM Haifa Research Laboratories, make any 38142413Simp// representation about the suitability of this software for any 39142424Simp// purpose. It is provided "as is" without express or implied 40142413Simp// warranty. 41137596Simp 42142424Simp/** 43137596Simp * @file split_join_branch_bag.hpp 44137596Simp * Contains an implementation class for pat_trie_. 45137596Simp */ 46137596Simp 47111211Sruclass split_join_branch_bag 48111211Sru{ 49111211Sruprivate: 50111211Sru typedef 51111802Sru std::list< 52111802Sru internal_node_pointer, 53111802Sru typename Allocator::template rebind< 54111766Sru internal_node_pointer>::other> 55111211Sru bag_t; 56111766Sru 57111766Srupublic: 58111211Sru 59111211Sru void 60111211Sru add_branch() 61111211Sru { 62111211Sru internal_node_pointer p_nd = s_internal_node_allocator.allocate(1); 63111211Sru try 64111211Sru { 65111211Sru m_bag.push_back(p_nd); 6685909Simp } 6785909Simp catch(...) 6885909Simp { 6985909Simp s_internal_node_allocator.deallocate(p_nd, 1); 7085909Simp __throw_exception_again; 7185909Simp } 72116252Sgrog } 7395356Sru 74116252Sgrog internal_node_pointer 75123965Sbde get_branch() 76116252Sgrog { 77123965Sbde _GLIBCXX_DEBUG_ASSERT(!m_bag.empty()); 78123965Sbde internal_node_pointer p_nd =* m_bag.begin(); 79135611Sphk m_bag.pop_front(); 80124776Sru return p_nd; 81116252Sgrog } 82123965Sbde 8385909Simp ~split_join_branch_bag() 84124776Sru { 8585909Simp while (!m_bag.empty()) 8685909Simp { 8785909Simp internal_node_pointer p_nd =* m_bag.begin(); 8885909Simp s_internal_node_allocator.deallocate(p_nd, 1); 8985909Simp m_bag.pop_front(); 90125775Sru } 91125775Sru } 92125775Sru 9385909Simp inline bool 9485909Simp empty() const 95116691Sru { return m_bag.empty(); } 96131129Simp 9785909Simpprivate: 9885909Simp bag_t m_bag; 99116341Smarkm}; 100116341Smarkm