~ubuntu-branches/ubuntu/hardy/libterralib/hardy

« back to all changes in this revision

Viewing changes to src/STLport/stl/debug/_tree.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2005-11-25 22:32:59 UTC
  • Revision ID: james.westby@ubuntu.com-20051125223259-3zubal8ux4ki4fjg
Tags: upstream-3.0.3b2
ImportĀ upstreamĀ versionĀ 3.0.3b2

Show diffs side-by-side

added added

removed removed

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