cond_dtor.hpp revision 169691
1110933Sseanc// -*- C++ -*- 2110933Sseanc 3110933Sseanc// Copyright (C) 2005, 2006 Free Software Foundation, Inc. 4110933Sseanc// 5110933Sseanc// This file is part of the GNU ISO C++ Library. This library is free 6110933Sseanc// software; you can redistribute it and/or modify it under the terms 7110933Sseanc// of the GNU General Public License as published by the Free Software 8110933Sseanc// Foundation; either version 2, or (at your option) any later 9110933Sseanc// version. 10110933Sseanc 11110933Sseanc// This library is distributed in the hope that it will be useful, but 12110933Sseanc// WITHOUT ANY WARRANTY; without even the implied warranty of 13110933Sseanc// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14110933Sseanc// General Public License for more details. 15110933Sseanc 16110933Sseanc// You should have received a copy of the GNU General Public License 17110933Sseanc// along with this library; see the file COPYING. If not, write to 18110933Sseanc// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, 19110933Sseanc// MA 02111-1307, USA. 20110933Sseanc 21110933Sseanc// As a special exception, you may use this file as part of a free 22110933Sseanc// software library without restriction. Specifically, if other files 23110933Sseanc// instantiate templates or use macros or inline functions from this 24110933Sseanc// file, or you compile this file and link it with other files to 25110933Sseanc// produce an executable, this file does not by itself cause the 26110933Sseanc// resulting executable to be covered by the GNU General Public 27110933Sseanc// License. This exception does not however invalidate any other 28110933Sseanc// reasons why the executable file might be covered by the GNU General 29110933Sseanc// Public License. 30110933Sseanc 31110933Sseanc// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 32110933Sseanc 33110933Sseanc// Permission to use, copy, modify, sell, and distribute this software 34110933Sseanc// is hereby granted without fee, provided that the above copyright 35110933Sseanc// notice appears in all copies, and that both that copyright notice 36110933Sseanc// and this permission notice appear in supporting documentation. None 37110933Sseanc// of the above authors, nor IBM Haifa Research Laboratories, make any 38110933Sseanc// representation about the suitability of this software for any 39110933Sseanc// purpose. It is provided "as is" without express or implied 40120919Sgrog// warranty. 41110933Sseanc 42110933Sseanc/** 43110933Sseanc * @file cond_dtor.hpp 44110933Sseanc * Contains a conditional destructor 45110933Sseanc */ 46110933Sseanc 47110933Sseanctemplate<typename Size_Type> 48110933Sseancclass cond_dtor 49{ 50public: 51 cond_dtor(value_vector a_vec, iterator& r_last_it, Size_Type total_size) 52 : m_a_vec(a_vec), m_r_last_it(r_last_it), m_max_size(total_size), 53 m_no_action(false) 54 { } 55 56 ~cond_dtor() 57 { 58 if (m_no_action) 59 return; 60 iterator it = m_a_vec; 61 while (it != m_r_last_it) 62 { 63 it->~value_type(); 64 ++it; 65 } 66 67 if (m_max_size > 0) 68 value_allocator().deallocate(m_a_vec, m_max_size); 69 } 70 71 inline void 72 set_no_action() 73 { m_no_action = true; } 74 75protected: 76 value_vector m_a_vec; 77 iterator& m_r_last_it; 78 const Size_Type m_max_size; 79 bool m_no_action; 80}; 81