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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 ultra_embe
// Debugging deque implementation -*- C++ -*-
2
 
3
// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
4
// 2012
5
// Free Software Foundation, Inc.
6
//
7
// This file is part of the GNU ISO C++ Library.  This library is free
8
// software; you can redistribute it and/or modify it under the
9
// terms of the GNU General Public License as published by the
10
// Free Software Foundation; either version 3, or (at your option)
11
// any later version.
12
 
13
// This library is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
// GNU General Public License for more details.
17
 
18
// Under Section 7 of GPL version 3, you are granted additional
19
// permissions described in the GCC Runtime Library Exception, version
20
// 3.1, as published by the Free Software Foundation.
21
 
22
// You should have received a copy of the GNU General Public License and
23
// a copy of the GCC Runtime Library Exception along with this program;
24
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
25
// .
26
 
27
/** @file debug/deque
28
 *  This file is a GNU debug extension to the Standard C++ Library.
29
 */
30
 
31
#ifndef _GLIBCXX_DEBUG_DEQUE
32
#define _GLIBCXX_DEBUG_DEQUE 1
33
 
34
#include 
35
#include 
36
#include 
37
 
38
namespace std _GLIBCXX_VISIBILITY(default)
39
{
40
namespace __debug
41
{
42
  /// Class std::deque with safety/checking/debug instrumentation.
43
  template >
44
    class deque
45
    : public _GLIBCXX_STD_C::deque<_Tp, _Allocator>,
46
      public __gnu_debug::_Safe_sequence >
47
    {
48
      typedef  _GLIBCXX_STD_C::deque<_Tp, _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
      typedef typename _Base::reference             reference;
55
      typedef typename _Base::const_reference       const_reference;
56
 
57
      typedef __gnu_debug::_Safe_iterator<_Base_iterator,deque>
58
                                                    iterator;
59
      typedef __gnu_debug::_Safe_iterator<_Base_const_iterator,deque>
60
                                                    const_iterator;
61
 
62
      typedef typename _Base::size_type             size_type;
63
      typedef typename _Base::difference_type       difference_type;
64
 
65
      typedef _Tp                                   value_type;
66
      typedef _Allocator                            allocator_type;
67
      typedef typename _Base::pointer               pointer;
68
      typedef typename _Base::const_pointer         const_pointer;
69
      typedef std::reverse_iterator       reverse_iterator;
70
      typedef std::reverse_iterator const_reverse_iterator;
71
 
72
      // 23.2.1.1 construct/copy/destroy:
73
      explicit
74
      deque(const _Allocator& __a = _Allocator())
75
      : _Base(__a) { }
76
 
77
#if __cplusplus >= 201103L
78
      explicit
79
      deque(size_type __n)
80
      : _Base(__n) { }
81
 
82
      deque(size_type __n, const _Tp& __value,
83
            const _Allocator& __a = _Allocator())
84
      : _Base(__n, __value, __a) { }
85
#else
86
      explicit
87
      deque(size_type __n, const _Tp& __value = _Tp(),
88
            const _Allocator& __a = _Allocator())
89
      : _Base(__n, __value, __a) { }
90
#endif
91
 
92
#if __cplusplus >= 201103L
93
      template
94
               typename = std::_RequireInputIter<_InputIterator>>
95
#else
96
      template
97
#endif
98
        deque(_InputIterator __first, _InputIterator __last,
99
              const _Allocator& __a = _Allocator())
100
        : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
101
                                                                     __last)),
102
                __gnu_debug::__base(__last), __a)
103
        { }
104
 
105
      deque(const deque& __x)
106
      : _Base(__x) { }
107
 
108
      deque(const _Base& __x)
109
      : _Base(__x) { }
110
 
111
#if __cplusplus >= 201103L
112
      deque(deque&& __x)
113
      : _Base(std::move(__x))
114
      { this->_M_swap(__x); }
115
 
116
      deque(initializer_list __l,
117
            const allocator_type& __a = allocator_type())
118
      : _Base(__l, __a) { }
119
#endif
120
 
121
      ~deque() _GLIBCXX_NOEXCEPT { }
122
 
123
      deque&
124
      operator=(const deque& __x)
125
      {
126
        *static_cast<_Base*>(this) = __x;
127
        this->_M_invalidate_all();
128
        return *this;
129
      }
130
 
131
#if __cplusplus >= 201103L
132
      deque&
133
      operator=(deque&& __x)
134
      {
135
        // NB: DR 1204.
136
        // NB: DR 675.
137
        __glibcxx_check_self_move_assign(__x);
138
        clear();
139
        swap(__x);
140
        return *this;
141
      }
142
 
143
      deque&
144
      operator=(initializer_list __l)
145
      {
146
        *static_cast<_Base*>(this) = __l;
147
        this->_M_invalidate_all();
148
        return *this;
149
      }
150
#endif
151
 
152
#if __cplusplus >= 201103L
153
      template
154
               typename = std::_RequireInputIter<_InputIterator>>
155
#else
156
      template
157
#endif
158
        void
159
        assign(_InputIterator __first, _InputIterator __last)
160
        {
161
          __glibcxx_check_valid_range(__first, __last);
162
          _Base::assign(__gnu_debug::__base(__first),
163
                        __gnu_debug::__base(__last));
164
          this->_M_invalidate_all();
165
        }
166
 
167
      void
168
      assign(size_type __n, const _Tp& __t)
169
      {
170
        _Base::assign(__n, __t);
171
        this->_M_invalidate_all();
172
      }
173
 
174
#if __cplusplus >= 201103L
175
      void
176
      assign(initializer_list __l)
177
      {
178
        _Base::assign(__l);
179
        this->_M_invalidate_all();
180
      }
181
#endif
182
 
183
      using _Base::get_allocator;
184
 
185
      // iterators:
186
      iterator
187
      begin() _GLIBCXX_NOEXCEPT
188
      { return iterator(_Base::begin(), this); }
189
 
190
      const_iterator
191
      begin() const _GLIBCXX_NOEXCEPT
192
      { return const_iterator(_Base::begin(), this); }
193
 
194
      iterator
195
      end() _GLIBCXX_NOEXCEPT
196
      { return iterator(_Base::end(), this); }
197
 
198
      const_iterator
199
      end() const _GLIBCXX_NOEXCEPT
200
      { return const_iterator(_Base::end(), this); }
201
 
202
      reverse_iterator
203
      rbegin() _GLIBCXX_NOEXCEPT
204
      { return reverse_iterator(end()); }
205
 
206
      const_reverse_iterator
207
      rbegin() const _GLIBCXX_NOEXCEPT
208
      { return const_reverse_iterator(end()); }
209
 
210
      reverse_iterator
211
      rend() _GLIBCXX_NOEXCEPT
212
      { return reverse_iterator(begin()); }
213
 
214
      const_reverse_iterator
215
      rend() const _GLIBCXX_NOEXCEPT
216
      { return const_reverse_iterator(begin()); }
217
 
218
#if __cplusplus >= 201103L
219
      const_iterator
220
      cbegin() const noexcept
221
      { return const_iterator(_Base::begin(), this); }
222
 
223
      const_iterator
224
      cend() const noexcept
225
      { return const_iterator(_Base::end(), this); }
226
 
227
      const_reverse_iterator
228
      crbegin() const noexcept
229
      { return const_reverse_iterator(end()); }
230
 
231
      const_reverse_iterator
232
      crend() const noexcept
233
      { return const_reverse_iterator(begin()); }
234
#endif
235
 
236
    private:
237
      void
238
      _M_invalidate_after_nth(difference_type __n)
239
      {
240
        typedef __gnu_debug::_After_nth_from<_Base_const_iterator> _After_nth;
241
        this->_M_invalidate_if(_After_nth(__n, _Base::begin()));
242
      }
243
 
244
    public:
245
      // 23.2.1.2 capacity:
246
      using _Base::size;
247
      using _Base::max_size;
248
 
249
#if __cplusplus >= 201103L
250
      void
251
      resize(size_type __sz)
252
      {
253
        bool __invalidate_all = __sz > this->size();
254
        if (__sz < this->size())
255
          this->_M_invalidate_after_nth(__sz);
256
 
257
        _Base::resize(__sz);
258
 
259
        if (__invalidate_all)
260
          this->_M_invalidate_all();
261
      }
262
 
263
      void
264
      resize(size_type __sz, const _Tp& __c)
265
      {
266
        bool __invalidate_all = __sz > this->size();
267
        if (__sz < this->size())
268
          this->_M_invalidate_after_nth(__sz);
269
 
270
        _Base::resize(__sz, __c);
271
 
272
        if (__invalidate_all)
273
          this->_M_invalidate_all();
274
      }
275
#else
276
      void
277
      resize(size_type __sz, _Tp __c = _Tp())
278
      {
279
        bool __invalidate_all = __sz > this->size();
280
        if (__sz < this->size())
281
          this->_M_invalidate_after_nth(__sz);
282
 
283
        _Base::resize(__sz, __c);
284
 
285
        if (__invalidate_all)
286
          this->_M_invalidate_all();
287
      }
288
#endif
289
 
290
#if __cplusplus >= 201103L
291
      void
292
      shrink_to_fit()
293
      {
294
        if (_Base::_M_shrink_to_fit())
295
          this->_M_invalidate_all();
296
      }
297
#endif
298
 
299
      using _Base::empty;
300
 
301
      // element access:
302
      reference
303
      operator[](size_type __n)
304
      {
305
        __glibcxx_check_subscript(__n);
306
        return _M_base()[__n];
307
      }
308
 
309
      const_reference
310
      operator[](size_type __n) const
311
      {
312
        __glibcxx_check_subscript(__n);
313
        return _M_base()[__n];
314
      }
315
 
316
      using _Base::at;
317
 
318
      reference
319
      front()
320
      {
321
        __glibcxx_check_nonempty();
322
        return _Base::front();
323
      }
324
 
325
      const_reference
326
      front() const
327
      {
328
        __glibcxx_check_nonempty();
329
        return _Base::front();
330
      }
331
 
332
      reference
333
      back()
334
      {
335
        __glibcxx_check_nonempty();
336
        return _Base::back();
337
      }
338
 
339
      const_reference
340
      back() const
341
      {
342
        __glibcxx_check_nonempty();
343
        return _Base::back();
344
      }
345
 
346
      // 23.2.1.3 modifiers:
347
      void
348
      push_front(const _Tp& __x)
349
      {
350
        _Base::push_front(__x);
351
        this->_M_invalidate_all();
352
      }
353
 
354
      void
355
      push_back(const _Tp& __x)
356
      {
357
        _Base::push_back(__x);
358
        this->_M_invalidate_all();
359
      }
360
 
361
#if __cplusplus >= 201103L
362
      void
363
      push_front(_Tp&& __x)
364
      { emplace_front(std::move(__x)); }
365
 
366
      void
367
      push_back(_Tp&& __x)
368
      { emplace_back(std::move(__x)); }
369
 
370
      template
371
        void
372
        emplace_front(_Args&&... __args)
373
        {
374
          _Base::emplace_front(std::forward<_Args>(__args)...);
375
          this->_M_invalidate_all();
376
        }
377
 
378
      template
379
        void
380
        emplace_back(_Args&&... __args)
381
        {
382
          _Base::emplace_back(std::forward<_Args>(__args)...);
383
          this->_M_invalidate_all();
384
        }
385
 
386
      template
387
        iterator
388
        emplace(iterator __position, _Args&&... __args)
389
        {
390
          __glibcxx_check_insert(__position);
391
          _Base_iterator __res = _Base::emplace(__position.base(),
392
                                                std::forward<_Args>(__args)...);
393
          this->_M_invalidate_all();
394
          return iterator(__res, this);
395
        }
396
#endif
397
 
398
      iterator
399
      insert(iterator __position, const _Tp& __x)
400
      {
401
        __glibcxx_check_insert(__position);
402
        _Base_iterator __res = _Base::insert(__position.base(), __x);
403
        this->_M_invalidate_all();
404
        return iterator(__res, this);
405
      }
406
 
407
#if __cplusplus >= 201103L
408
      iterator
409
      insert(iterator __position, _Tp&& __x)
410
      { return emplace(__position, std::move(__x)); }
411
 
412
      void
413
      insert(iterator __p, initializer_list __l)
414
      {
415
        _Base::insert(__p, __l);
416
        this->_M_invalidate_all();
417
      }
418
#endif
419
 
420
      void
421
      insert(iterator __position, size_type __n, const _Tp& __x)
422
      {
423
        __glibcxx_check_insert(__position);
424
        _Base::insert(__position.base(), __n, __x);
425
        this->_M_invalidate_all();
426
      }
427
 
428
#if __cplusplus >= 201103L
429
      template
430
               typename = std::_RequireInputIter<_InputIterator>>
431
#else
432
      template
433
#endif
434
        void
435
        insert(iterator __position,
436
               _InputIterator __first, _InputIterator __last)
437
        {
438
          __glibcxx_check_insert_range(__position, __first, __last);
439
          _Base::insert(__position.base(), __gnu_debug::__base(__first),
440
                                           __gnu_debug::__base(__last));
441
          this->_M_invalidate_all();
442
        }
443
 
444
      void
445
      pop_front()
446
      {
447
        __glibcxx_check_nonempty();
448
        this->_M_invalidate_if(_Equal(_Base::begin()));
449
        _Base::pop_front();
450
      }
451
 
452
      void
453
      pop_back()
454
      {
455
        __glibcxx_check_nonempty();
456
        this->_M_invalidate_if(_Equal(--_Base::end()));
457
        _Base::pop_back();
458
      }
459
 
460
      iterator
461
      erase(iterator __position)
462
      {
463
        __glibcxx_check_erase(__position);
464
        _Base_iterator __victim = __position.base();
465
        if (__victim == _Base::begin() || __victim == _Base::end()-1)
466
          {
467
            this->_M_invalidate_if(_Equal(__victim));
468
            return iterator(_Base::erase(__victim), this);
469
          }
470
        else
471
          {
472
            _Base_iterator __res = _Base::erase(__victim);
473
            this->_M_invalidate_all();
474
            return iterator(__res, this);
475
          }
476
      }
477
 
478
      iterator
479
      erase(iterator __first, iterator __last)
480
      {
481
        // _GLIBCXX_RESOLVE_LIB_DEFECTS
482
        // 151. can't currently clear() empty container
483
        __glibcxx_check_erase_range(__first, __last);
484
 
485
        if (__first.base() == __last.base())
486
          return __first;
487
        else if (__first.base() == _Base::begin()
488
                 || __last.base() == _Base::end())
489
          {
490
            this->_M_detach_singular();
491
            for (_Base_iterator __position = __first.base();
492
                 __position != __last.base(); ++__position)
493
              {
494
                this->_M_invalidate_if(_Equal(__position));
495
              }
496
            __try
497
              {
498
                return iterator(_Base::erase(__first.base(), __last.base()),
499
                                this);
500
              }
501
            __catch(...)
502
              {
503
                this->_M_revalidate_singular();
504
                __throw_exception_again;
505
              }
506
          }
507
        else
508
          {
509
            _Base_iterator __res = _Base::erase(__first.base(),
510
                                                __last.base());
511
            this->_M_invalidate_all();
512
            return iterator(__res, this);
513
          }
514
      }
515
 
516
      void
517
      swap(deque& __x)
518
      {
519
        _Base::swap(__x);
520
        this->_M_swap(__x);
521
      }
522
 
523
      void
524
      clear() _GLIBCXX_NOEXCEPT
525
      {
526
        _Base::clear();
527
        this->_M_invalidate_all();
528
      }
529
 
530
      _Base&
531
      _M_base() _GLIBCXX_NOEXCEPT       { return *this; }
532
 
533
      const _Base&
534
      _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
535
    };
536
 
537
  template
538
    inline bool
539
    operator==(const deque<_Tp, _Alloc>& __lhs,
540
               const deque<_Tp, _Alloc>& __rhs)
541
    { return __lhs._M_base() == __rhs._M_base(); }
542
 
543
  template
544
    inline bool
545
    operator!=(const deque<_Tp, _Alloc>& __lhs,
546
               const deque<_Tp, _Alloc>& __rhs)
547
    { return __lhs._M_base() != __rhs._M_base(); }
548
 
549
  template
550
    inline bool
551
    operator<(const deque<_Tp, _Alloc>& __lhs,
552
              const deque<_Tp, _Alloc>& __rhs)
553
    { return __lhs._M_base() < __rhs._M_base(); }
554
 
555
  template
556
    inline bool
557
    operator<=(const deque<_Tp, _Alloc>& __lhs,
558
               const deque<_Tp, _Alloc>& __rhs)
559
    { return __lhs._M_base() <= __rhs._M_base(); }
560
 
561
  template
562
    inline bool
563
    operator>=(const deque<_Tp, _Alloc>& __lhs,
564
               const deque<_Tp, _Alloc>& __rhs)
565
    { return __lhs._M_base() >= __rhs._M_base(); }
566
 
567
  template
568
    inline bool
569
    operator>(const deque<_Tp, _Alloc>& __lhs,
570
              const deque<_Tp, _Alloc>& __rhs)
571
    { return __lhs._M_base() > __rhs._M_base(); }
572
 
573
  template
574
    inline void
575
    swap(deque<_Tp, _Alloc>& __lhs, deque<_Tp, _Alloc>& __rhs)
576
    { __lhs.swap(__rhs); }
577
 
578
} // namespace __debug
579
} // namespace std
580
 
581
#endif

powered by: WebSVN 2.1.0

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