epoc32/include/tools/stlport/stl/debug/_deque.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     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_DEQUE_H
    31 #define _STLP_INTERNAL_DBG_DEQUE_H
    32 
    33 #ifndef _STLP_DBG_ITERATOR_H
    34 #  include <stl/debug/_iterator.h>
    35 #endif
    36 
    37 #define _STLP_NON_DBG_DEQUE _STLP_PRIV _STLP_NON_DBG_NAME(deque) <_Tp,_Alloc>
    38 
    39 _STLP_BEGIN_NAMESPACE
    40 
    41 #if defined (_STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS)
    42 template <class _Tp, class _Alloc>
    43 inline _Tp* value_type(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_DEQUE >&)
    44 { return (_Tp*)0; }
    45 template <class _Tp, class _Alloc>
    46 inline random_access_iterator_tag iterator_category(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_DEQUE >&)
    47 { return random_access_iterator_tag(); }
    48 #endif
    49 
    50 template <class _Tp, _STLP_DBG_ALLOCATOR_SELECT(_Tp) >
    51 class deque :
    52 #if !defined (__DMC__)
    53              private
    54 #endif
    55                      _STLP_PRIV __construct_checker<_STLP_NON_DBG_DEQUE >
    56 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
    57             , public __stlport_class<deque<_Tp, _Alloc> >
    58 #endif
    59 {
    60   typedef deque<_Tp,_Alloc> _Self;
    61   typedef _STLP_NON_DBG_DEQUE _Base;
    62   typedef _STLP_PRIV __construct_checker<_STLP_NON_DBG_DEQUE > _ConstructCheck;
    63 
    64 public:
    65   // Basic types
    66   __IMPORT_CONTAINER_TYPEDEFS(_Base)
    67 
    68   // Iterators
    69   typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _DbgTraits<_Nonconst_traits<value_type> > > iterator;
    70   typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _DbgTraits<_Const_traits<value_type> > >    const_iterator;
    71 
    72   _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
    73 
    74 protected:
    75   _Base _M_non_dbg_impl;
    76   _STLP_PRIV __owned_list _M_iter_list;
    77 
    78   void _Invalidate_iterator(const iterator& __it)
    79   { _STLP_PRIV __invalidate_iterator(&_M_iter_list,__it); }
    80   void _Invalidate_all()
    81   { _M_iter_list._Invalidate_all(); }
    82 
    83 public:
    84   // Basic accessors
    85   allocator_type get_allocator() const { return _M_non_dbg_impl.get_allocator(); }
    86 
    87   iterator begin() { return iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
    88   iterator end() { return iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
    89   const_iterator begin() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
    90   const_iterator end() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
    91 
    92   reverse_iterator rbegin() { return reverse_iterator(end()); }
    93   reverse_iterator rend() { return reverse_iterator(begin()); }
    94   const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
    95   const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
    96 
    97   reference operator[](size_type __n) {
    98     _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
    99     return _M_non_dbg_impl[__n];
   100   }
   101   const_reference operator[](size_type __n) const {
   102     _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
   103     return _M_non_dbg_impl[__n];
   104   }
   105 
   106   reference at(size_type __n) { return _M_non_dbg_impl.at(__n); }
   107   const_reference at(size_type __n) const { return _M_non_dbg_impl.at(__n); }
   108 
   109   reference front() {
   110     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
   111     return *begin();
   112   }
   113   const_reference front() const {
   114     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
   115     return *begin();
   116   }
   117   reference back() {
   118     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
   119     return *(--end());
   120   }
   121   const_reference back() const {
   122     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
   123     return *(--end());
   124   }
   125 
   126   // Constructor, destructor.
   127   explicit deque(const allocator_type& __a = allocator_type()) :
   128     _M_non_dbg_impl(__a), _M_iter_list(&_M_non_dbg_impl) {}
   129   deque(const _Self& __x) :
   130     _ConstructCheck(__x), _M_non_dbg_impl(__x._M_non_dbg_impl),
   131     _M_iter_list(&_M_non_dbg_impl) {}
   132 
   133 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
   134   explicit deque(size_type __n, const value_type& __x = _Tp(),
   135 #else
   136   deque(size_type __n, param_type __x,
   137 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
   138             const allocator_type& __a = allocator_type()) :
   139     _M_non_dbg_impl(__n, __x, __a), _M_iter_list(&_M_non_dbg_impl) {}
   140 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
   141   explicit deque(size_type __n) :
   142     _M_non_dbg_impl(__n), _M_iter_list(&_M_non_dbg_impl) {}
   143 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
   144 
   145   deque(__move_source<_Self> src)
   146     : _M_non_dbg_impl(__move_source<_Base>(src.get()._M_non_dbg_impl)),
   147       _M_iter_list(&_M_non_dbg_impl) {
   148 #if defined (_STLP_NO_EXTENSIONS) || (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
   149     src.get()._M_iter_list._Invalidate_all();
   150 #else
   151     src.get()._M_iter_list._Set_owner(_M_iter_list);
   152 #endif
   153   }
   154 
   155 #if defined (_STLP_MEMBER_TEMPLATES)
   156   template <class _InputIterator>
   157   deque(_InputIterator __first, _InputIterator __last,
   158         const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
   159     : _ConstructCheck(__first, __last),
   160       _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last), __a),
   161       _M_iter_list(&_M_non_dbg_impl) {
   162     }
   163 #  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
   164   template <class _InputIterator>
   165   deque(_InputIterator __first, _InputIterator __last)
   166     : _ConstructCheck(__first, __last),
   167       _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last)),
   168       _M_iter_list(&_M_non_dbg_impl) {
   169     }
   170 #  endif
   171 #else
   172   deque(const value_type* __first, const value_type* __last,
   173         const allocator_type& __a = allocator_type())
   174     : _ConstructCheck(__first, __last),
   175       _M_non_dbg_impl(__first, __last, __a),
   176       _M_iter_list(&_M_non_dbg_impl) {
   177     }
   178 
   179   deque(const_iterator __first, const_iterator __last,
   180         const allocator_type& __a = allocator_type())
   181     : _ConstructCheck(__first, __last),
   182       _M_non_dbg_impl(__first._M_iterator, __last._M_iterator, __a),
   183       _M_iter_list(&_M_non_dbg_impl) {
   184     }
   185 #endif
   186 
   187   _Self& operator=(const _Self& __x) {
   188     if (this != &__x) {
   189       _Invalidate_all();
   190       _M_non_dbg_impl = __x._M_non_dbg_impl;
   191     }
   192     return *this;
   193   }
   194 
   195   bool empty() const { return _M_non_dbg_impl.empty(); }
   196   size_type size() const { return _M_non_dbg_impl.size(); }
   197   size_type max_size() const { return _M_non_dbg_impl.max_size(); }
   198 
   199   void swap(_Self& __x) {
   200     _M_iter_list._Swap_owners(__x._M_iter_list);
   201     _M_non_dbg_impl.swap(__x._M_non_dbg_impl);
   202   }
   203 
   204 public:
   205   void assign(size_type __n, const _Tp& __val) {
   206     _Invalidate_all();
   207     _M_non_dbg_impl.assign(__n, __val);
   208   }
   209 
   210 #if defined (_STLP_MEMBER_TEMPLATES)
   211   template <class _InputIterator>
   212   void assign(_InputIterator __first, _InputIterator __last) {
   213     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
   214     _Invalidate_all();
   215     _M_non_dbg_impl.assign(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
   216   }
   217 #else
   218   void assign(const_iterator __first, const_iterator __last) {
   219     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
   220     _Invalidate_all();
   221     _M_non_dbg_impl.assign(__first._M_iterator, __last._M_iterator);
   222   }
   223   void assign(const value_type *__first, const value_type *__last) {
   224     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first, __last))
   225     _Invalidate_all();
   226     _M_non_dbg_impl.assign(__first, __last);
   227   }
   228 #endif
   229 
   230 public:                         // push_* and pop_*
   231 
   232 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
   233   void push_back(const value_type& __t = _Tp()) {
   234 #else
   235   void push_back(const value_type& __t) {
   236 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
   237     _Invalidate_all();
   238     _M_non_dbg_impl.push_back(__t);
   239   }
   240 
   241 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
   242   void push_back() {
   243     _Invalidate_all();
   244     _M_non_dbg_impl.push_back();
   245   }
   246 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
   247 
   248 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
   249   void push_front(const value_type& __t = _Tp()) {
   250 #else
   251   void push_front(const value_type& __t) {
   252 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
   253     _Invalidate_all();
   254     _M_non_dbg_impl.push_front(__t);
   255   }
   256 
   257 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
   258   void push_front() {
   259     _Invalidate_all();
   260     _M_non_dbg_impl.push_front();
   261   }
   262 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
   263 
   264   void pop_back() {
   265     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
   266     _Invalidate_iterator(end());
   267     _M_non_dbg_impl.pop_back();
   268   }
   269 
   270   void pop_front() {
   271     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
   272     _Invalidate_iterator(begin());
   273     _M_non_dbg_impl.pop_front();
   274   }
   275 
   276 public:                         // Insert
   277 
   278 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
   279   iterator insert(iterator __pos, const value_type& __x = _Tp()) {
   280 #else
   281   iterator insert(iterator __pos, const value_type& __x) {
   282 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
   283     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
   284     _Invalidate_all();
   285     return iterator(&_M_iter_list, _M_non_dbg_impl.insert(__pos._M_iterator, __x));
   286   }
   287 
   288 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
   289   iterator insert(iterator __pos) {
   290     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
   291     _Invalidate_all();
   292     return iterator(&_M_iter_list, _M_non_dbg_impl.insert(__pos._M_iterator));
   293   }
   294 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
   295 
   296   void insert(iterator __pos, size_type __n, const value_type& __x) {
   297     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
   298     if (__n != 0) _Invalidate_all();
   299     _M_non_dbg_impl.insert(__pos._M_iterator, __n, __x);
   300   }
   301 
   302 #if defined (_STLP_MEMBER_TEMPLATES)
   303   template <class _InputIterator>
   304   void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
   305     typedef typename _AreSameUnCVTypes<_InputIterator, iterator>::_Ret _IsNonConstIterator;
   306     typedef typename _AreSameUnCVTypes<_InputIterator, const_iterator>::_Ret _IsConstIterator;
   307     typedef typename _Lor2<_IsNonConstIterator, _IsConstIterator>::_Ret _DoCheck;
   308     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
   309     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
   310     //Sequence requirements 23.1.1 Table 67:
   311     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first, _DoCheck()));
   312     _M_non_dbg_impl.insert(__pos._M_iterator,
   313                            _STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
   314     //dums: because of self insertion iterators must be invalidated after insertion.
   315     if (__first != __last) _Invalidate_all();
   316   }
   317 #else
   318   void insert(iterator __pos,
   319               const value_type* __first, const value_type* __last) {
   320     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
   321     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first, __last))
   322     _M_non_dbg_impl.insert(__pos._M_iterator, __first, __last);
   323     //dums: because of self insertion iterators must be invalidated after insertion.
   324     if (__first != __last) _Invalidate_all();
   325   }
   326   void insert(iterator __pos,
   327               const_iterator __first, const_iterator __last) {
   328     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
   329     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
   330     //Sequence requirements 23.1.1 Table 67:
   331     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first, __true_type()));
   332     _M_non_dbg_impl.insert(__pos._M_iterator, __first._M_iterator, __last._M_iterator);
   333     //dums: because of self insertion iterators must be invalidated after insertion.
   334     if (__first != __last) _Invalidate_all();
   335   }
   336 #endif
   337 
   338 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
   339   void resize(size_type __new_size, const value_type& __x = _Tp()) {
   340 #else
   341   void resize(size_type __new_size, const value_type& __x) {
   342 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
   343     if (__new_size != size()) {
   344       if ((__new_size > size()) || (__new_size < size() - 1))
   345         _Invalidate_all();
   346       else
   347         _Invalidate_iterator(end());
   348     }
   349     _M_non_dbg_impl.resize(__new_size, __x);
   350   }
   351 
   352 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
   353   void resize(size_type new_size) { resize(new_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
   354 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
   355 
   356   // Erase
   357   iterator erase(iterator __pos) {
   358     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
   359     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
   360     if (__pos == begin())
   361       _Invalidate_iterator(__pos);
   362     else {
   363       iterator __tmp = --(end());
   364       if (__pos == __tmp)
   365         _Invalidate_iterator(__pos);
   366       else
   367         _Invalidate_all();
   368     }
   369     return iterator (&_M_iter_list, _M_non_dbg_impl.erase(__pos._M_iterator));
   370   }
   371 
   372   iterator erase(iterator __first, iterator __last) {
   373     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last, begin(), end()))
   374     if (!empty()) {
   375       if (__last == (++(begin())))
   376         _Invalidate_iterator(__last);
   377       else {
   378         if (__first == (--(end())))
   379           _Invalidate_iterator(__first);
   380         else
   381           _Invalidate_all();
   382       }
   383     }
   384     return iterator (&_M_iter_list, _M_non_dbg_impl.erase(__first._M_iterator, __last._M_iterator));
   385   }
   386 
   387   void clear() {
   388     _Invalidate_all();
   389     _M_non_dbg_impl.clear();
   390   }
   391 };
   392 
   393 _STLP_END_NAMESPACE
   394 
   395 #undef _STLP_NON_DBG_DEQUE
   396 
   397 #endif /* _STLP_INTERNAL_DEQUE_H */
   398 
   399 // Local Variables:
   400 // mode:C++
   401 // End: