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
00040
00041
00042
00043
00044
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 }
00127
00128 }
00129
00130 #endif // #ifndef PB_DS_COND_DEALTOR_HPP
00131