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 MAP_DEBUG_BASE_HPP
00046 #define MAP_DEBUG_BASE_HPP
00047
00048 #ifdef PB_ASSOC_USE_MAP_DEBUG_BASE
00049
00050 #include <assert.h>
00051 #include <utility>
00052 #include <set>
00053 #include <pb_assoc/testsuite/regression/res_mng/dbg_ex_allocator_base.hpp>
00054
00055 namespace pb_assoc
00056 {
00057
00058 namespace detail
00059 {
00060
00061 #ifdef PB_ASSOC_MAP_DEBUG_BASE_DEBUG
00062 #define PB_ASSOC_DBG_ASSERT(X) assert(X)
00063 #define PB_ASSOC_DBG_VERIFY(X) assert(X)
00064 #define PB_ASSOC_DBG_ONLY(X) X
00065 #else // #ifdef PB_ASSOC_MAP_DEBUG_BASE_DEBUG
00066 #define PB_ASSOC_DBG_ASSERT(X)
00067 #define PB_ASSOC_DBG_VERIFY(X) {if((X)==0);}
00068 #define PB_ASSOC_DBG_ONLY(X) ;
00069 #endif // #ifdef PB_ASSOC_MAP_DEBUG_BASE_DEBUG
00070
00071 #define PB_ASSOC_CLASS_T_DEC \
00072 template<typename Key, class Eq_Fn>
00073
00074 #define PB_ASSOC_CLASS_C_DEC \
00075 map_debug_base< \
00076 Key, \
00077 Eq_Fn>
00078
00079 template<typename Key, class Eq_Fn>
00080 class map_debug_base
00081 {
00082 private:
00083 typedef typename std::allocator<Key> key_allocator;
00084
00085 typedef typename key_allocator::size_type size_type;
00086
00087 typedef typename key_allocator::const_reference const_key_reference;
00088
00089 protected:
00090 map_debug_base();
00091
00092 map_debug_base(const PB_ASSOC_CLASS_C_DEC& r_other);
00093
00094 ~map_debug_base();
00095
00096 inline void
00097 insert_new(const_key_reference r_key);
00098
00099 inline void
00100 insert_existing(const_key_reference r_key);
00101
00102 inline void
00103 erase_existing(const_key_reference r_key);
00104
00105 void
00106 clear();
00107
00108 inline void
00109 check_key_exists(const_key_reference r_key) const;
00110
00111 inline void
00112 check_key_does_not_exist(const_key_reference r_key) const;
00113
00114 inline void
00115 check_size(size_type size) const;
00116
00117 void
00118 swap(PB_ASSOC_CLASS_C_DEC& r_other);
00119
00120 private:
00121 typedef std::set<Key> key_set;
00122
00123 private:
00124 key_set m_key_set;
00125 };
00126
00127 PB_ASSOC_CLASS_T_DEC
00128 PB_ASSOC_CLASS_C_DEC::
00129 map_debug_base()
00130 {
00131
00132 }
00133
00134 PB_ASSOC_CLASS_T_DEC
00135 PB_ASSOC_CLASS_C_DEC::
00136 map_debug_base(const PB_ASSOC_CLASS_C_DEC& r_other) :
00137 m_key_set(r_other.m_key_set)
00138 { }
00139
00140 PB_ASSOC_CLASS_T_DEC
00141 PB_ASSOC_CLASS_C_DEC::
00142 ~map_debug_base()
00143 { }
00144
00145 PB_ASSOC_CLASS_T_DEC
00146 inline void
00147 PB_ASSOC_CLASS_C_DEC::
00148 insert_new(const_key_reference r_key)
00149 {
00150 const double orig_throw_prob =
00151 pb_assoc::detail::test::dbg_ex_allocator_base().get_throw_prob();
00152
00153 pb_assoc::detail::test::dbg_ex_allocator_base().
00154 set_throw_prob(0);
00155
00156 if (m_key_set.find(r_key) != m_key_set.end())
00157 abort();
00158
00159 try
00160 {
00161 m_key_set.insert(r_key);
00162 }
00163 catch(...)
00164 {
00165 pb_assoc::detail::test::dbg_ex_allocator_base().
00166 set_throw_prob(orig_throw_prob);
00167
00168 throw;
00169 }
00170
00171 pb_assoc::detail::test::dbg_ex_allocator_base().
00172 set_throw_prob(orig_throw_prob);
00173 }
00174
00175 PB_ASSOC_CLASS_T_DEC
00176 inline void
00177 PB_ASSOC_CLASS_C_DEC::
00178 erase_existing(const_key_reference r_key)
00179 {
00180 if (m_key_set.find(r_key) == m_key_set.end())
00181 abort();
00182
00183 m_key_set.erase(r_key);
00184
00185 if (m_key_set.find(r_key) != m_key_set.end())
00186 abort();
00187 }
00188
00189 PB_ASSOC_CLASS_T_DEC
00190 void
00191 PB_ASSOC_CLASS_C_DEC::
00192 clear()
00193 {
00194 m_key_set.clear();
00195 }
00196
00197 PB_ASSOC_CLASS_T_DEC
00198 inline void
00199 PB_ASSOC_CLASS_C_DEC::
00200 check_key_exists(const_key_reference r_key) const
00201 {
00202 if (m_key_set.find(r_key) == m_key_set.end())
00203 abort();
00204 }
00205
00206 PB_ASSOC_CLASS_T_DEC
00207 inline void
00208 PB_ASSOC_CLASS_C_DEC::
00209 check_key_does_not_exist(const_key_reference r_key) const
00210 {
00211 if (m_key_set.find(r_key) != m_key_set.end())
00212 abort();
00213 }
00214
00215 PB_ASSOC_CLASS_T_DEC
00216 inline void
00217 PB_ASSOC_CLASS_C_DEC::
00218 check_size(size_type size) const
00219 {
00220 const size_type key_set_size = m_key_set.size();
00221
00222 if (size != key_set_size)
00223 abort();
00224 }
00225
00226 PB_ASSOC_CLASS_T_DEC
00227 void
00228 PB_ASSOC_CLASS_C_DEC::
00229 swap(PB_ASSOC_CLASS_C_DEC& r_other)
00230 {
00231 m_key_set.swap(r_other.m_key_set);
00232 }
00233
00234 #undef PB_ASSOC_CLASS_T_DEC
00235 #undef PB_ASSOC_CLASS_C_DEC
00236
00237 #undef PB_ASSOC_DBG_ASSERT
00238 #undef PB_ASSOC_DBG_VERIFY
00239 #undef PB_ASSOC_DBG_ONLY
00240
00241 }
00242
00243 }
00244
00245 #endif // #ifdef PB_ASSOC_USE_MAP_DEBUG_BASE
00246
00247 #endif // #ifndef MAP_DEBUG_BASE_HPP
00248