cond_dealtor.hpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the terms
00007 // of the GNU General Public License as published by the Free Software
00008 // Foundation; either version 2, or (at your option) any later
00009 // version.
00010 
00011 // This library is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License
00017 // along with this library; see the file COPYING.  If not, write to
00018 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00019 // MA 02111-1307, USA.
00020 
00021 // As a special exception, you may use this file as part of a free
00022 // software library without restriction.  Specifically, if other files
00023 // instantiate templates or use macros or inline functions from this
00024 // file, or you compile this file and link it with other files to
00025 // produce an executable, this file does not by itself cause the
00026 // resulting executable to be covered by the GNU General Public
00027 // License.  This exception does not however invalidate any other
00028 // reasons why the executable file might be covered by the GNU General
00029 // Public License.
00030 
00031 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
00032 
00033 // Permission to use, copy, modify, sell, and distribute this software
00034 // is hereby granted without fee, provided that the above copyright
00035 // notice appears in all copies, and that both that copyright notice
00036 // and this permission notice appear in supporting documentation. None
00037 // of the above authors, nor IBM Haifa Research Laboratories, make any
00038 // representation about the suitability of this software for any
00039 // purpose. It is provided "as is" without express or implied
00040 // warranty.
00041 
00042 /**
00043  * @file cond_dealtor.hpp
00044  * Contains a conditional deallocator.
00045  */
00046 
00047 #ifndef PB_DS_COND_DEALTOR_HPP
00048 #define PB_DS_COND_DEALTOR_HPP
00049 
00050 namespace pb_ds
00051 {
00052 
00053   namespace detail
00054   {
00055 
00056 #define PB_DS_COND_DEALTOR_CLASS_T_DEC      \
00057     template<typename Entry, class Allocator>
00058 
00059 #define PB_DS_COND_DEALTOR_CLASS_C_DEC              \
00060     cond_dealtor<                       \
00061                         Entry,      \
00062                         Allocator>
00063 
00064     template<typename Entry, class Allocator>
00065     class cond_dealtor
00066     {
00067     public:
00068       typedef
00069       typename Allocator::template rebind<Entry>::other
00070       entry_allocator;
00071 
00072       typedef typename entry_allocator::pointer entry_pointer;
00073 
00074     public:
00075       inline
00076       cond_dealtor(entry_pointer p_e);
00077 
00078       inline
00079       ~cond_dealtor();
00080 
00081       inline void
00082       set_no_action();
00083 
00084     private:
00085       entry_pointer m_p_e;
00086 
00087       bool m_no_action_destructor;
00088 
00089       static entry_allocator s_alloc;
00090     };
00091 
00092     PB_DS_COND_DEALTOR_CLASS_T_DEC
00093     typename PB_DS_COND_DEALTOR_CLASS_C_DEC::entry_allocator
00094     PB_DS_COND_DEALTOR_CLASS_C_DEC::s_alloc;
00095 
00096     PB_DS_COND_DEALTOR_CLASS_T_DEC
00097     inline
00098     PB_DS_COND_DEALTOR_CLASS_C_DEC::
00099     cond_dealtor(entry_pointer p_e) :
00100       m_p_e(p_e),
00101       m_no_action_destructor(false)
00102     { }
00103 
00104     PB_DS_COND_DEALTOR_CLASS_T_DEC
00105     inline void
00106     PB_DS_COND_DEALTOR_CLASS_C_DEC::
00107     set_no_action()
00108     {
00109       m_no_action_destructor = true;
00110     }
00111 
00112     PB_DS_COND_DEALTOR_CLASS_T_DEC
00113     inline
00114     PB_DS_COND_DEALTOR_CLASS_C_DEC::
00115     ~cond_dealtor()
00116     {
00117       if (m_no_action_destructor)
00118         return;
00119 
00120       s_alloc.deallocate(m_p_e, 1);
00121     }
00122 
00123 #undef PB_DS_COND_DEALTOR_CLASS_T_DEC
00124 #undef PB_DS_COND_DEALTOR_CLASS_C_DEC
00125 
00126   } // namespace detail
00127 
00128 } // namespace pb_ds
00129 
00130 #endif // #ifndef PB_DS_COND_DEALTOR_HPP
00131 

Generated on Thu Nov 1 13:11:23 2007 for libstdc++ by  doxygen 1.5.1