00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00045 #ifndef COND_DEALTOR_HPP
00046 #define COND_DEALTOR_HPP
00047
00048 namespace pb_assoc
00049 {
00050
00051 namespace detail
00052 {
00053
00054 #define PB_ASSOC_COND_DEALTOR_CLASS_T_DEC \
00055 template<class Entry, class Allocator>
00056
00057 #define PB_ASSOC_COND_DEALTOR_CLASS_C_DEC \
00058 cond_dealtor< \
00059 Entry, \
00060 Allocator>
00061
00062 template<class Entry, class Allocator>
00063 class cond_dealtor
00064 {
00065 public:
00066 typedef
00067 typename Allocator::template rebind<Entry>::other
00068 entry_allocator;
00069
00070 typedef typename entry_allocator::pointer entry_pointer;
00071
00072 public:
00073 inline
00074 cond_dealtor(entry_pointer p_e);
00075
00076 inline
00077 ~cond_dealtor();
00078
00079 inline void
00080 set_no_action();
00081
00082 private:
00083 entry_pointer m_p_e;
00084
00085 bool m_no_action_destructor;
00086
00087 static entry_allocator s_alloc;
00088 };
00089
00090 PB_ASSOC_COND_DEALTOR_CLASS_T_DEC
00091 typename PB_ASSOC_COND_DEALTOR_CLASS_C_DEC::entry_allocator
00092 PB_ASSOC_COND_DEALTOR_CLASS_C_DEC::s_alloc;
00093
00094 PB_ASSOC_COND_DEALTOR_CLASS_T_DEC
00095 inline
00096 PB_ASSOC_COND_DEALTOR_CLASS_C_DEC::
00097 cond_dealtor(entry_pointer p_e) :
00098 m_p_e(p_e),
00099 m_no_action_destructor(false)
00100 { }
00101
00102 PB_ASSOC_COND_DEALTOR_CLASS_T_DEC
00103 inline void
00104 PB_ASSOC_COND_DEALTOR_CLASS_C_DEC::
00105 set_no_action()
00106 {
00107 m_no_action_destructor = true;
00108 }
00109
00110 PB_ASSOC_COND_DEALTOR_CLASS_T_DEC
00111 inline
00112 PB_ASSOC_COND_DEALTOR_CLASS_C_DEC::
00113 ~cond_dealtor()
00114 {
00115 if (m_no_action_destructor)
00116 return;
00117
00118 s_alloc.deallocate(m_p_e, 1);
00119 }
00120
00121 #undef PB_ASSOC_COND_DEALTOR_CLASS_T_DEC
00122 #undef PB_ASSOC_COND_DEALTOR_CLASS_C_DEC
00123
00124 }
00125
00126 }
00127
00128 #endif // #ifndef COND_DEALTOR_HPP
00129