]>
Commit | Line | Data |
---|---|---|
285b36d6 BK |
1 | // Debugging multimap implementation -*- C++ -*- |
2 | ||
09952acc | 3 | // Copyright (C) 2003, 2004, 2005 |
285b36d6 BK |
4 | // Free Software Foundation, Inc. |
5 | // | |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 2, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING. If not, write to the Free | |
83f51799 | 19 | // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
285b36d6 BK |
20 | // USA. |
21 | ||
22 | // As a special exception, you may use this file as part of a free software | |
23 | // library without restriction. Specifically, if other files instantiate | |
24 | // templates or use macros or inline functions from this file, or you compile | |
25 | // this file and link it with other files to produce an executable, this | |
26 | // file does not by itself cause the resulting executable to be covered by | |
27 | // the GNU General Public License. This exception does not however | |
28 | // invalidate any other reasons why the executable file might be covered by | |
29 | // the GNU General Public License. | |
30 | ||
31 | #ifndef _GLIBCXX_DEBUG_MULTIMAP_H | |
32 | #define _GLIBCXX_DEBUG_MULTIMAP_H 1 | |
33 | ||
34 | #include <debug/safe_sequence.h> | |
35 | #include <debug/safe_iterator.h> | |
36 | #include <utility> | |
37 | ||
38 | namespace __gnu_debug_def | |
39 | { | |
40 | template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>, | |
41 | typename _Allocator = std::allocator<std::pair<const _Key, _Tp> > > | |
526da49c | 42 | class multimap |
390e4c0d | 43 | : public _GLIBCXX_STD::multimap<_Key, _Tp, _Compare, _Allocator>, |
285b36d6 BK |
44 | public __gnu_debug::_Safe_sequence<multimap<_Key,_Tp,_Compare,_Allocator> > |
45 | { | |
390e4c0d | 46 | typedef _GLIBCXX_STD::multimap<_Key, _Tp, _Compare, _Allocator> _Base; |
285b36d6 | 47 | typedef __gnu_debug::_Safe_sequence<multimap> _Safe_base; |
526da49c | 48 | |
285b36d6 BK |
49 | public: |
50 | // types: | |
526da49c BI |
51 | typedef _Key key_type; |
52 | typedef _Tp mapped_type; | |
285b36d6 BK |
53 | typedef std::pair<const _Key, _Tp> value_type; |
54 | typedef _Compare key_compare; | |
55 | typedef _Allocator allocator_type; | |
09952acc PC |
56 | typedef typename _Base::reference reference; |
57 | typedef typename _Base::const_reference const_reference; | |
526da49c BI |
58 | |
59 | typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, multimap> | |
285b36d6 BK |
60 | iterator; |
61 | typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator, | |
62 | multimap> const_iterator; | |
63 | ||
64 | typedef typename _Base::size_type size_type; | |
65 | typedef typename _Base::difference_type difference_type; | |
09952acc PC |
66 | typedef typename _Base::pointer pointer; |
67 | typedef typename _Base::const_pointer const_pointer; | |
285b36d6 BK |
68 | typedef std::reverse_iterator<iterator> reverse_iterator; |
69 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; | |
526da49c | 70 | |
285b36d6 | 71 | using _Base::value_compare; |
526da49c | 72 | |
285b36d6 BK |
73 | // 23.3.1.1 construct/copy/destroy: |
74 | explicit multimap(const _Compare& __comp = _Compare(), | |
75 | const _Allocator& __a = _Allocator()) | |
76 | : _Base(__comp, __a) { } | |
77 | ||
78 | template<typename _InputIterator> | |
79 | multimap(_InputIterator __first, _InputIterator __last, | |
526da49c | 80 | const _Compare& __comp = _Compare(), |
285b36d6 BK |
81 | const _Allocator& __a = _Allocator()) |
82 | : _Base(__gnu_debug::__check_valid_range(__first, __last), __last, | |
83 | __comp, __a) { } | |
84 | ||
85 | multimap(const multimap<_Key,_Tp,_Compare,_Allocator>& __x) | |
526da49c | 86 | : _Base(__x), _Safe_base() { } |
285b36d6 BK |
87 | |
88 | multimap(const _Base& __x) : _Base(__x), _Safe_base() { } | |
89 | ||
90 | ~multimap() { } | |
91 | ||
92 | multimap<_Key,_Tp,_Compare,_Allocator>& | |
93 | operator=(const multimap<_Key,_Tp,_Compare,_Allocator>& __x) | |
94 | { | |
95 | *static_cast<_Base*>(this) = __x; | |
96 | this->_M_invalidate_all(); | |
97 | return *this; | |
98 | } | |
99 | ||
100 | using _Base::get_allocator; | |
101 | ||
102 | // iterators: | |
526da49c BI |
103 | iterator |
104 | begin() | |
285b36d6 BK |
105 | { return iterator(_Base::begin(), this); } |
106 | ||
526da49c BI |
107 | const_iterator |
108 | begin() const | |
285b36d6 BK |
109 | { return const_iterator(_Base::begin(), this); } |
110 | ||
526da49c BI |
111 | iterator |
112 | end() | |
285b36d6 BK |
113 | { return iterator(_Base::end(), this); } |
114 | ||
526da49c BI |
115 | const_iterator |
116 | end() const | |
285b36d6 BK |
117 | { return const_iterator(_Base::end(), this); } |
118 | ||
526da49c BI |
119 | reverse_iterator |
120 | rbegin() | |
285b36d6 BK |
121 | { return reverse_iterator(end()); } |
122 | ||
526da49c | 123 | const_reverse_iterator |
285b36d6 BK |
124 | rbegin() const |
125 | { return const_reverse_iterator(end()); } | |
126 | ||
526da49c BI |
127 | reverse_iterator |
128 | rend() | |
285b36d6 BK |
129 | { return reverse_iterator(begin()); } |
130 | ||
526da49c BI |
131 | const_reverse_iterator |
132 | rend() const | |
285b36d6 BK |
133 | { return const_reverse_iterator(begin()); } |
134 | ||
135 | // capacity: | |
136 | using _Base::empty; | |
137 | using _Base::size; | |
138 | using _Base::max_size; | |
139 | ||
140 | // modifiers: | |
526da49c | 141 | iterator |
285b36d6 BK |
142 | insert(const value_type& __x) |
143 | { return iterator(_Base::insert(__x), this); } | |
144 | ||
526da49c | 145 | iterator |
285b36d6 BK |
146 | insert(iterator __position, const value_type& __x) |
147 | { | |
148 | __glibcxx_check_insert(__position); | |
149 | return iterator(_Base::insert(__position.base(), __x), this); | |
150 | } | |
151 | ||
152 | template<typename _InputIterator> | |
526da49c | 153 | void |
285b36d6 BK |
154 | insert(_InputIterator __first, _InputIterator __last) |
155 | { | |
156 | __glibcxx_check_valid_range(__first, __last); | |
157 | _Base::insert(__first, __last); | |
158 | } | |
159 | ||
526da49c | 160 | void |
285b36d6 BK |
161 | erase(iterator __position) |
162 | { | |
163 | __glibcxx_check_erase(__position); | |
164 | __position._M_invalidate(); | |
165 | _Base::erase(__position.base()); | |
166 | } | |
167 | ||
526da49c | 168 | size_type |
285b36d6 BK |
169 | erase(const key_type& __x) |
170 | { | |
171 | std::pair<iterator, iterator> __victims = this->equal_range(__x); | |
172 | size_type __count = 0; | |
173 | while (__victims.first != __victims.second) | |
174 | { | |
175 | iterator __victim = __victims.first++; | |
176 | __victim._M_invalidate(); | |
177 | _Base::erase(__victim.base()); | |
178 | ++__count; | |
179 | } | |
180 | return __count; | |
181 | } | |
182 | ||
526da49c | 183 | void |
285b36d6 BK |
184 | erase(iterator __first, iterator __last) |
185 | { | |
186 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
187 | // 151. can't currently clear() empty container | |
188 | __glibcxx_check_erase_range(__first, __last); | |
189 | while (__first != __last) | |
190 | this->erase(__first++); | |
191 | } | |
192 | ||
526da49c | 193 | void |
285b36d6 BK |
194 | swap(multimap<_Key,_Tp,_Compare,_Allocator>& __x) |
195 | { | |
196 | _Base::swap(__x); | |
197 | this->_M_swap(__x); | |
198 | } | |
199 | ||
526da49c | 200 | void |
285b36d6 BK |
201 | clear() |
202 | { this->erase(begin(), end()); } | |
203 | ||
204 | // observers: | |
205 | using _Base::key_comp; | |
206 | using _Base::value_comp; | |
207 | ||
208 | // 23.3.1.3 multimap operations: | |
526da49c | 209 | iterator |
285b36d6 BK |
210 | find(const key_type& __x) |
211 | { return iterator(_Base::find(__x), this); } | |
212 | ||
526da49c | 213 | const_iterator |
285b36d6 BK |
214 | find(const key_type& __x) const |
215 | { return const_iterator(_Base::find(__x), this); } | |
216 | ||
217 | using _Base::count; | |
218 | ||
526da49c | 219 | iterator |
285b36d6 BK |
220 | lower_bound(const key_type& __x) |
221 | { return iterator(_Base::lower_bound(__x), this); } | |
222 | ||
526da49c | 223 | const_iterator |
285b36d6 BK |
224 | lower_bound(const key_type& __x) const |
225 | { return const_iterator(_Base::lower_bound(__x), this); } | |
226 | ||
526da49c | 227 | iterator |
285b36d6 BK |
228 | upper_bound(const key_type& __x) |
229 | { return iterator(_Base::upper_bound(__x), this); } | |
230 | ||
526da49c | 231 | const_iterator |
285b36d6 BK |
232 | upper_bound(const key_type& __x) const |
233 | { return const_iterator(_Base::upper_bound(__x), this); } | |
234 | ||
235 | std::pair<iterator,iterator> | |
236 | equal_range(const key_type& __x) | |
237 | { | |
238 | typedef typename _Base::iterator _Base_iterator; | |
239 | std::pair<_Base_iterator, _Base_iterator> __res = | |
240 | _Base::equal_range(__x); | |
241 | return std::make_pair(iterator(__res.first, this), | |
242 | iterator(__res.second, this)); | |
243 | } | |
244 | ||
245 | std::pair<const_iterator,const_iterator> | |
246 | equal_range(const key_type& __x) const | |
247 | { | |
248 | typedef typename _Base::const_iterator _Base_const_iterator; | |
249 | std::pair<_Base_const_iterator, _Base_const_iterator> __res = | |
250 | _Base::equal_range(__x); | |
251 | return std::make_pair(const_iterator(__res.first, this), | |
252 | const_iterator(__res.second, this)); | |
253 | } | |
254 | ||
526da49c | 255 | _Base& |
285b36d6 BK |
256 | _M_base() { return *this; } |
257 | ||
526da49c | 258 | const _Base& |
285b36d6 BK |
259 | _M_base() const { return *this; } |
260 | ||
261 | private: | |
526da49c | 262 | void |
285b36d6 BK |
263 | _M_invalidate_all() |
264 | { | |
265 | typedef typename _Base::const_iterator _Base_const_iterator; | |
266 | typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal; | |
267 | this->_M_invalidate_if(_Not_equal(_M_base().end())); | |
268 | } | |
269 | }; | |
270 | ||
271 | template<typename _Key,typename _Tp,typename _Compare,typename _Allocator> | |
272 | inline bool | |
526da49c | 273 | operator==(const multimap<_Key,_Tp,_Compare,_Allocator>& __lhs, |
285b36d6 BK |
274 | const multimap<_Key,_Tp,_Compare,_Allocator>& __rhs) |
275 | { return __lhs._M_base() == __rhs._M_base(); } | |
276 | ||
277 | template<typename _Key,typename _Tp,typename _Compare,typename _Allocator> | |
278 | inline bool | |
526da49c | 279 | operator!=(const multimap<_Key,_Tp,_Compare,_Allocator>& __lhs, |
285b36d6 BK |
280 | const multimap<_Key,_Tp,_Compare,_Allocator>& __rhs) |
281 | { return __lhs._M_base() != __rhs._M_base(); } | |
282 | ||
283 | template<typename _Key,typename _Tp,typename _Compare,typename _Allocator> | |
284 | inline bool | |
526da49c | 285 | operator<(const multimap<_Key,_Tp,_Compare,_Allocator>& __lhs, |
285b36d6 BK |
286 | const multimap<_Key,_Tp,_Compare,_Allocator>& __rhs) |
287 | { return __lhs._M_base() < __rhs._M_base(); } | |
288 | ||
289 | template<typename _Key,typename _Tp,typename _Compare,typename _Allocator> | |
290 | inline bool | |
526da49c | 291 | operator<=(const multimap<_Key,_Tp,_Compare,_Allocator>& __lhs, |
285b36d6 BK |
292 | const multimap<_Key,_Tp,_Compare,_Allocator>& __rhs) |
293 | { return __lhs._M_base() <= __rhs._M_base(); } | |
294 | ||
295 | template<typename _Key,typename _Tp,typename _Compare,typename _Allocator> | |
296 | inline bool | |
526da49c | 297 | operator>=(const multimap<_Key,_Tp,_Compare,_Allocator>& __lhs, |
285b36d6 BK |
298 | const multimap<_Key,_Tp,_Compare,_Allocator>& __rhs) |
299 | { return __lhs._M_base() >= __rhs._M_base(); } | |
300 | ||
301 | template<typename _Key,typename _Tp,typename _Compare,typename _Allocator> | |
302 | inline bool | |
526da49c | 303 | operator>(const multimap<_Key,_Tp,_Compare,_Allocator>& __lhs, |
285b36d6 BK |
304 | const multimap<_Key,_Tp,_Compare,_Allocator>& __rhs) |
305 | { return __lhs._M_base() > __rhs._M_base(); } | |
306 | ||
307 | template<typename _Key,typename _Tp,typename _Compare,typename _Allocator> | |
308 | inline void | |
526da49c | 309 | swap(multimap<_Key,_Tp,_Compare,_Allocator>& __lhs, |
285b36d6 BK |
310 | multimap<_Key,_Tp,_Compare,_Allocator>& __rhs) |
311 | { __lhs.swap(__rhs); } | |
312 | } // namespace __gnu_debug_def | |
313 | ||
526da49c | 314 | #endif |