epoc32/include/tools/stlport/stl/debug/_vector.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_VECTOR_H
    31 #define _STLP_INTERNAL_DBG_VECTOR_H
    32 
    33 #ifndef _STLP_DBG_ITERATOR_H
    34 #  include <stl/debug/_iterator.h>
    35 #endif
    36 
    37 #define _STLP_NON_DBG_VECTOR _STLP_PRIV _STLP_NON_DBG_NAME(vector) <_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*
    44 value_type(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_VECTOR >&)
    45 { return (_Tp*)0; }
    46 template <class _Tp, class _Alloc>
    47 inline random_access_iterator_tag
    48 iterator_category(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_VECTOR >&)
    49 { return random_access_iterator_tag(); }
    50 #endif
    51 
    52 _STLP_MOVE_TO_PRIV_NAMESPACE
    53 
    54 template <class _Tp, class _NcIt>
    55 struct _Vector_const_traits;
    56 
    57 template <class _Tp, class _NcIt>
    58 struct _Vector_nonconst_traits {
    59   typedef _Nonconst_traits<_Tp> _BaseT;
    60   typedef _Tp value_type;
    61   typedef _Tp& reference;
    62   typedef _Tp* pointer;
    63   typedef _Vector_const_traits<_Tp, _NcIt> _ConstTraits;
    64   typedef _Vector_nonconst_traits<_Tp, _NcIt> _NonConstTraits;
    65 };
    66 
    67 template <class _Tp, class _NcIt>
    68 struct _Vector_const_traits {
    69   typedef _Const_traits<_Tp> _BaseT;
    70   typedef _Tp value_type;
    71   typedef const _Tp& reference;
    72   typedef const _Tp* pointer;
    73   typedef _Vector_const_traits<_Tp, _NcIt> _ConstTraits;
    74   typedef _Vector_nonconst_traits<_Tp, _NcIt> _NonConstTraits;
    75 };
    76 
    77 _STLP_TEMPLATE_NULL
    78 struct _Vector_nonconst_traits<bool, _Bit_iterator> {
    79   typedef _Bit_iterator::value_type value_type;
    80   typedef _Bit_iterator::reference reference;
    81   typedef _Bit_iterator::pointer pointer;
    82   typedef _Vector_const_traits<bool, _Bit_iterator> _ConstTraits;
    83   typedef _Vector_nonconst_traits<bool, _Bit_iterator> _NonConstTraits;
    84 };
    85 
    86 _STLP_TEMPLATE_NULL
    87 struct _Vector_const_traits<bool, _Bit_iterator> {
    88   typedef _Bit_const_iterator::value_type value_type;
    89   typedef _Bit_const_iterator::reference reference;
    90   typedef _Bit_const_iterator::pointer pointer;
    91   typedef _Vector_const_traits<bool, _Bit_iterator> _ConstTraits;
    92   typedef _Vector_nonconst_traits<bool, _Bit_iterator> _NonConstTraits;
    93 };
    94 
    95 _STLP_MOVE_TO_STD_NAMESPACE
    96 
    97 template <class _Tp, _STLP_DBG_ALLOCATOR_SELECT(_Tp) >
    98 class vector :
    99 #if !defined (__DMC__)
   100              private
   101 #endif
   102                      _STLP_PRIV __construct_checker< _STLP_NON_DBG_VECTOR >
   103 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
   104              , public __stlport_class<vector<_Tp, _Alloc> >
   105 #endif
   106 {
   107 private:
   108   typedef _STLP_NON_DBG_VECTOR _Base;
   109   typedef vector<_Tp, _Alloc> _Self;
   110   typedef _STLP_PRIV __construct_checker<_STLP_NON_DBG_VECTOR > _ConstructCheck;
   111   _Base _M_non_dbg_impl;
   112   _STLP_PRIV __owned_list _M_iter_list;
   113 
   114 public:
   115   __IMPORT_CONTAINER_TYPEDEFS(_Base)
   116 
   117   typedef _STLP_PRIV _DBG_iter<_Base,
   118     _STLP_PRIV _DbgTraits<_STLP_PRIV _Vector_nonconst_traits<value_type, typename _Base::iterator> > > iterator;
   119 
   120   typedef _STLP_PRIV _DBG_iter<_Base,
   121     _STLP_PRIV _DbgTraits<_STLP_PRIV _Vector_const_traits<value_type, typename _Base::iterator> > > const_iterator;
   122 
   123 private:
   124   void _Invalidate_all()
   125   { _M_iter_list._Invalidate_all(); }
   126   void _Invalidate_iterator(const iterator& __it)
   127   { _STLP_PRIV __invalidate_iterator(&_M_iter_list, __it); }
   128   void _Invalidate_iterators(const iterator& __first, const iterator& __last)
   129   { _STLP_PRIV __invalidate_range(&_M_iter_list, __first, __last); }
   130 
   131   void _Check_Overflow(size_type __nb) {
   132     if (size() + __nb > capacity())
   133       _Invalidate_all();
   134   }
   135   void _Compare_Capacity (size_type __old_capacity) {
   136     if (capacity() > __old_capacity) {
   137       _Invalidate_all();
   138     }
   139   }
   140 
   141 public:
   142   _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
   143 
   144   allocator_type get_allocator() const { return _M_non_dbg_impl.get_allocator(); }
   145 
   146   iterator begin()             { return iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
   147   const_iterator begin() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
   148   iterator end()               { return iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
   149   const_iterator end() const   { return const_iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
   150 
   151   reverse_iterator rbegin()             { return reverse_iterator(end()); }
   152   const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
   153   reverse_iterator rend()               { return reverse_iterator(begin()); }
   154   const_reverse_iterator rend() const   { return const_reverse_iterator(begin()); }
   155 
   156   size_type size() const        { return _M_non_dbg_impl.size(); }
   157   size_type max_size() const    { return _M_non_dbg_impl.max_size(); }
   158   size_type capacity() const    { return _M_non_dbg_impl.capacity(); }
   159   bool empty() const            { return _M_non_dbg_impl.empty(); }
   160 
   161   reference operator[](size_type __n) {
   162     _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
   163     return _M_non_dbg_impl[__n];
   164   }
   165 
   166   const_reference operator[](size_type __n) const {
   167     _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
   168     return _M_non_dbg_impl[__n];
   169   }
   170 
   171   reference at(size_type __n) { return _M_non_dbg_impl.at(__n); }
   172   const_reference at(size_type __n) const { return _M_non_dbg_impl.at(__n); }
   173 
   174   explicit vector(const allocator_type& __a = allocator_type())
   175     : _M_non_dbg_impl(__a), _M_iter_list(&_M_non_dbg_impl)  {}
   176 
   177 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
   178   explicit vector(size_type __n, const _Tp& __x = _Tp(),
   179 #else
   180   vector(size_type __n, const _Tp& __x,
   181 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
   182          const allocator_type& __a = allocator_type())
   183     : _M_non_dbg_impl(__n, __x, __a), _M_iter_list(&_M_non_dbg_impl) {}
   184 
   185 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
   186   explicit vector(size_type __n)
   187     : _M_non_dbg_impl(__n), _M_iter_list(&_M_non_dbg_impl) {}
   188 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
   189 
   190   vector(const _Self& __x)
   191     : _ConstructCheck(__x), _M_non_dbg_impl(__x._M_non_dbg_impl), _M_iter_list(&_M_non_dbg_impl) {}
   192 
   193   vector(__move_source<_Self> src)
   194     : _M_non_dbg_impl(__move_source<_Base>(src.get()._M_non_dbg_impl)),
   195       _M_iter_list(&_M_non_dbg_impl) {
   196 #if defined (_STLP_NO_EXTENSIONS) || (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
   197     src.get()._M_iter_list._Invalidate_all();
   198 #else
   199     src.get()._M_iter_list._Set_owner(_M_iter_list);
   200 #endif
   201   }
   202 
   203 #if defined (_STLP_MEMBER_TEMPLATES)
   204   template <class _InputIterator>
   205   vector(_InputIterator __first, _InputIterator __last,
   206          const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
   207     : _ConstructCheck(__first, __last),
   208       _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last), __a),
   209       _M_iter_list(&_M_non_dbg_impl) {}
   210 
   211 #  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
   212   template <class _InputIterator>
   213   vector(_InputIterator __first, _InputIterator __last)
   214     : _ConstructCheck(__first, __last),
   215       _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last)),
   216       _M_iter_list(&_M_non_dbg_impl) {}
   217 #  endif
   218 #else
   219   vector(const _Tp* __first, const _Tp* __last,
   220          const allocator_type& __a = allocator_type())
   221     : _ConstructCheck(__first, __last), _M_non_dbg_impl(__first, __last, __a),
   222     _M_iter_list(&_M_non_dbg_impl) {}
   223 
   224   // mysterious VC++ bug ?
   225   vector(const_iterator __first, const_iterator __last ,
   226          const allocator_type& __a = allocator_type())
   227     : _ConstructCheck(__first, __last),
   228       _M_non_dbg_impl(__first._M_iterator, __last._M_iterator, __a),
   229     _M_iter_list(&_M_non_dbg_impl) {}
   230 #endif /* _STLP_MEMBER_TEMPLATES */
   231 
   232   _Self& operator=(const _Self& __x) {
   233     if (this != &__x) {
   234       _Invalidate_all();
   235       _M_non_dbg_impl = __x._M_non_dbg_impl;
   236     }
   237     return *this;
   238   }
   239 
   240   void reserve(size_type __n) {
   241     if (capacity() < __n)
   242       _Invalidate_all();
   243     _M_non_dbg_impl.reserve(__n);
   244   }
   245 
   246   reference front() {
   247     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
   248     return *begin();
   249   }
   250   const_reference front() const {
   251     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
   252     return *begin();
   253   }
   254   reference back() {
   255     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
   256     return *(--end());
   257   }
   258   const_reference back() const {
   259     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
   260     return *(--end());
   261   }
   262 
   263   void swap(_Self& __x) {
   264     _M_iter_list._Swap_owners(__x._M_iter_list);
   265     _M_non_dbg_impl.swap(__x._M_non_dbg_impl);
   266   }
   267 
   268 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
   269   iterator insert(iterator __pos, const _Tp& __x = _Tp()) {
   270 #else
   271   iterator insert(iterator __pos, const _Tp& __x) {
   272 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
   273     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
   274     _Check_Overflow(1);
   275     return iterator(&_M_iter_list, _M_non_dbg_impl.insert(__pos._M_iterator, __x));
   276   }
   277 
   278 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
   279   iterator insert(iterator __pos)
   280   { return insert(__pos, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
   281 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
   282 
   283 #if defined (_STLP_MEMBER_TEMPLATES)
   284   // Check whether it's an integral type.  If so, it's not an iterator.
   285   template <class _InputIterator>
   286   void insert(iterator __pos,
   287               _InputIterator __first, _InputIterator __last) {
   288     typedef typename _AreSameUnCVTypes<_InputIterator, iterator>::_Ret _IsNonConstIterator;
   289     typedef typename _AreSameUnCVTypes<_InputIterator, const_iterator>::_Ret _IsConstIterator;
   290     typedef typename _Lor2<_IsNonConstIterator, _IsConstIterator>::_Ret _DoCheck;
   291     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
   292     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
   293     //Sequence requirements 23.1.1 Table 67:
   294     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first, _DoCheck()));
   295     size_type __old_capacity = capacity();
   296     _M_non_dbg_impl.insert(__pos._M_iterator,
   297                            _STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
   298     _Compare_Capacity(__old_capacity);
   299   }
   300 #else
   301   void insert (iterator __pos,
   302                const value_type *__first, const value_type *__last) {
   303     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first,__last))
   304     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
   305     size_type __old_capacity = capacity();
   306     _M_non_dbg_impl.insert(__pos._M_iterator, __first, __last);
   307     _Compare_Capacity(__old_capacity);
   308   }
   309 
   310   void insert(iterator __pos,
   311               const_iterator __first, const_iterator __last) {
   312     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first,__last))
   313     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
   314     //Sequence requirements 23.1.1 Table 67:
   315     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first, __true_type()));
   316     size_type __old_capacity = capacity();
   317     _M_non_dbg_impl.insert(__pos._M_iterator, __first._M_iterator, __last._M_iterator);
   318     _Compare_Capacity(__old_capacity);
   319 }
   320 #endif
   321 
   322   void insert (iterator __pos, size_type __n, const _Tp& __x){
   323     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
   324     _Check_Overflow(__n);
   325     _M_non_dbg_impl.insert(__pos._M_iterator, __n, __x);
   326   }
   327 
   328   void pop_back() {
   329     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
   330     _Invalidate_iterator(end());
   331     _M_non_dbg_impl.pop_back();
   332   }
   333   iterator erase(iterator __pos) {
   334     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
   335     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
   336     _Invalidate_iterators(__pos, end());
   337     return iterator(&_M_iter_list, _M_non_dbg_impl.erase(__pos._M_iterator));
   338   }
   339   iterator erase(iterator __first, iterator __last) {
   340     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last, begin(), end()))
   341     _Invalidate_iterators(__first, end());
   342     return iterator(&_M_iter_list, _M_non_dbg_impl.erase(__first._M_iterator, __last._M_iterator));
   343   }
   344 
   345 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
   346   void resize(size_type __new_size, const _Tp& __x = _STLP_DEFAULT_CONSTRUCTED(_Tp)) {
   347 #else
   348   void resize(size_type __new_size, const _Tp& __x) {
   349 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
   350     if (__new_size > capacity()) {
   351       _Invalidate_all();
   352     }
   353     else if (__new_size < size()) {
   354       _Invalidate_iterators(begin() + __new_size, end());
   355     }
   356     _M_non_dbg_impl.resize(__new_size, __x);
   357   }
   358 
   359 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
   360   void resize(size_type __new_size) { resize(__new_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
   361 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
   362 
   363 #if defined (_STLP_MEMBER_TEMPLATES)
   364 private:
   365   template <class _Integer>
   366   void _M_assign_dispatch(_Integer __n, _Integer __val,
   367                           const __true_type& /*_IsIntegral*/) {
   368     _M_check_assign(__n);
   369     _M_non_dbg_impl.assign(__n, __val);
   370   }
   371 
   372   template <class _InputIter>
   373   void _M_assign_dispatch(_InputIter __first, _InputIter __last,
   374                           const __false_type& /*_IsIntegral*/) {
   375     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first,__last))
   376     size_type __len = distance(__first, __last);
   377     _M_check_assign(__len);
   378     _M_non_dbg_impl.assign(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
   379   }
   380 
   381 public:
   382   template <class _InputIterator>
   383   void assign(_InputIterator __first, _InputIterator __last) {
   384     typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
   385     _M_assign_dispatch(__first, __last, _Integral());
   386   }
   387 #else
   388 private:
   389   void _M_assign(const value_type *__first, const value_type *__last) {
   390     size_type __len = distance(__first, __last);
   391     _M_check_assign(__len);
   392     _M_non_dbg_impl.assign(__first, __last);
   393   }
   394 public:
   395   void assign(const value_type *__first, const value_type *__last) {
   396     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first,__last))
   397     _M_assign(__first, __last);
   398   }
   399 
   400   void assign(const_iterator __first, const_iterator __last) {
   401     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first,__last))
   402     _M_assign(__first._M_iterator, __last._M_iterator);
   403   }
   404 #endif
   405 
   406 private:
   407   void _M_check_assign(size_type __n) {
   408     if (__n > capacity()) {
   409       _Invalidate_all();
   410     }
   411     else if (__n < size()) {
   412       _Invalidate_iterators(begin() + __n, end());
   413     }
   414   }
   415 
   416 public:
   417   void assign(size_type __n, const _Tp& __val) {
   418     _M_check_assign(__n);
   419     _M_non_dbg_impl.assign(__n, __val);
   420   }
   421 
   422   void clear() {
   423     _Invalidate_all();
   424     _M_non_dbg_impl.clear();
   425   }
   426   void push_back(const _Tp& __x) {
   427     _Check_Overflow(1);
   428     _M_non_dbg_impl.push_back(__x);
   429   }
   430 };
   431 
   432 _STLP_END_NAMESPACE
   433 
   434 #undef _STLP_NON_DBG_VECTOR
   435 
   436 #endif /* _STLP_DBG_VECTOR_H */
   437 
   438 // Local Variables:
   439 // mode:C++
   440 // End: