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/] [map.h] - Blame information for rev 35

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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