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 #ifndef _STLP_INTERNAL_DBG_TREE_H
00031 #define _STLP_INTERNAL_DBG_TREE_H
00032
00033 #include <stl/debug/_iterator.h>
00034 #include <stl/_function.h>
00035 #include <stl/_alloc.h>
00036
00037 # undef _DBG_Rb_tree
00038 # define _DBG_Rb_tree _Rb_tree
00039
00040 # define _STLP_DBG_TREE_SUPER __WORKAROUND_DBG_RENAME(Rb_tree) <_Key, _Value, _KeyOfValue, _Compare, _Alloc>
00041
00042 _STLP_BEGIN_NAMESPACE
00043
00044 # ifdef _STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS
00045 template <class _Key, class _Value, class _KeyOfValue, class _Compare, class _Alloc >
00046 inline _Value*
00047 value_type(const _DBG_iter_base< _STLP_DBG_TREE_SUPER >&) {
00048 return (_Value*)0;
00049 }
00050 template <class _Key, class _Value, class _KeyOfValue, class _Compare, class _Alloc >
00051 inline bidirectional_iterator_tag
00052 iterator_category(const _DBG_iter_base< _STLP_DBG_TREE_SUPER >&) {
00053 return bidirectional_iterator_tag();
00054 }
00055 # endif
00056
00057 template <class _Key, class _Value, class _KeyOfValue, class _Compare,
00058 _STLP_DBG_ALLOCATOR_SELECT(_Value) >
00059 class _DBG_Rb_tree : public _STLP_DBG_TREE_SUPER {
00060 typedef _STLP_DBG_TREE_SUPER _Base;
00061 typedef _DBG_Rb_tree<_Key, _Value, _KeyOfValue, _Compare, _Alloc> _Self;
00062 protected:
00063 friend class __owned_link;
00064 mutable __owned_list _M_iter_list;
00065 public:
00066 void _Invalidate_all() {_M_iter_list._Invalidate_all();}
00067
00068 public:
00069 __IMPORT_CONTAINER_TYPEDEFS(_Base)
00070 typedef typename _Base::key_type key_type;
00071
00072 typedef _DBG_iter<_Base, _Nonconst_traits<value_type> > iterator;
00073 typedef _DBG_iter<_Base, _Const_traits<value_type> > const_iterator;
00074
00075 _STLP_DECLARE_BIDIRECTIONAL_REVERSE_ITERATORS;
00076
00077 public:
00078 const _Base* _Get_base() const { return (const _Base*)this; }
00079 _Base* _Get_base() { return (_Base*)this; }
00080
00081 _DBG_Rb_tree() : _STLP_DBG_TREE_SUPER(),
00082 _M_iter_list(_Get_base()) {}
00083 _DBG_Rb_tree(const _Compare& __comp) :
00084 _STLP_DBG_TREE_SUPER(__comp), _M_iter_list(_Get_base()) {}
00085 _DBG_Rb_tree(const _Compare& __comp, const allocator_type& __a):
00086 _STLP_DBG_TREE_SUPER(__comp, __a), _M_iter_list(_Get_base()) {}
00087 _DBG_Rb_tree(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x):
00088 _STLP_DBG_TREE_SUPER(__x), _M_iter_list(_Get_base()) {}
00089 ~_DBG_Rb_tree() { _Invalidate_all(); }
00090
00091 _Self& operator=(const _Self& __x) {
00092 _Invalidate_all();
00093 (_Base&)*this = (const _Base&)__x;
00094 return *this;
00095 }
00096
00097 iterator begin() { return iterator(&_M_iter_list,_Base::begin()); }
00098 const_iterator begin() const { return const_iterator(&_M_iter_list, _Base::begin()); }
00099 iterator end() { return iterator(&_M_iter_list, _Base::end()); }
00100 const_iterator end() const { return const_iterator(&_M_iter_list,_Base::end()); }
00101 void _Invalidate_iterator(const iterator& __it) {
00102 __invalidate_iterator(&_M_iter_list,__it);
00103 }
00104 reverse_iterator rbegin() { return reverse_iterator(end()); }
00105 const_reverse_iterator rbegin() const {
00106 return const_reverse_iterator(end());
00107 }
00108 reverse_iterator rend() { return reverse_iterator(begin()); }
00109 const_reverse_iterator rend() const {
00110 return const_reverse_iterator(begin());
00111 }
00112 void swap(_Self& __t) {
00113 _Base::swap(__t);
00114 _M_iter_list._Swap_owners(__t._M_iter_list);
00115 }
00116
00117 public:
00118
00119 iterator find(const key_type& __x) {
00120 return iterator(&_M_iter_list, _Base::find(__x));
00121 }
00122 const_iterator find(const key_type& __x) const {
00123 return const_iterator(&_M_iter_list, _Base::find(__x));
00124 }
00125
00126 iterator lower_bound(const key_type& __x) {
00127 return iterator(&_M_iter_list, _Base::lower_bound(__x));
00128 }
00129 const_iterator lower_bound(const key_type& __x) const {
00130 return const_iterator(&_M_iter_list, _Base::lower_bound(__x));
00131 }
00132
00133 iterator upper_bound(const key_type& __x) {
00134 return iterator(&_M_iter_list, _Base::upper_bound(__x));
00135 }
00136 const_iterator upper_bound(const key_type& __x) const {
00137 return const_iterator(&_M_iter_list, _Base::upper_bound(__x));
00138 }
00139
00140 pair<iterator,iterator> equal_range(const key_type& __x) {
00141 return pair<iterator, iterator>(iterator(&_M_iter_list, _Base::lower_bound(__x)),
00142 iterator(&_M_iter_list, _Base::upper_bound(__x)));
00143 }
00144 pair<const_iterator, const_iterator> equal_range(const key_type& __x) const {
00145 return pair<const_iterator,const_iterator>(const_iterator(&_M_iter_list, _Base::lower_bound(__x)),
00146 const_iterator(&_M_iter_list, _Base::upper_bound(__x)));
00147 }
00148
00149 pair<iterator,bool> insert_unique(const value_type& __x) {
00150 # ifndef _STLP_MSVC
00151 _STLP_STD::pair<typename _Base::iterator, bool>
00152 # else
00153
00154 _STLP_STD::pair<_Base::iterator, bool>
00155 # endif
00156 __res = _Base::insert_unique(__x);
00157 return pair<iterator,bool>( iterator(&_M_iter_list, __res.first), __res.second ) ;
00158 }
00159 iterator insert_equal(const value_type& __x) {
00160 return iterator(&_M_iter_list, _Base::insert_equal(__x));
00161 }
00162
00163 iterator insert_unique(iterator __position, const value_type& __x) {
00164 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position))
00165 return iterator(&_M_iter_list, _Base::insert_unique(__position._M_iterator, __x));
00166 }
00167 iterator insert_equal(iterator __position, const value_type& __x) {
00168 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position))
00169 return iterator(&_M_iter_list, _Base::insert_equal(__position._M_iterator, __x));
00170 }
00171
00172 #ifdef _STLP_MEMBER_TEMPLATES
00173 template<class _II>
00174 void insert_equal(_II __first, _II __last) {
00175 _Base::insert_equal(__first, __last);
00176 }
00177 template<class _II>
00178 void insert_unique(_II __first, _II __last) {
00179 _Base::insert_unique(__first, __last);
00180 }
00181 #else
00182 void insert_unique(const_iterator __first, const_iterator __last) {
00183 _Base::insert_unique(__first._M_iterator, __last._M_iterator);
00184 }
00185 void insert_unique(const value_type* __first, const value_type* __last) {
00186 _Base::insert_unique(__first, __last);
00187 }
00188 void insert_equal(const_iterator __first, const_iterator __last) {
00189 _Base::insert_equal(__first._M_iterator, __last._M_iterator);
00190 }
00191 void insert_equal(const value_type* __first, const value_type* __last) {
00192 _Base::insert_equal(__first, __last);
00193 }
00194 #endif
00195
00196 void erase(iterator __position) {
00197 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position))
00198 _STLP_DEBUG_CHECK(_Dereferenceable(__position))
00199 _Invalidate_iterator(__position);
00200 _Base::erase(__position._M_iterator);
00201 }
00202 size_type erase(const key_type& __x) {
00203 return _Base::erase(__x);
00204 }
00205
00206 void erase(iterator __first, iterator __last) {
00207 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __first)&&
00208 __check_if_owner(&_M_iter_list, __last))
00209 _Base::erase(__first._M_iterator, __last._M_iterator);
00210 }
00211 void erase(const key_type* __first, const key_type* __last) {
00212 _Base::erase(__first, __last);
00213 }
00214
00215 void clear() {
00216 _Invalidate_all();
00217 _Base::clear();
00218 }
00219 };
00220
00221 #ifdef _STLP_EXTRA_OPERATORS_FOR_DEBUG
00222
00223 template <class _Key, class _Value, class _KeyOfValue,
00224 class _Compare, class _Alloc>
00225 inline bool
00226 operator==(const _DBG_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
00227 const _DBG_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y)
00228 {
00229 return __x.size() == __y.size() &&
00230 equal(__x.begin(), __x.end(), __y.begin());
00231 }
00232
00233 template <class _Key, class _Value, class _KeyOfValue,
00234 class _Compare, class _Alloc>
00235 inline bool
00236 operator<(const _DBG_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
00237 const _DBG_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y)
00238 {
00239 return lexicographical_compare(__x.begin(), __x.end(),
00240 __y.begin(), __y.end());
00241 }
00242
00243 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
00244
00245 template <class _Key, class _Value, class _KeyOfValue,
00246 class _Compare, class _Alloc>
00247 inline bool
00248 operator!=(const _DBG_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
00249 const _DBG_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y) {
00250 return !(__x == __y);
00251 }
00252
00253 template <class _Key, class _Value, class _KeyOfValue,
00254 class _Compare, class _Alloc>
00255 inline bool
00256 operator>(const _DBG_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
00257 const _DBG_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y) {
00258 return __y < __x;
00259 }
00260
00261 template <class _Key, class _Value, class _KeyOfValue,
00262 class _Compare, class _Alloc>
00263 inline bool
00264 operator<=(const _DBG_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
00265 const _DBG_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y) {
00266 return !(__y < __x);
00267 }
00268
00269 template <class _Key, class _Value, class _KeyOfValue,
00270 class _Compare, class _Alloc>
00271 inline bool
00272 operator>=(const _DBG_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
00273 const _DBG_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y) {
00274 return !(__x < __y);
00275 }
00276
00277 #endif
00278 #endif
00279
00280
00281 #ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
00282 template <class _Key, class _Value, class _KeyOfValue,
00283 class _Compare, class _Alloc>
00284 inline void
00285 swap( _DBG_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
00286 _DBG_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y)
00287 {
00288 __x.swap(__y);
00289 }
00290 #endif
00291
00292 _STLP_END_NAMESPACE
00293
00294 # undef _STLP_DBG_TREE_SUPER
00295
00296 #endif
00297
00298
00299
00300
00301