1.1 --- a/epoc32/include/stdapis/stlportv5/stl/_vector.c Wed Mar 31 12:27:01 2010 +0100
1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_vector.c Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -10,13 +10,13 @@
1.4 * Copyright (c) 1997
1.5 * Moscow Center for SPARC Technology
1.6 *
1.7 - * Copyright (c) 1999
1.8 + * Copyright (c) 1999
1.9 * Boris Fomitchev
1.10 *
1.11 * This material is provided "as is", with absolutely no warranty expressed
1.12 * or implied. Any use is at your own risk.
1.13 *
1.14 - * Permission to use or copy this software for any purpose is hereby granted
1.15 + * Permission to use or copy this software for any purpose is hereby granted
1.16 * without fee, provided the above notices are retained on all copies.
1.17 * Permission to modify the code and to distribute modified code is granted,
1.18 * provided the above notices are retained, and a notice that the code was
1.19 @@ -26,84 +26,173 @@
1.20 #ifndef _STLP_VECTOR_C
1.21 #define _STLP_VECTOR_C
1.22
1.23 -# if !defined (_STLP_INTERNAL_VECTOR_H)
1.24 +#if !defined (_STLP_INTERNAL_VECTOR_H)
1.25 # include <stl/_vector.h>
1.26 -# endif
1.27 +#endif
1.28
1.29 -# if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
1.30 -# define iterator _Tp*
1.31 -# define size_type size_t
1.32 -# endif
1.33 -
1.34 -# undef vector
1.35 -# define vector __WORKAROUND_DBG_RENAME(vector)
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
1.44 -__vector__<_Tp, _Alloc>::reserve(size_type __n) {
1.45 +void _Vector_base<_Tp,_Alloc>::_M_throw_length_error() const {
1.46 + __stl_throw_length_error("vector");
1.47 +}
1.48 +
1.49 +template <class _Tp, class _Alloc>
1.50 +void _Vector_base<_Tp, _Alloc>::_M_throw_out_of_range() const {
1.51 + __stl_throw_out_of_range("vector");
1.52 +}
1.53 +
1.54 +#if defined (_STLP_USE_PTR_SPECIALIZATIONS)
1.55 +# define vector _STLP_PTR_IMPL_NAME(vector)
1.56 +#elif defined (_STLP_DEBUG)
1.57 +# define vector _STLP_NON_DBG_NAME(vector)
1.58 +#else
1.59 +_STLP_MOVE_TO_STD_NAMESPACE
1.60 +#endif
1.61 +
1.62 +#if defined (_STLP_NESTED_TYPE_PARAM_BUG)
1.63 +# define __iterator__ _Tp*
1.64 +#else
1.65 +# define __iterator__ _STLP_TYPENAME_ON_RETURN_TYPE vector<_Tp, _Alloc>::iterator
1.66 +#endif
1.67 +
1.68 +template <class _Tp, class _Alloc>
1.69 +void vector<_Tp, _Alloc>::reserve(size_type __n) {
1.70 if (capacity() < __n) {
1.71 + if (max_size() < __n) {
1.72 + this->_M_throw_length_error();
1.73 + }
1.74 +
1.75 const size_type __old_size = size();
1.76 pointer __tmp;
1.77 if (this->_M_start) {
1.78 __tmp = _M_allocate_and_copy(__n, this->_M_start, this->_M_finish);
1.79 _M_clear();
1.80 } else {
1.81 - __tmp = this->_M_end_of_storage.allocate(__n);
1.82 + __tmp = this->_M_end_of_storage.allocate(__n, __n);
1.83 }
1.84 _M_set(__tmp, __tmp + __old_size, __tmp + __n);
1.85 }
1.86 }
1.87
1.88 template <class _Tp, class _Alloc>
1.89 -void
1.90 -__vector__<_Tp, _Alloc>::_M_fill_insert(
1.91 - iterator __position,
1.92 - size_type __n, const _Tp& __x) {
1.93 - if (__n != 0) {
1.94 - if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n) {
1.95 - _Tp __x_copy = __x;
1.96 - const size_type __elems_after = this->_M_finish - __position;
1.97 - pointer __old_finish = this->_M_finish;
1.98 - if (__elems_after > __n) {
1.99 - __uninitialized_copy(this->_M_finish - __n, this->_M_finish, this->_M_finish, _IsPODType());
1.100 - this->_M_finish += __n;
1.101 - __copy_backward_ptrs(__position, __old_finish - __n, __old_finish, _TrivialAss());
1.102 - _STLP_STD::fill(__position, __position + __n, __x_copy);
1.103 - }
1.104 - else {
1.105 - uninitialized_fill_n(this->_M_finish, __n - __elems_after, __x_copy);
1.106 - this->_M_finish += __n - __elems_after;
1.107 - __uninitialized_copy(__position, __old_finish, this->_M_finish, _IsPODType());
1.108 - this->_M_finish += __elems_after;
1.109 - _STLP_STD::fill(__position, __old_finish, __x_copy);
1.110 - }
1.111 - }
1.112 - else
1.113 - _M_insert_overflow(__position, __x, _IsPODType(), __n);
1.114 +void vector<_Tp, _Alloc>::_M_insert_overflow_aux(pointer __pos, const _Tp& __x, const __false_type& /*DO NOT USE!!*/,
1.115 + size_type __fill_len, bool __atend ) {
1.116 + const size_type __old_size = size();
1.117 + size_type __len = __old_size + (max)(__old_size, __fill_len);
1.118 +
1.119 + pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
1.120 + pointer __new_finish = __new_start;
1.121 + _STLP_TRY {
1.122 + __new_finish = _STLP_PRIV __uninitialized_move(this->_M_start, __pos, __new_start, _TrivialUCopy(), _Movable());
1.123 + // handle insertion
1.124 + if (__fill_len == 1) {
1.125 + _Copy_Construct(__new_finish, __x);
1.126 + ++__new_finish;
1.127 + } else
1.128 + __new_finish = _STLP_PRIV __uninitialized_fill_n(__new_finish, __fill_len, __x);
1.129 + if (!__atend)
1.130 + __new_finish = _STLP_PRIV __uninitialized_move(__pos, this->_M_finish, __new_finish, _TrivialUCopy(), _Movable()); // copy remainder
1.131 + }
1.132 + _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
1.133 + this->_M_end_of_storage.deallocate(__new_start,__len)))
1.134 + _M_clear_after_move();
1.135 + _M_set(__new_start, __new_finish, __new_start + __len);
1.136 +}
1.137 +
1.138 +template <class _Tp, class _Alloc>
1.139 +void vector<_Tp, _Alloc>::_M_insert_overflow(pointer __pos, const _Tp& __x, const __true_type& /*_TrivialCopy*/,
1.140 + size_type __fill_len, bool __atend ) {
1.141 + const size_type __old_size = size();
1.142 + size_type __len = __old_size + (max)(__old_size, __fill_len);
1.143 +
1.144 + pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
1.145 + pointer __new_finish = __STATIC_CAST(pointer, _STLP_PRIV __copy_trivial(this->_M_start, __pos, __new_start));
1.146 + // handle insertion
1.147 + __new_finish = _STLP_PRIV __fill_n(__new_finish, __fill_len, __x);
1.148 + if (!__atend)
1.149 + __new_finish = __STATIC_CAST(pointer, _STLP_PRIV __copy_trivial(__pos, this->_M_finish, __new_finish)); // copy remainder
1.150 + _M_clear();
1.151 + _M_set(__new_start, __new_finish, __new_start + __len);
1.152 +}
1.153 +
1.154 +template <class _Tp, class _Alloc>
1.155 +void vector<_Tp, _Alloc>::_M_fill_insert_aux(iterator __pos, size_type __n,
1.156 + const _Tp& __x, const __true_type& /*_Movable*/) {
1.157 + if (_M_is_inside(__x)) {
1.158 + _Tp __x_copy = __x;
1.159 + _M_fill_insert_aux(__pos, __n, __x_copy, __true_type());
1.160 + return;
1.161 + }
1.162 + iterator __src = this->_M_finish - 1;
1.163 + iterator __dst = __src + __n;
1.164 + for (; __src >= __pos; --__dst, --__src) {
1.165 + _STLP_STD::_Move_Construct(__dst, *__src);
1.166 + _STLP_STD::_Destroy_Moved(__src);
1.167 + }
1.168 + _STLP_PRIV __uninitialized_fill_n(__pos, __n, __x);
1.169 + this->_M_finish += __n;
1.170 +}
1.171 +
1.172 +template <class _Tp, class _Alloc>
1.173 +void vector<_Tp, _Alloc>::_M_fill_insert_aux (iterator __pos, size_type __n,
1.174 + const _Tp& __x, const __false_type& /*_Movable*/) {
1.175 + //Here self referencing needs to be checked even for non movable types.
1.176 + if (_M_is_inside(__x)) {
1.177 + _Tp __x_copy = __x;
1.178 + _M_fill_insert_aux(__pos, __n, __x_copy, __false_type());
1.179 + return;
1.180 + }
1.181 + const size_type __elems_after = this->_M_finish - __pos;
1.182 + pointer __old_finish = this->_M_finish;
1.183 + if (__elems_after > __n) {
1.184 + _STLP_PRIV __ucopy_ptrs(this->_M_finish - __n, this->_M_finish, this->_M_finish, _TrivialUCopy());
1.185 + this->_M_finish += __n;
1.186 + _STLP_PRIV __copy_backward_ptrs(__pos, __old_finish - __n, __old_finish, _TrivialCopy());
1.187 + _STLP_STD::fill(__pos, __pos + __n, __x);
1.188 + } else {
1.189 + this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_finish, __n - __elems_after, __x);
1.190 + _STLP_PRIV __ucopy_ptrs(__pos, __old_finish, this->_M_finish, _TrivialUCopy());
1.191 + this->_M_finish += __elems_after;
1.192 + _STLP_STD::fill(__pos, __old_finish, __x);
1.193 }
1.194 }
1.195
1.196 template <class _Tp, class _Alloc>
1.197 -__vector__<_Tp,_Alloc>&
1.198 -__vector__<_Tp,_Alloc>::operator=(const __vector__<_Tp, _Alloc>& __x)
1.199 -{
1.200 +void vector<_Tp, _Alloc>::_M_fill_insert(iterator __pos,
1.201 + size_type __n, const _Tp& __x) {
1.202 + if (__n != 0) {
1.203 + if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n) {
1.204 + _M_fill_insert_aux(__pos, __n, __x, _Movable());
1.205 + } else
1.206 + _M_insert_overflow(__pos, __x, _TrivialCopy(), __n);
1.207 + }
1.208 +}
1.209 +
1.210 +template <class _Tp, class _Alloc>
1.211 +vector<_Tp, _Alloc>& vector<_Tp, _Alloc>::operator = (const vector<_Tp, _Alloc>& __x) {
1.212 if (&__x != this) {
1.213 const size_type __xlen = __x.size();
1.214 if (__xlen > capacity()) {
1.215 - pointer __tmp = _M_allocate_and_copy(__xlen, (const_pointer)__x._M_start+0, (const_pointer)__x._M_finish+0);
1.216 + size_type __len = __xlen;
1.217 + pointer __tmp = _M_allocate_and_copy(__len, __CONST_CAST(const_pointer, __x._M_start) + 0,
1.218 + __CONST_CAST(const_pointer, __x._M_finish) + 0);
1.219 _M_clear();
1.220 this->_M_start = __tmp;
1.221 - this->_M_end_of_storage._M_data = this->_M_start + __xlen;
1.222 - }
1.223 - else if (size() >= __xlen) {
1.224 - pointer __i = __copy_ptrs((const_pointer)__x._M_start+0, (const_pointer)__x._M_finish+0, (pointer)this->_M_start, _TrivialAss());
1.225 - _STLP_STD::_Destroy(__i, this->_M_finish);
1.226 - }
1.227 - else {
1.228 - __copy_ptrs((const_pointer)__x._M_start, (const_pointer)__x._M_start + size(), (pointer)this->_M_start, _TrivialAss());
1.229 - __uninitialized_copy((const_pointer)__x._M_start + size(), (const_pointer)__x._M_finish+0, this->_M_finish, _IsPODType());
1.230 + this->_M_end_of_storage._M_data = this->_M_start + __len;
1.231 + } else if (size() >= __xlen) {
1.232 + pointer __i = _STLP_PRIV __copy_ptrs(__CONST_CAST(const_pointer, __x._M_start) + 0,
1.233 + __CONST_CAST(const_pointer, __x._M_finish) + 0, this->_M_start, _TrivialCopy());
1.234 + _STLP_STD::_Destroy_Range(__i, this->_M_finish);
1.235 + } else {
1.236 + _STLP_PRIV __copy_ptrs(__CONST_CAST(const_pointer, __x._M_start),
1.237 + __CONST_CAST(const_pointer, __x._M_start) + size(), this->_M_start, _TrivialCopy());
1.238 + _STLP_PRIV __ucopy_ptrs(__CONST_CAST(const_pointer, __x._M_start) + size(),
1.239 + __CONST_CAST(const_pointer, __x._M_finish) + 0, this->_M_finish, _TrivialUCopy());
1.240 }
1.241 this->_M_finish = this->_M_start + __xlen;
1.242 }
1.243 @@ -111,27 +200,36 @@
1.244 }
1.245
1.246 template <class _Tp, class _Alloc>
1.247 -void __vector__<_Tp, _Alloc>::_M_fill_assign(size_t __n, const _Tp& __val) {
1.248 +void vector<_Tp, _Alloc>::_M_fill_assign(size_t __n, const _Tp& __val) {
1.249 if (__n > capacity()) {
1.250 - __vector__<_Tp, _Alloc> __tmp(__n, __val, get_allocator());
1.251 + vector<_Tp, _Alloc> __tmp(__n, __val, get_allocator());
1.252 __tmp.swap(*this);
1.253 - }
1.254 - else if (__n > size()) {
1.255 + } else if (__n > size()) {
1.256 fill(begin(), end(), __val);
1.257 - this->_M_finish = _STLP_STD::uninitialized_fill_n(this->_M_finish, __n - size(), __val);
1.258 - }
1.259 - else
1.260 - erase(_STLP_STD::fill_n(begin(), __n, __val), end());
1.261 + this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_finish, __n - size(), __val);
1.262 + } else
1.263 + erase(_STLP_PRIV __fill_n(begin(), __n, __val), end());
1.264 }
1.265
1.266 +template <class _Tp, class _Alloc>
1.267 +__iterator__
1.268 +vector<_Tp, _Alloc>::insert(iterator __pos, const _Tp& __x) {
1.269 + size_type __n = __pos - begin();
1.270 + _M_fill_insert(__pos, 1, __x);
1.271 + return begin() + __n;
1.272 +}
1.273 +
1.274 +#undef __iterator__
1.275 +
1.276 +#if defined (vector)
1.277 +# undef vector
1.278 +_STLP_MOVE_TO_STD_NAMESPACE
1.279 +#endif
1.280 +
1.281 _STLP_END_NAMESPACE
1.282
1.283 -# undef size_type
1.284 -# undef iterator
1.285 -# undef vector
1.286 -
1.287 #endif /* _STLP_VECTOR_C */
1.288
1.289 - // Local Variables:
1.290 - // mode:C++
1.291 - // End:
1.292 +// Local Variables:
1.293 +// mode:C++
1.294 +// End: