1e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// -*- C++ -*- 2e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh 3e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// Copyright (C) 2005, 2006, 2009, 2011 Free Software Foundation, Inc. 4e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// 5e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// This file is part of the GNU ISO C++ Library. This library is free 6e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// software; you can redistribute it and/or modify it under the terms 7e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// of the GNU General Public License as published by the Free Software 8e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// Foundation; either version 3, or (at your option) any later 9e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// version. 10e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh 11e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// This library is distributed in the hope that it will be useful, but 12e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// WITHOUT ANY WARRANTY; without even the implied warranty of 13e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// General Public License for more details. 15e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh 16e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// Under Section 7 of GPL version 3, you are granted additional 17e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// permissions described in the GCC Runtime Library Exception, version 18e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// 3.1, as published by the Free Software Foundation. 19e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh 20e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// You should have received a copy of the GNU General Public License and 21e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// a copy of the GCC Runtime Library Exception along with this program; 22e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// <http://www.gnu.org/licenses/>. 24e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh 25e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 26e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh 27e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// Permission to use, copy, modify, sell, and distribute this software 28e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// is hereby granted without fee, provided that the above copyright 29e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// notice appears in all copies, and that both that copyright notice 30e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// and this permission notice appear in supporting documentation. None 31e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// of the above authors, nor IBM Haifa Research Laboratories, make any 32e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// representation about the suitability of this software for any 33e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// purpose. It is provided "as is" without express or implied 34e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh// warranty. 35e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh 36e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh/** 37e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * @file cc_hash_table_map_/cond_key_dtor_entry_dealtor.hpp 38e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh * Contains a conditional key destructor, used for exception handling. 39e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh */ 40e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh 41e7de7d971409d955ca138406d5062499bc554451Andrew Hsiehnamespace __gnu_pbds 42e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh{ 43e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh namespace detail 44e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh { 45e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh /// Conditional dey destructor, cc_hash. 46e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh template<typename HT_Map> 47e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh class cond_dealtor 48e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh { 49e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh public: 50e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh typedef typename HT_Map::entry entry; 51e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh typedef typename HT_Map::entry_allocator entry_allocator; 52e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh typedef typename HT_Map::key_type key_type; 53e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh 54e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh cond_dealtor(entry_allocator* p_a, entry* p_e) 55e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh : m_p_a(p_a), m_p_e(p_e), m_key_destruct(false), 56e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh m_no_action_destructor(false) 57e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh { } 58e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh 59e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh inline 60e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh ~cond_dealtor(); 61e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh 62e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh void 63e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh set_key_destruct() 64e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh { m_key_destruct = true; } 65e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh 66e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh void 67e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh set_no_action_destructor() 68e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh { m_no_action_destructor = true; } 69e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh 70e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh protected: 71e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh entry_allocator* const m_p_a; 72e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh entry* const m_p_e; 73e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh 74e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh bool m_key_destruct; 75e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh bool m_no_action_destructor; 76e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh }; 77e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh 78e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh template<typename HT_Map> 79e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh inline 80e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh cond_dealtor<HT_Map>:: 81e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh ~cond_dealtor() 82e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh { 83e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh if (m_no_action_destructor) 84e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh return; 85e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh if (m_key_destruct) 86e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh m_p_e->m_value.first.~key_type(); 87e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh m_p_a->deallocate(m_p_e, 1); 88e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh } 89e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh } // namespace detail 90e7de7d971409d955ca138406d5062499bc554451Andrew Hsieh} // namespace __gnu_pbds 91