OpenCores
URL https://opencores.org/ocsvn/altor32/altor32/trunk

Subversion Repositories altor32

[/] [altor32/] [trunk/] [gcc-x64/] [or1knd-elf/] [or1knd-elf/] [include/] [c++/] [4.8.0/] [debug/] [multimap.h] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 ultra_embe
// Debugging multimap implementation -*- C++ -*-
2
 
3
// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011, 2012
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 3, 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
// Under Section 7 of GPL version 3, you are granted additional
18
// permissions described in the GCC Runtime Library Exception, version
19
// 3.1, as published by the Free Software Foundation.
20
 
21
// You should have received a copy of the GNU General Public License and
22
// a copy of the GCC Runtime Library Exception along with this program;
23
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24
// <http://www.gnu.org/licenses/>.
25
 
26
/** @file debug/multimap.h
27
 *  This file is a GNU debug extension to the Standard C++ Library.
28
 */
29
 
30
#ifndef _GLIBCXX_DEBUG_MULTIMAP_H
31
#define _GLIBCXX_DEBUG_MULTIMAP_H 1
32
 
33
#include <debug/safe_sequence.h>
34
#include <debug/safe_iterator.h>
35
#include <utility>
36
 
37
namespace std _GLIBCXX_VISIBILITY(default)
38
{
39
namespace __debug
40
{
41
  /// Class std::multimap with safety/checking/debug instrumentation.
42
  template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
43
           typename _Allocator = std::allocator<std::pair<const _Key, _Tp> > >
44
    class multimap
45
    : public _GLIBCXX_STD_C::multimap<_Key, _Tp, _Compare, _Allocator>,
46
      public __gnu_debug::_Safe_sequence<multimap<_Key, _Tp,
47
                                                  _Compare, _Allocator> >
48
    {
49
      typedef _GLIBCXX_STD_C::multimap<_Key, _Tp, _Compare, _Allocator> _Base;
50
 
51
      typedef typename _Base::const_iterator _Base_const_iterator;
52
      typedef typename _Base::iterator _Base_iterator;
53
      typedef __gnu_debug::_Equal_to<_Base_const_iterator> _Equal;
54
    public:
55
      // types:
56
      typedef _Key                                   key_type;
57
      typedef _Tp                                    mapped_type;
58
      typedef std::pair<const _Key, _Tp>             value_type;
59
      typedef _Compare                               key_compare;
60
      typedef _Allocator                             allocator_type;
61
      typedef typename _Base::reference              reference;
62
      typedef typename _Base::const_reference        const_reference;
63
 
64
      typedef __gnu_debug::_Safe_iterator<_Base_iterator, multimap>
65
                                                     iterator;
66
      typedef __gnu_debug::_Safe_iterator<_Base_const_iterator,
67
                                           multimap> const_iterator;
68
 
69
      typedef typename _Base::size_type              size_type;
70
      typedef typename _Base::difference_type        difference_type;
71
      typedef typename _Base::pointer                pointer;
72
      typedef typename _Base::const_pointer          const_pointer;
73
      typedef std::reverse_iterator<iterator>        reverse_iterator;
74
      typedef std::reverse_iterator<const_iterator>  const_reverse_iterator;
75
 
76
      // 23.3.1.1 construct/copy/destroy:
77
      explicit multimap(const _Compare& __comp = _Compare(),
78
                        const _Allocator& __a = _Allocator())
79
      : _Base(__comp, __a) { }
80
 
81
      template<typename _InputIterator>
82
      multimap(_InputIterator __first, _InputIterator __last,
83
               const _Compare& __comp = _Compare(),
84
               const _Allocator& __a = _Allocator())
85
        : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
86
                                                                     __last)),
87
                __gnu_debug::__base(__last),
88
              __comp, __a) { }
89
 
90
      multimap(const multimap& __x)
91
      : _Base(__x) { }
92
 
93
      multimap(const _Base& __x)
94
      : _Base(__x) { }
95
 
96
#if __cplusplus >= 201103L
97
      multimap(multimap&& __x)
98
      noexcept(is_nothrow_copy_constructible<_Compare>::value)
99
      : _Base(std::move(__x))
100
      { this->_M_swap(__x); }
101
 
102
      multimap(initializer_list<value_type> __l,
103
               const _Compare& __c = _Compare(),
104
               const allocator_type& __a = allocator_type())
105
      : _Base(__l, __c, __a) { }
106
#endif
107
 
108
      ~multimap() _GLIBCXX_NOEXCEPT { }
109
 
110
      multimap&
111
      operator=(const multimap& __x)
112
      {
113
        *static_cast<_Base*>(this) = __x;
114
        this->_M_invalidate_all();
115
        return *this;
116
      }
117
 
118
#if __cplusplus >= 201103L
119
      multimap&
120
      operator=(multimap&& __x)
121
      {
122
        // NB: DR 1204.
123
        // NB: DR 675.
124
        __glibcxx_check_self_move_assign(__x);
125
        clear();
126
        swap(__x);
127
        return *this;
128
      }
129
 
130
      multimap&
131
      operator=(initializer_list<value_type> __l)
132
      {
133
        this->clear();
134
        this->insert(__l);
135
        return *this;
136
      }
137
#endif
138
 
139
      using _Base::get_allocator;
140
 
141
      // iterators:
142
      iterator
143
      begin() _GLIBCXX_NOEXCEPT
144
      { return iterator(_Base::begin(), this); }
145
 
146
      const_iterator
147
      begin() const _GLIBCXX_NOEXCEPT
148
      { return const_iterator(_Base::begin(), this); }
149
 
150
      iterator
151
      end() _GLIBCXX_NOEXCEPT
152
      { return iterator(_Base::end(), this); }
153
 
154
      const_iterator
155
      end() const _GLIBCXX_NOEXCEPT
156
      { return const_iterator(_Base::end(), this); }
157
 
158
      reverse_iterator
159
      rbegin() _GLIBCXX_NOEXCEPT
160
      { return reverse_iterator(end()); }
161
 
162
      const_reverse_iterator
163
      rbegin() const _GLIBCXX_NOEXCEPT
164
      { return const_reverse_iterator(end()); }
165
 
166
      reverse_iterator
167
      rend() _GLIBCXX_NOEXCEPT
168
      { return reverse_iterator(begin()); }
169
 
170
      const_reverse_iterator
171
      rend() const _GLIBCXX_NOEXCEPT
172
      { return const_reverse_iterator(begin()); }
173
 
174
#if __cplusplus >= 201103L
175
      const_iterator
176
      cbegin() const noexcept
177
      { return const_iterator(_Base::begin(), this); }
178
 
179
      const_iterator
180
      cend() const noexcept
181
      { return const_iterator(_Base::end(), this); }
182
 
183
      const_reverse_iterator
184
      crbegin() const noexcept
185
      { return const_reverse_iterator(end()); }
186
 
187
      const_reverse_iterator
188
      crend() const noexcept
189
      { return const_reverse_iterator(begin()); }
190
#endif
191
 
192
      // capacity:
193
      using _Base::empty;
194
      using _Base::size;
195
      using _Base::max_size;
196
 
197
      // modifiers:
198
#if __cplusplus >= 201103L
199
      template<typename... _Args>
200
        iterator
201
        emplace(_Args&&... __args)
202
        {
203
          return iterator(_Base::emplace(std::forward<_Args>(__args)...), this);
204
        }
205
 
206
      template<typename... _Args>
207
        iterator
208
        emplace_hint(const_iterator __pos, _Args&&... __args)
209
        {
210
          __glibcxx_check_insert(__pos);
211
          return iterator(_Base::emplace_hint(__pos.base(),
212
                                              std::forward<_Args>(__args)...),
213
                          this);
214
        }
215
#endif
216
 
217
      iterator
218
      insert(const value_type& __x)
219
      { return iterator(_Base::insert(__x), this); }
220
 
221
#if __cplusplus >= 201103L
222
      template<typename _Pair, typename = typename
223
               std::enable_if<std::is_constructible<value_type,
224
                                                    _Pair&&>::value>::type>
225
        iterator
226
        insert(_Pair&& __x)
227
        { return iterator(_Base::insert(std::forward<_Pair>(__x)), this); }
228
#endif
229
 
230
#if __cplusplus >= 201103L
231
      void
232
      insert(std::initializer_list<value_type> __list)
233
      { _Base::insert(__list); }
234
#endif
235
 
236
      iterator
237
#if __cplusplus >= 201103L
238
      insert(const_iterator __position, const value_type& __x)
239
#else
240
      insert(iterator __position, const value_type& __x)
241
#endif
242
      {
243
        __glibcxx_check_insert(__position);
244
        return iterator(_Base::insert(__position.base(), __x), this);
245
      }
246
 
247
#if __cplusplus >= 201103L
248
      template<typename _Pair, typename = typename
249
               std::enable_if<std::is_constructible<value_type,
250
                                                    _Pair&&>::value>::type>
251
        iterator
252
        insert(const_iterator __position, _Pair&& __x)
253
        {
254
          __glibcxx_check_insert(__position);
255
          return iterator(_Base::insert(__position.base(),
256
                                        std::forward<_Pair>(__x)), this);
257
        }
258
#endif
259
 
260
      template<typename _InputIterator>
261
        void
262
        insert(_InputIterator __first, _InputIterator __last)
263
        {
264
          __glibcxx_check_valid_range(__first, __last);
265
          _Base::insert(__gnu_debug::__base(__first),
266
                        __gnu_debug::__base(__last));
267
        }
268
 
269
#if __cplusplus >= 201103L
270
      iterator
271
      erase(const_iterator __position)
272
      {
273
        __glibcxx_check_erase(__position);
274
        this->_M_invalidate_if(_Equal(__position.base()));
275
        return iterator(_Base::erase(__position.base()), this);
276
      }
277
 
278
      iterator
279
      erase(iterator __position)
280
      { return erase(const_iterator(__position)); }
281
#else
282
      void
283
      erase(iterator __position)
284
      {
285
        __glibcxx_check_erase(__position);
286
        this->_M_invalidate_if(_Equal(__position.base()));
287
        _Base::erase(__position.base());
288
      }
289
#endif
290
 
291
      size_type
292
      erase(const key_type& __x)
293
      {
294
        std::pair<_Base_iterator, _Base_iterator> __victims =
295
          _Base::equal_range(__x);
296
        size_type __count = 0;
297
        _Base_iterator __victim = __victims.first;
298
        while (__victim !=  __victims.second)
299
          {
300
            this->_M_invalidate_if(_Equal(__victim));
301
            _Base::erase(__victim++);
302
            ++__count;
303
          }
304
        return __count;
305
      }
306
 
307
#if __cplusplus >= 201103L
308
      iterator
309
      erase(const_iterator __first, const_iterator __last)
310
      {
311
        // _GLIBCXX_RESOLVE_LIB_DEFECTS
312
        // 151. can't currently clear() empty container
313
        __glibcxx_check_erase_range(__first, __last);
314
        for (_Base_const_iterator __victim = __first.base();
315
             __victim != __last.base(); ++__victim)
316
          {
317
            _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
318
                                  _M_message(__gnu_debug::__msg_valid_range)
319
                                  ._M_iterator(__first, "first")
320
                                  ._M_iterator(__last, "last"));
321
            this->_M_invalidate_if(_Equal(__victim));
322
          }
323
        return iterator(_Base::erase(__first.base(), __last.base()), this);
324
      }
325
#else
326
      void
327
      erase(iterator __first, iterator __last)
328
      {
329
        // _GLIBCXX_RESOLVE_LIB_DEFECTS
330
        // 151. can't currently clear() empty container
331
        __glibcxx_check_erase_range(__first, __last);
332
        for (_Base_iterator __victim = __first.base();
333
             __victim != __last.base(); ++__victim)
334
          {
335
            _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
336
                                  _M_message(__gnu_debug::__msg_valid_range)
337
                                  ._M_iterator(__first, "first")
338
                                  ._M_iterator(__last, "last"));
339
            this->_M_invalidate_if(_Equal(__victim));
340
          }
341
        _Base::erase(__first.base(), __last.base());
342
      }
343
#endif
344
 
345
      void
346
      swap(multimap& __x)
347
      {
348
        _Base::swap(__x);
349
        this->_M_swap(__x);
350
      }
351
 
352
      void
353
      clear() _GLIBCXX_NOEXCEPT
354
      {
355
        this->_M_invalidate_all();
356
        _Base::clear();
357
      }
358
 
359
      // observers:
360
      using _Base::key_comp;
361
      using _Base::value_comp;
362
 
363
      // 23.3.1.3 multimap operations:
364
      iterator
365
      find(const key_type& __x)
366
      { return iterator(_Base::find(__x), this); }
367
 
368
      const_iterator
369
      find(const key_type& __x) const
370
      { return const_iterator(_Base::find(__x), this); }
371
 
372
      using _Base::count;
373
 
374
      iterator
375
      lower_bound(const key_type& __x)
376
      { return iterator(_Base::lower_bound(__x), this); }
377
 
378
      const_iterator
379
      lower_bound(const key_type& __x) const
380
      { return const_iterator(_Base::lower_bound(__x), this); }
381
 
382
      iterator
383
      upper_bound(const key_type& __x)
384
      { return iterator(_Base::upper_bound(__x), this); }
385
 
386
      const_iterator
387
      upper_bound(const key_type& __x) const
388
      { return const_iterator(_Base::upper_bound(__x), this); }
389
 
390
      std::pair<iterator,iterator>
391
      equal_range(const key_type& __x)
392
      {
393
        std::pair<_Base_iterator, _Base_iterator> __res =
394
        _Base::equal_range(__x);
395
        return std::make_pair(iterator(__res.first, this),
396
                              iterator(__res.second, this));
397
      }
398
 
399
      std::pair<const_iterator,const_iterator>
400
      equal_range(const key_type& __x) const
401
      {
402
        std::pair<_Base_const_iterator, _Base_const_iterator> __res =
403
          _Base::equal_range(__x);
404
        return std::make_pair(const_iterator(__res.first, this),
405
                              const_iterator(__res.second, this));
406
      }
407
 
408
      _Base&
409
      _M_base() _GLIBCXX_NOEXCEPT       { return *this; }
410
 
411
      const _Base&
412
      _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
413
 
414
    private:
415
      void
416
      _M_invalidate_all()
417
      {
418
        typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
419
        this->_M_invalidate_if(_Not_equal(_Base::end()));
420
      }
421
    };
422
 
423
  template<typename _Key, typename _Tp,
424
           typename _Compare, typename _Allocator>
425
    inline bool
426
    operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
427
               const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
428
    { return __lhs._M_base() == __rhs._M_base(); }
429
 
430
  template<typename _Key, typename _Tp,
431
           typename _Compare, typename _Allocator>
432
    inline bool
433
    operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
434
               const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
435
    { return __lhs._M_base() != __rhs._M_base(); }
436
 
437
  template<typename _Key, typename _Tp,
438
           typename _Compare, typename _Allocator>
439
    inline bool
440
    operator<(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
441
              const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
442
    { return __lhs._M_base() < __rhs._M_base(); }
443
 
444
  template<typename _Key, typename _Tp,
445
           typename _Compare, typename _Allocator>
446
    inline bool
447
    operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
448
               const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
449
    { return __lhs._M_base() <= __rhs._M_base(); }
450
 
451
  template<typename _Key, typename _Tp,
452
           typename _Compare, typename _Allocator>
453
    inline bool
454
    operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
455
               const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
456
    { return __lhs._M_base() >= __rhs._M_base(); }
457
 
458
  template<typename _Key, typename _Tp,
459
           typename _Compare, typename _Allocator>
460
    inline bool
461
    operator>(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
462
              const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
463
    { return __lhs._M_base() > __rhs._M_base(); }
464
 
465
  template<typename _Key, typename _Tp,
466
           typename _Compare, typename _Allocator>
467
    inline void
468
    swap(multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
469
         multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
470
    { __lhs.swap(__rhs); }
471
 
472
} // namespace __debug
473
} // namespace std
474
 
475
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.