epoc32/include/tools/stlport/stl/_vector.c
branchSymbian3
changeset 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/tools/stlport/stl/_vector.c	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -0,0 +1,235 @@
     1.4 +/*
     1.5 + *
     1.6 + *
     1.7 + * Copyright (c) 1994
     1.8 + * Hewlett-Packard Company
     1.9 + *
    1.10 + * Copyright (c) 1996,1997
    1.11 + * Silicon Graphics Computer Systems, Inc.
    1.12 + *
    1.13 + * Copyright (c) 1997
    1.14 + * Moscow Center for SPARC Technology
    1.15 + *
    1.16 + * Copyright (c) 1999
    1.17 + * Boris Fomitchev
    1.18 + *
    1.19 + * This material is provided "as is", with absolutely no warranty expressed
    1.20 + * or implied. Any use is at your own risk.
    1.21 + *
    1.22 + * Permission to use or copy this software for any purpose is hereby granted
    1.23 + * without fee, provided the above notices are retained on all copies.
    1.24 + * Permission to modify the code and to distribute modified code is granted,
    1.25 + * provided the above notices are retained, and a notice that the code was
    1.26 + * modified is included with the above copyright notice.
    1.27 + *
    1.28 + */
    1.29 +#ifndef _STLP_VECTOR_C
    1.30 +#define _STLP_VECTOR_C
    1.31 +
    1.32 +#if !defined (_STLP_INTERNAL_VECTOR_H)
    1.33 +#  include <stl/_vector.h>
    1.34 +#endif
    1.35 +
    1.36 +#include <stl/_range_errors.h>
    1.37 +
    1.38 +_STLP_BEGIN_NAMESPACE
    1.39 +
    1.40 +_STLP_MOVE_TO_PRIV_NAMESPACE
    1.41 +
    1.42 +template <class _Tp, class _Alloc>
    1.43 +void _Vector_base<_Tp,_Alloc>::_M_throw_length_error() const {
    1.44 +  __stl_throw_length_error("vector");
    1.45 +}
    1.46 +
    1.47 +template <class _Tp, class _Alloc>
    1.48 +void _Vector_base<_Tp, _Alloc>::_M_throw_out_of_range() const {
    1.49 +  __stl_throw_out_of_range("vector");
    1.50 +}
    1.51 +
    1.52 +#if defined (_STLP_USE_PTR_SPECIALIZATIONS)
    1.53 +#  define vector _STLP_PTR_IMPL_NAME(vector)
    1.54 +#elif defined (_STLP_DEBUG)
    1.55 +#  define vector _STLP_NON_DBG_NAME(vector)
    1.56 +#else
    1.57 +_STLP_MOVE_TO_STD_NAMESPACE
    1.58 +#endif
    1.59 +
    1.60 +#if defined (_STLP_NESTED_TYPE_PARAM_BUG)
    1.61 +#  define __iterator__  _Tp*
    1.62 +#else
    1.63 +#  define __iterator__  _STLP_TYPENAME_ON_RETURN_TYPE vector<_Tp, _Alloc>::iterator
    1.64 +#endif
    1.65 +
    1.66 +template <class _Tp, class _Alloc>
    1.67 +void vector<_Tp, _Alloc>::reserve(size_type __n) {
    1.68 +  if (capacity() < __n) {
    1.69 +    if (max_size() < __n) {
    1.70 +      this->_M_throw_length_error();
    1.71 +    }
    1.72 +
    1.73 +    const size_type __old_size = size();
    1.74 +    pointer __tmp;
    1.75 +    if (this->_M_start) {
    1.76 +      __tmp = _M_allocate_and_copy(__n, this->_M_start, this->_M_finish);
    1.77 +      _M_clear();
    1.78 +    } else {
    1.79 +      __tmp = this->_M_end_of_storage.allocate(__n, __n);
    1.80 +    }
    1.81 +    _M_set(__tmp, __tmp + __old_size, __tmp + __n);
    1.82 +  }
    1.83 +}
    1.84 +
    1.85 +template <class _Tp, class _Alloc>
    1.86 +void vector<_Tp, _Alloc>::_M_insert_overflow_aux(pointer __pos, const _Tp& __x, const __false_type& /*DO NOT USE!!*/,
    1.87 +                                                 size_type __fill_len, bool __atend ) {
    1.88 +  const size_type __old_size = size();
    1.89 +  size_type __len = __old_size + (max)(__old_size, __fill_len);
    1.90 +
    1.91 +  pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
    1.92 +  pointer __new_finish = __new_start;
    1.93 +  _STLP_TRY {
    1.94 +    __new_finish = _STLP_PRIV __uninitialized_move(this->_M_start, __pos, __new_start, _TrivialUCopy(), _Movable());
    1.95 +    // handle insertion
    1.96 +    if (__fill_len == 1) {
    1.97 +      _Copy_Construct(__new_finish, __x);
    1.98 +      ++__new_finish;
    1.99 +    } else
   1.100 +      __new_finish = _STLP_PRIV __uninitialized_fill_n(__new_finish, __fill_len, __x);
   1.101 +    if (!__atend)
   1.102 +      __new_finish = _STLP_PRIV __uninitialized_move(__pos, this->_M_finish, __new_finish, _TrivialUCopy(), _Movable()); // copy remainder
   1.103 +  }
   1.104 +  _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
   1.105 +               this->_M_end_of_storage.deallocate(__new_start,__len)))
   1.106 +  _M_clear_after_move();
   1.107 +  _M_set(__new_start, __new_finish, __new_start + __len);
   1.108 +}
   1.109 +
   1.110 +template <class _Tp, class _Alloc>
   1.111 +void vector<_Tp, _Alloc>::_M_insert_overflow(pointer __pos, const _Tp& __x, const __true_type& /*_TrivialCopy*/,
   1.112 +                                             size_type __fill_len, bool __atend ) {
   1.113 +  const size_type __old_size = size();
   1.114 +  size_type __len = __old_size + (max)(__old_size, __fill_len);
   1.115 +
   1.116 +  pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
   1.117 +  pointer __new_finish = __STATIC_CAST(pointer, _STLP_PRIV __copy_trivial(this->_M_start, __pos, __new_start));
   1.118 +  // handle insertion
   1.119 +  __new_finish = _STLP_PRIV __fill_n(__new_finish, __fill_len, __x);
   1.120 +  if (!__atend)
   1.121 +    __new_finish = __STATIC_CAST(pointer, _STLP_PRIV __copy_trivial(__pos, this->_M_finish, __new_finish)); // copy remainder
   1.122 +  _M_clear();
   1.123 +  _M_set(__new_start, __new_finish, __new_start + __len);
   1.124 +}
   1.125 +
   1.126 +template <class _Tp, class _Alloc>
   1.127 +void vector<_Tp, _Alloc>::_M_fill_insert_aux(iterator __pos, size_type __n,
   1.128 +                                             const _Tp& __x, const __true_type& /*_Movable*/) {
   1.129 +  if (_M_is_inside(__x)) {
   1.130 +    _Tp __x_copy = __x;
   1.131 +    _M_fill_insert_aux(__pos, __n, __x_copy, __true_type());
   1.132 +    return;
   1.133 +  }
   1.134 +  iterator __src = this->_M_finish - 1;
   1.135 +  iterator __dst = __src + __n;
   1.136 +  for (; __src >= __pos; --__dst, --__src) {
   1.137 +    _STLP_STD::_Move_Construct(__dst, *__src);
   1.138 +    _STLP_STD::_Destroy_Moved(__src);
   1.139 +  }
   1.140 +  _STLP_PRIV __uninitialized_fill_n(__pos, __n, __x);
   1.141 +  this->_M_finish += __n;
   1.142 +}
   1.143 +
   1.144 +template <class _Tp, class _Alloc>
   1.145 +void vector<_Tp, _Alloc>::_M_fill_insert_aux (iterator __pos, size_type __n,
   1.146 +                                              const _Tp& __x, const __false_type& /*_Movable*/) {
   1.147 +  //Here self referencing needs to be checked even for non movable types.
   1.148 +  if (_M_is_inside(__x)) {
   1.149 +    _Tp __x_copy = __x;
   1.150 +    _M_fill_insert_aux(__pos, __n, __x_copy, __false_type());
   1.151 +    return;
   1.152 +  }
   1.153 +  const size_type __elems_after = this->_M_finish - __pos;
   1.154 +  pointer __old_finish = this->_M_finish;
   1.155 +  if (__elems_after > __n) {
   1.156 +    _STLP_PRIV __ucopy_ptrs(this->_M_finish - __n, this->_M_finish, this->_M_finish, _TrivialUCopy());
   1.157 +    this->_M_finish += __n;
   1.158 +    _STLP_PRIV __copy_backward_ptrs(__pos, __old_finish - __n, __old_finish, _TrivialCopy());
   1.159 +    _STLP_STD::fill(__pos, __pos + __n, __x);
   1.160 +  } else {
   1.161 +    this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_finish, __n - __elems_after, __x);
   1.162 +    _STLP_PRIV __ucopy_ptrs(__pos, __old_finish, this->_M_finish, _TrivialUCopy());
   1.163 +    this->_M_finish += __elems_after;
   1.164 +    _STLP_STD::fill(__pos, __old_finish, __x);
   1.165 +  }
   1.166 +}
   1.167 +
   1.168 +template <class _Tp, class _Alloc>
   1.169 +void vector<_Tp, _Alloc>::_M_fill_insert(iterator __pos,
   1.170 +                                         size_type __n, const _Tp& __x) {
   1.171 +  if (__n != 0) {
   1.172 +    if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n) {
   1.173 +      _M_fill_insert_aux(__pos, __n, __x, _Movable());
   1.174 +    } else
   1.175 +      _M_insert_overflow(__pos, __x, _TrivialCopy(), __n);
   1.176 +  }
   1.177 +}
   1.178 +
   1.179 +template <class _Tp, class _Alloc>
   1.180 +vector<_Tp, _Alloc>& vector<_Tp, _Alloc>::operator = (const vector<_Tp, _Alloc>& __x) {
   1.181 +  if (&__x != this) {
   1.182 +    const size_type __xlen = __x.size();
   1.183 +    if (__xlen > capacity()) {
   1.184 +      size_type __len = __xlen;
   1.185 +      pointer __tmp = _M_allocate_and_copy(__len, __CONST_CAST(const_pointer, __x._M_start) + 0,
   1.186 +                                                  __CONST_CAST(const_pointer, __x._M_finish) + 0);
   1.187 +      _M_clear();
   1.188 +      this->_M_start = __tmp;
   1.189 +      this->_M_end_of_storage._M_data = this->_M_start + __len;
   1.190 +    } else if (size() >= __xlen) {
   1.191 +      pointer __i = _STLP_PRIV __copy_ptrs(__CONST_CAST(const_pointer, __x._M_start) + 0,
   1.192 +                                           __CONST_CAST(const_pointer, __x._M_finish) + 0, this->_M_start, _TrivialCopy());
   1.193 +      _STLP_STD::_Destroy_Range(__i, this->_M_finish);
   1.194 +    } else {
   1.195 +      _STLP_PRIV __copy_ptrs(__CONST_CAST(const_pointer, __x._M_start),
   1.196 +                             __CONST_CAST(const_pointer, __x._M_start) + size(), this->_M_start, _TrivialCopy());
   1.197 +      _STLP_PRIV __ucopy_ptrs(__CONST_CAST(const_pointer, __x._M_start) + size(),
   1.198 +                              __CONST_CAST(const_pointer, __x._M_finish) + 0, this->_M_finish, _TrivialUCopy());
   1.199 +    }
   1.200 +    this->_M_finish = this->_M_start + __xlen;
   1.201 +  }
   1.202 +  return *this;
   1.203 +}
   1.204 +
   1.205 +template <class _Tp, class _Alloc>
   1.206 +void vector<_Tp, _Alloc>::_M_fill_assign(size_t __n, const _Tp& __val) {
   1.207 +  if (__n > capacity()) {
   1.208 +    vector<_Tp, _Alloc> __tmp(__n, __val, get_allocator());
   1.209 +    __tmp.swap(*this);
   1.210 +  } else if (__n > size()) {
   1.211 +    fill(begin(), end(), __val);
   1.212 +    this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_finish, __n - size(), __val);
   1.213 +  } else
   1.214 +    erase(_STLP_PRIV __fill_n(begin(), __n, __val), end());
   1.215 +}
   1.216 +
   1.217 +template <class _Tp, class _Alloc>
   1.218 +__iterator__
   1.219 +vector<_Tp, _Alloc>::insert(iterator __pos, const _Tp& __x) {
   1.220 +  size_type __n = __pos - begin();
   1.221 +  _M_fill_insert(__pos, 1, __x);
   1.222 +  return begin() + __n;
   1.223 +}
   1.224 +
   1.225 +#undef __iterator__
   1.226 +
   1.227 +#if defined (vector)
   1.228 +#  undef vector
   1.229 +_STLP_MOVE_TO_STD_NAMESPACE
   1.230 +#endif
   1.231 +
   1.232 +_STLP_END_NAMESPACE
   1.233 +
   1.234 +#endif /*  _STLP_VECTOR_C */
   1.235 +
   1.236 +// Local Variables:
   1.237 +// mode:C++
   1.238 +// End: