epoc32/include/tools/stlport/stl/pointers/_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  * Copyright (c) 2003
     3  * Francois Dumont
     4  *
     5  * This material is provided "as is", with absolutely no warranty expressed
     6  * or implied. Any use is at your own risk.
     7  *
     8  * Permission to use or copy this software for any purpose is hereby granted
     9  * without fee, provided the above notices are retained on all copies.
    10  * Permission to modify the code and to distribute modified code is granted,
    11  * provided the above notices are retained, and a notice that the code was
    12  * modified is included with the above copyright notice.
    13  *
    14  */
    15 
    16 /* NOTE: This is an internal header file, included by other STL headers.
    17  *   You should not attempt to use it directly.
    18  */
    19 
    20 #ifndef _STLP_SPECIALIZED_VECTOR_H
    21 #define _STLP_SPECIALIZED_VECTOR_H
    22 
    23 #ifndef _STLP_POINTERS_SPEC_TOOLS_H
    24 #  include <stl/pointers/_tools.h>
    25 #endif
    26 
    27 _STLP_BEGIN_NAMESPACE
    28 
    29 #define VECTOR_IMPL _STLP_PTR_IMPL_NAME(vector)
    30 
    31 #if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
    32 _STLP_EXPORT_TEMPLATE_CLASS _STLP_PRIV _Vector_base<void*,allocator<void*> >;
    33 _STLP_EXPORT_TEMPLATE_CLASS _STLP_PRIV VECTOR_IMPL<void*, allocator<void*> >;
    34 #endif
    35 
    36 #if defined (_STLP_DEBUG)
    37 #  define vector _STLP_NON_DBG_NAME(vector)
    38 _STLP_MOVE_TO_PRIV_NAMESPACE
    39 #endif
    40 
    41 template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) >
    42 class vector
    43 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (vector)
    44              : public __stlport_class<vector<_Tp, _Alloc> >
    45 #endif
    46 {
    47   /* In the vector implementation iterators are pointer which give a number
    48    * of opportunities for optimization. To not break those optimizations
    49    * iterators passed to template should not be wrapped for casting purpose.
    50    * So vector implementation will always use a qualified void pointer type and
    51    * won't use iterator wrapping.
    52    */
    53   typedef typename _STLP_PRIV _StorageType<_Tp>::_QualifiedType _StorageType;
    54   typedef typename _Alloc_traits<_StorageType, _Alloc>::allocator_type _StorageTypeAlloc;
    55   typedef _STLP_PRIV VECTOR_IMPL<_StorageType, _StorageTypeAlloc> _Base;
    56   typedef vector<_Tp, _Alloc> _Self;
    57 
    58   typedef _STLP_PRIV _CastTraits<_StorageType, _Tp> cast_traits;
    59 
    60 public:
    61   typedef _Tp value_type;
    62   typedef value_type* pointer;
    63   typedef const value_type* const_pointer;
    64   typedef value_type* iterator;
    65   typedef const value_type* const_iterator;
    66   typedef value_type& reference;
    67   typedef const value_type& const_reference;
    68   typedef size_t size_type;
    69   typedef ptrdiff_t difference_type;
    70   typedef random_access_iterator_tag _Iterator_category;
    71 
    72   _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
    73   _STLP_FORCE_ALLOCATORS(value_type, _Alloc)
    74   typedef typename _Alloc_traits<value_type, _Alloc>::allocator_type allocator_type;
    75 
    76   allocator_type get_allocator() const
    77   { return _STLP_CONVERT_ALLOCATOR(_M_impl.get_allocator(), value_type); }
    78 
    79   iterator begin()             { return cast_traits::to_value_type_ptr(_M_impl.begin()); }
    80   const_iterator begin() const { return cast_traits::to_value_type_cptr(_M_impl.begin()); }
    81   iterator end()               { return cast_traits::to_value_type_ptr(_M_impl.end()); }
    82   const_iterator end() const   { return cast_traits::to_value_type_cptr(_M_impl.end()); }
    83 
    84   reverse_iterator rbegin()              { return reverse_iterator(end()); }
    85   const_reverse_iterator rbegin() const  { return const_reverse_iterator(end()); }
    86   reverse_iterator rend()                { return reverse_iterator(begin()); }
    87   const_reverse_iterator rend() const    { return const_reverse_iterator(begin()); }
    88 
    89   size_type size() const        { return _M_impl.size(); }
    90   size_type max_size() const    { return _M_impl.max_size(); }
    91 
    92   size_type capacity() const    { return _M_impl.capacity(); }
    93   bool empty() const            { return _M_impl.empty(); }
    94 
    95   reference operator[](size_type __n) { return cast_traits::to_value_type_ref(_M_impl[__n]); }
    96   const_reference operator[](size_type __n) const { return cast_traits::to_value_type_cref(_M_impl[__n]); }
    97 
    98   reference front()             { return cast_traits::to_value_type_ref(_M_impl.front()); }
    99   const_reference front() const { return cast_traits::to_value_type_cref(_M_impl.front()); }
   100   reference back()              { return cast_traits::to_value_type_ref(_M_impl.back()); }
   101   const_reference back() const  { return cast_traits::to_value_type_cref(_M_impl.back()); }
   102 
   103   reference at(size_type __n) { return cast_traits::to_value_type_ref(_M_impl.at(__n)); }
   104   const_reference at(size_type __n) const { return cast_traits::to_value_type_cref(_M_impl.at(__n)); }
   105 
   106   explicit vector(const allocator_type& __a = allocator_type())
   107     : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
   108 
   109 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
   110   explicit vector(size_type __n, const value_type& __val = _STLP_DEFAULT_CONSTRUCTED(value_type),
   111 #else
   112   vector(size_type __n, const value_type& __val,
   113 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
   114          const allocator_type& __a = allocator_type())
   115     : _M_impl(__n, cast_traits::to_storage_type_cref(__val),
   116       _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
   117 
   118 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
   119   explicit vector(size_type __n)
   120     : _M_impl(__n, allocator_type() ) {}
   121 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
   122 
   123   vector(const _Self& __x)
   124     : _M_impl(__x._M_impl) {}
   125 
   126   explicit vector(__move_source<_Self> src)
   127     : _M_impl(__move_source<_Base>(src.get()._M_impl)) {}
   128 
   129 #if defined (_STLP_MEMBER_TEMPLATES)
   130   template <class _InputIterator>
   131   vector(_InputIterator __first, _InputIterator __last,
   132          const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL )
   133   : _M_impl(__first, __last,
   134             _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
   135 
   136 #  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
   137   template <class _InputIterator>
   138   vector(_InputIterator __first, _InputIterator __last)
   139     : _M_impl(__first, __last) {}
   140 #  endif
   141 
   142 #else
   143   vector(const_iterator __first, const_iterator __last,
   144          const allocator_type& __a = allocator_type())
   145     : _M_impl(cast_traits::to_storage_type_cptr(__first), cast_traits::to_storage_type_cptr(__last),
   146               _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
   147 #endif /* _STLP_MEMBER_TEMPLATES */
   148 
   149   _Self& operator=(const _Self& __x) { _M_impl = __x._M_impl; return *this; }
   150 
   151   void reserve(size_type __n) {_M_impl.reserve(__n);}
   152   void assign(size_type __n, const value_type& __val)
   153   { _M_impl.assign(__n, cast_traits::to_storage_type_cref(__val)); }
   154 
   155 #if defined (_STLP_MEMBER_TEMPLATES)
   156   template <class _InputIterator>
   157   void assign(_InputIterator __first, _InputIterator __last)
   158   { _M_impl.assign(__first, __last); }
   159 #else
   160   void assign(const_iterator __first, const_iterator __last) {
   161     _M_impl.assign(cast_traits::to_storage_type_cptr(__first),
   162                    cast_traits::to_storage_type_cptr(__last));
   163   }
   164 #endif /* _STLP_MEMBER_TEMPLATES */
   165 
   166 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
   167   void push_back(const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
   168 #else
   169   void push_back(const value_type& __x)
   170 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
   171   { _M_impl.push_back(cast_traits::to_storage_type_cref(__x)); }
   172 
   173 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
   174   iterator insert(iterator __pos, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
   175 #else
   176   iterator insert(iterator __pos, const value_type& __x)
   177 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
   178   { return cast_traits::to_value_type_ptr(_M_impl.insert(cast_traits::to_storage_type_ptr(__pos),
   179                                                          cast_traits::to_storage_type_cref(__x))); }
   180 
   181 #if defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
   182   void push_back() { _M_impl.push_back(); }
   183   iterator insert(iterator __pos)
   184   { return _M_impl.insert(cast_traits::to_storage_type_ptr(__pos)); }
   185 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
   186 
   187   void swap(_Self& __x) { _M_impl.swap(__x._M_impl); }
   188 
   189 #if defined (_STLP_MEMBER_TEMPLATES)
   190   template <class _InputIterator>
   191   void insert(iterator __pos, _InputIterator __first, _InputIterator __last)
   192   { _M_impl.insert(cast_traits::to_storage_type_ptr(__pos), __first, __last); }
   193 #else
   194   void insert(iterator __pos, const_iterator __first, const_iterator __last) {
   195     _M_impl.insert(cast_traits::to_storage_type_ptr(__pos), cast_traits::to_storage_type_cptr(__first),
   196                                                             cast_traits::to_storage_type_cptr(__last));
   197   }
   198 #endif
   199 
   200   void insert (iterator __pos, size_type __n, const value_type& __x) {
   201     _M_impl.insert(cast_traits::to_storage_type_ptr(__pos), __n, cast_traits::to_storage_type_cref(__x));
   202   }
   203 
   204   void pop_back() {_M_impl.pop_back();}
   205   iterator erase(iterator __pos)
   206   {return cast_traits::to_value_type_ptr(_M_impl.erase(cast_traits::to_storage_type_ptr(__pos)));}
   207   iterator erase(iterator __first, iterator __last) {
   208     return cast_traits::to_value_type_ptr(_M_impl.erase(cast_traits::to_storage_type_ptr(__first),
   209                                                         cast_traits::to_storage_type_ptr(__last)));
   210   }
   211 
   212 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
   213   void resize(size_type __new_size, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
   214 #else
   215   void resize(size_type __new_size, const value_type& __x)
   216 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
   217   { _M_impl.resize(__new_size, cast_traits::to_storage_type_cref(__x)); }
   218 
   219 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
   220   void resize(size_type __new_size) { _M_impl.resize(__new_size); }
   221 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
   222 
   223   void clear() { _M_impl.clear(); }
   224 
   225 private:
   226   _Base _M_impl;
   227 };
   228 
   229 #if defined (vector)
   230 #  undef vector
   231 _STLP_MOVE_TO_STD_NAMESPACE
   232 #endif
   233 
   234 #undef VECTOR_IMPL
   235 
   236 _STLP_END_NAMESPACE
   237 
   238 #endif /* _STLP_SPECIALIZED_VECTOR_H */