williamr@2
|
1 |
/*
|
williamr@2
|
2 |
*
|
williamr@2
|
3 |
* Copyright (c) 1994
|
williamr@2
|
4 |
* Hewlett-Packard Company
|
williamr@2
|
5 |
*
|
williamr@2
|
6 |
* Copyright (c) 1996,1997
|
williamr@2
|
7 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@2
|
8 |
*
|
williamr@2
|
9 |
* Copyright (c) 1997
|
williamr@2
|
10 |
* Moscow Center for SPARC Technology
|
williamr@2
|
11 |
*
|
williamr@2
|
12 |
* Copyright (c) 1999
|
williamr@2
|
13 |
* Boris Fomitchev
|
williamr@2
|
14 |
*
|
williamr@2
|
15 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@2
|
16 |
* or implied. Any use is at your own risk.
|
williamr@2
|
17 |
*
|
williamr@2
|
18 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@2
|
19 |
* without fee, provided the above notices are retained on all copies.
|
williamr@2
|
20 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@2
|
21 |
* provided the above notices are retained, and a notice that the code was
|
williamr@2
|
22 |
* modified is included with the above copyright notice.
|
williamr@2
|
23 |
*
|
williamr@2
|
24 |
*/
|
williamr@2
|
25 |
|
williamr@2
|
26 |
/* NOTE: This is an internal header file, included by other STL headers.
|
williamr@2
|
27 |
* You should not attempt to use it directly.
|
williamr@2
|
28 |
*/
|
williamr@2
|
29 |
|
williamr@2
|
30 |
#ifndef _STLP_INTERNAL_DBG_TREE_H
|
williamr@2
|
31 |
#define _STLP_INTERNAL_DBG_TREE_H
|
williamr@2
|
32 |
|
williamr@2
|
33 |
#include <stl/debug/_iterator.h>
|
williamr@2
|
34 |
#include <stl/_function.h>
|
williamr@2
|
35 |
#include <stl/_alloc.h>
|
williamr@2
|
36 |
|
williamr@2
|
37 |
# undef _DBG_Rb_tree
|
williamr@2
|
38 |
# define _DBG_Rb_tree _Rb_tree
|
williamr@2
|
39 |
|
williamr@2
|
40 |
# define _STLP_DBG_TREE_SUPER __WORKAROUND_DBG_RENAME(Rb_tree) <_Key, _Value, _KeyOfValue, _Compare, _Alloc>
|
williamr@2
|
41 |
|
williamr@2
|
42 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
43 |
|
williamr@2
|
44 |
# ifdef _STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS
|
williamr@2
|
45 |
template <class _Key, class _Value, class _KeyOfValue, class _Compare, class _Alloc >
|
williamr@2
|
46 |
inline _Value*
|
williamr@2
|
47 |
value_type(const _DBG_iter_base< _STLP_DBG_TREE_SUPER >&) {
|
williamr@2
|
48 |
return (_Value*)0;
|
williamr@2
|
49 |
}
|
williamr@2
|
50 |
template <class _Key, class _Value, class _KeyOfValue, class _Compare, class _Alloc >
|
williamr@2
|
51 |
inline bidirectional_iterator_tag
|
williamr@2
|
52 |
iterator_category(const _DBG_iter_base< _STLP_DBG_TREE_SUPER >&) {
|
williamr@2
|
53 |
return bidirectional_iterator_tag();
|
williamr@2
|
54 |
}
|
williamr@2
|
55 |
# endif
|
williamr@2
|
56 |
|
williamr@2
|
57 |
template <class _Key, class _Value, class _KeyOfValue, class _Compare,
|
williamr@2
|
58 |
_STLP_DBG_ALLOCATOR_SELECT(_Value) >
|
williamr@2
|
59 |
class _DBG_Rb_tree : public _STLP_DBG_TREE_SUPER {
|
williamr@2
|
60 |
typedef _STLP_DBG_TREE_SUPER _Base;
|
williamr@2
|
61 |
typedef _DBG_Rb_tree<_Key, _Value, _KeyOfValue, _Compare, _Alloc> _Self;
|
williamr@2
|
62 |
protected:
|
williamr@2
|
63 |
friend class __owned_link;
|
williamr@2
|
64 |
mutable __owned_list _M_iter_list;
|
williamr@2
|
65 |
|
williamr@2
|
66 |
public:
|
williamr@2
|
67 |
__IMPORT_CONTAINER_TYPEDEFS(_Base)
|
williamr@2
|
68 |
typedef typename _Base::key_type key_type;
|
williamr@2
|
69 |
|
williamr@2
|
70 |
typedef _DBG_iter<_Base, _Nonconst_traits<value_type> > iterator;
|
williamr@2
|
71 |
typedef _DBG_iter<_Base, _Const_traits<value_type> > const_iterator;
|
williamr@2
|
72 |
|
williamr@2
|
73 |
_STLP_DECLARE_BIDIRECTIONAL_REVERSE_ITERATORS;
|
williamr@2
|
74 |
|
williamr@2
|
75 |
protected:
|
williamr@2
|
76 |
|
williamr@2
|
77 |
//typedef typename _Base::key_param_type key_param_type;
|
williamr@2
|
78 |
//typedef typename _Base::val_param_type val_param_type;
|
williamr@2
|
79 |
|
williamr@2
|
80 |
void _Invalidate_all() {_M_iter_list._Invalidate_all();}
|
williamr@2
|
81 |
|
williamr@2
|
82 |
void _Invalidate_iterator(const iterator& __it) {
|
williamr@2
|
83 |
__invalidate_iterator(&_M_iter_list,__it);
|
williamr@2
|
84 |
}
|
williamr@2
|
85 |
void _Invalidate_iterators(const iterator& __first, const iterator& __last) {
|
williamr@2
|
86 |
iterator __cur = __first;
|
williamr@2
|
87 |
while (__cur != __last) __invalidate_iterator(&_M_iter_list, __cur++);
|
williamr@2
|
88 |
}
|
williamr@2
|
89 |
|
williamr@2
|
90 |
const _Base* _Get_base() const { return (const _Base*)this; }
|
williamr@2
|
91 |
_Base* _Get_base() { return (_Base*)this; }
|
williamr@2
|
92 |
|
williamr@2
|
93 |
public:
|
williamr@2
|
94 |
_DBG_Rb_tree() : _STLP_DBG_TREE_SUPER(),
|
williamr@2
|
95 |
_M_iter_list(_Get_base()) {}
|
williamr@2
|
96 |
_DBG_Rb_tree(const _Compare& __comp) :
|
williamr@2
|
97 |
_STLP_DBG_TREE_SUPER(__comp), _M_iter_list(_Get_base()) {}
|
williamr@2
|
98 |
_DBG_Rb_tree(const _Compare& __comp, const allocator_type& __a):
|
williamr@2
|
99 |
_STLP_DBG_TREE_SUPER(__comp, __a), _M_iter_list(_Get_base()) {}
|
williamr@2
|
100 |
_DBG_Rb_tree(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x):
|
williamr@2
|
101 |
_STLP_DBG_TREE_SUPER(__x), _M_iter_list(_Get_base()) {}
|
williamr@2
|
102 |
~_DBG_Rb_tree() { _Invalidate_all(); }
|
williamr@2
|
103 |
|
williamr@2
|
104 |
_Self& operator=(const _Self& __x) {
|
williamr@2
|
105 |
_Invalidate_all();
|
williamr@2
|
106 |
(_Base&)*this = (const _Base&)__x;
|
williamr@2
|
107 |
return *this;
|
williamr@2
|
108 |
}
|
williamr@2
|
109 |
|
williamr@2
|
110 |
iterator begin() { return iterator(&_M_iter_list,_Base::begin()); }
|
williamr@2
|
111 |
const_iterator begin() const { return const_iterator(&_M_iter_list, _Base::begin()); }
|
williamr@2
|
112 |
iterator end() { return iterator(&_M_iter_list, _Base::end()); }
|
williamr@2
|
113 |
const_iterator end() const { return const_iterator(&_M_iter_list,_Base::end()); }
|
williamr@2
|
114 |
|
williamr@2
|
115 |
public:
|
williamr@2
|
116 |
reverse_iterator rbegin() { return reverse_iterator(end()); }
|
williamr@2
|
117 |
const_reverse_iterator rbegin() const {
|
williamr@2
|
118 |
return const_reverse_iterator(end());
|
williamr@2
|
119 |
}
|
williamr@2
|
120 |
reverse_iterator rend() { return reverse_iterator(begin()); }
|
williamr@2
|
121 |
const_reverse_iterator rend() const {
|
williamr@2
|
122 |
return const_reverse_iterator(begin());
|
williamr@2
|
123 |
}
|
williamr@2
|
124 |
void swap(_Self& __t) {
|
williamr@2
|
125 |
_Base::swap(__t);
|
williamr@2
|
126 |
_M_iter_list._Swap_owners(__t._M_iter_list);
|
williamr@2
|
127 |
}
|
williamr@2
|
128 |
|
williamr@2
|
129 |
public:
|
williamr@2
|
130 |
|
williamr@2
|
131 |
iterator find(const key_type& __x) {
|
williamr@2
|
132 |
return iterator(&_M_iter_list, _Base::find(__x));
|
williamr@2
|
133 |
}
|
williamr@2
|
134 |
const_iterator find(const key_type& __x) const {
|
williamr@2
|
135 |
return const_iterator(&_M_iter_list, _Base::find(__x));
|
williamr@2
|
136 |
}
|
williamr@2
|
137 |
|
williamr@2
|
138 |
iterator lower_bound(const key_type& __x) {
|
williamr@2
|
139 |
return iterator(&_M_iter_list, _Base::lower_bound(__x));
|
williamr@2
|
140 |
}
|
williamr@2
|
141 |
const_iterator lower_bound(const key_type& __x) const {
|
williamr@2
|
142 |
return const_iterator(&_M_iter_list, _Base::lower_bound(__x));
|
williamr@2
|
143 |
}
|
williamr@2
|
144 |
|
williamr@2
|
145 |
iterator upper_bound(const key_type& __x) {
|
williamr@2
|
146 |
return iterator(&_M_iter_list, _Base::upper_bound(__x));
|
williamr@2
|
147 |
}
|
williamr@2
|
148 |
const_iterator upper_bound(const key_type& __x) const {
|
williamr@2
|
149 |
return const_iterator(&_M_iter_list, _Base::upper_bound(__x));
|
williamr@2
|
150 |
}
|
williamr@2
|
151 |
|
williamr@2
|
152 |
pair<iterator,iterator> equal_range(const key_type& __x) {
|
williamr@2
|
153 |
return pair<iterator, iterator>(iterator(&_M_iter_list, _Base::lower_bound(__x)),
|
williamr@2
|
154 |
iterator(&_M_iter_list, _Base::upper_bound(__x)));
|
williamr@2
|
155 |
}
|
williamr@2
|
156 |
pair<const_iterator, const_iterator> equal_range(const key_type& __x) const {
|
williamr@2
|
157 |
return pair<const_iterator,const_iterator>(const_iterator(&_M_iter_list, _Base::lower_bound(__x)),
|
williamr@2
|
158 |
const_iterator(&_M_iter_list, _Base::upper_bound(__x)));
|
williamr@2
|
159 |
}
|
williamr@2
|
160 |
|
williamr@2
|
161 |
pair<iterator,bool> insert_unique(const value_type& __x) {
|
williamr@2
|
162 |
_STLP_STD::pair<_STLP_HEADER_TYPENAME _Base::iterator, bool> __res = _Base::insert_unique(__x);
|
williamr@2
|
163 |
return pair<iterator,bool>( iterator(&_M_iter_list, __res.first), __res.second ) ;
|
williamr@2
|
164 |
}
|
williamr@2
|
165 |
iterator insert_equal(const value_type& __x) {
|
williamr@2
|
166 |
return iterator(&_M_iter_list, _Base::insert_equal(__x));
|
williamr@2
|
167 |
}
|
williamr@2
|
168 |
|
williamr@2
|
169 |
iterator insert_unique(iterator __position, const value_type& __x) {
|
williamr@2
|
170 |
_STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position))
|
williamr@2
|
171 |
return iterator(&_M_iter_list, _Base::insert_unique(__position._M_iterator, __x));
|
williamr@2
|
172 |
}
|
williamr@2
|
173 |
iterator insert_equal(iterator __position, const value_type& __x) {
|
williamr@2
|
174 |
_STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position))
|
williamr@2
|
175 |
return iterator(&_M_iter_list, _Base::insert_equal(__position._M_iterator, __x));
|
williamr@2
|
176 |
}
|
williamr@2
|
177 |
|
williamr@2
|
178 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
179 |
template<class _II>
|
williamr@2
|
180 |
void insert_equal(_II __first, _II __last) {
|
williamr@2
|
181 |
_Base::insert_equal(__first, __last);
|
williamr@2
|
182 |
}
|
williamr@2
|
183 |
template<class _II>
|
williamr@2
|
184 |
void insert_unique(_II __first, _II __last) {
|
williamr@2
|
185 |
_Base::insert_unique(__first, __last);
|
williamr@2
|
186 |
}
|
williamr@2
|
187 |
#else /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
188 |
void insert_unique(const_iterator __first, const_iterator __last) {
|
williamr@2
|
189 |
_Base::insert_unique(__first._M_iterator, __last._M_iterator);
|
williamr@2
|
190 |
}
|
williamr@2
|
191 |
void insert_unique(const value_type* __first, const value_type* __last) {
|
williamr@2
|
192 |
_Base::insert_unique(__first, __last);
|
williamr@2
|
193 |
}
|
williamr@2
|
194 |
void insert_equal(const_iterator __first, const_iterator __last) {
|
williamr@2
|
195 |
_Base::insert_equal(__first._M_iterator, __last._M_iterator);
|
williamr@2
|
196 |
}
|
williamr@2
|
197 |
void insert_equal(const value_type* __first, const value_type* __last) {
|
williamr@2
|
198 |
_Base::insert_equal(__first, __last);
|
williamr@2
|
199 |
}
|
williamr@2
|
200 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
201 |
|
williamr@2
|
202 |
void erase(iterator __position) {
|
williamr@2
|
203 |
_STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position))
|
williamr@2
|
204 |
_STLP_DEBUG_CHECK(_Dereferenceable(__position))
|
williamr@2
|
205 |
_Invalidate_iterator(__position);
|
williamr@2
|
206 |
_Base::erase(__position._M_iterator);
|
williamr@2
|
207 |
}
|
williamr@2
|
208 |
size_type erase(const key_type& __x) {
|
williamr@2
|
209 |
pair<iterator,iterator> __p = equal_range(__x);
|
williamr@2
|
210 |
size_type __n = distance(__p.first, __p.second);
|
williamr@2
|
211 |
_Invalidate_iterators(__p.first, __p.second);
|
williamr@2
|
212 |
_Base::erase(__p.first._M_iterator, __p.second._M_iterator);
|
williamr@2
|
213 |
return __n;
|
williamr@2
|
214 |
}
|
williamr@2
|
215 |
|
williamr@2
|
216 |
void erase(iterator __first, iterator __last) {
|
williamr@2
|
217 |
_STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __first)&&
|
williamr@2
|
218 |
__check_if_owner(&_M_iter_list, __last))
|
williamr@2
|
219 |
_Invalidate_iterators(__first, __last);
|
williamr@2
|
220 |
_Base::erase(__first._M_iterator, __last._M_iterator);
|
williamr@2
|
221 |
}
|
williamr@2
|
222 |
void erase(const key_type* __first, const key_type* __last) {
|
williamr@2
|
223 |
while (__first != __last) erase(*__first++);
|
williamr@2
|
224 |
}
|
williamr@2
|
225 |
|
williamr@2
|
226 |
void clear() {
|
williamr@2
|
227 |
_Invalidate_all();
|
williamr@2
|
228 |
_Base::clear();
|
williamr@2
|
229 |
}
|
williamr@2
|
230 |
};
|
williamr@2
|
231 |
|
williamr@2
|
232 |
#define _STLP_TEMPLATE_HEADER template <class _Key, class _Value, class _KeyOfValue, class _Compare, class _Alloc>
|
williamr@2
|
233 |
#define _STLP_TEMPLATE_CONTAINER _DBG_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>
|
williamr@2
|
234 |
#define _STLP_TEMPLATE_CONTAINER_BASE _STLP_DBG_TREE_SUPER
|
williamr@2
|
235 |
#include <stl/debug/_relops_cont.h>
|
williamr@2
|
236 |
#undef _STLP_TEMPLATE_CONTAINER_BASE
|
williamr@2
|
237 |
#undef _STLP_TEMPLATE_CONTAINER
|
williamr@2
|
238 |
#undef _STLP_TEMPLATE_HEADER
|
williamr@2
|
239 |
|
williamr@2
|
240 |
_STLP_END_NAMESPACE
|
williamr@2
|
241 |
|
williamr@2
|
242 |
# undef _STLP_DBG_TREE_SUPER
|
williamr@2
|
243 |
|
williamr@2
|
244 |
#endif /* _STLP_INTERNAL_DBG_TREE_H */
|
williamr@2
|
245 |
|
williamr@2
|
246 |
// Local Variables:
|
williamr@2
|
247 |
// mode:C++
|
williamr@2
|
248 |
// End:
|
williamr@2
|
249 |
|