1.1 --- a/epoc32/include/stdapis/stlportv5/stl/_slist.c Wed Mar 31 12:27:01 2010 +0100
1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_slist.c Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -3,13 +3,13 @@
1.4 * Copyright (c) 1996,1997
1.5 * Silicon Graphics Computer Systems, Inc.
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 @@ -20,25 +20,33 @@
1.20 #define _STLP_SLIST_C
1.21
1.22 #ifndef _STLP_INTERNAL_SLIST_H
1.23 -# include <stl/_slist.h>
1.24 +# include <stl/_slist.h>
1.25 #endif
1.26
1.27 -# undef slist
1.28 -# define slist __WORKAROUND_DBG_RENAME(slist)
1.29 -# if defined (_STLP_NESTED_TYPE_PARAM_BUG)
1.30 -# define size_type size_t
1.31 -# endif
1.32 +#ifndef _STLP_CARRAY_H
1.33 +# include <stl/_carray.h>
1.34 +#endif
1.35 +
1.36 +#ifndef _STLP_RANGE_ERRORS_H
1.37 +# include <stl/_range_errors.h>
1.38 +#endif
1.39 +
1.40 +#if defined (_STLP_NESTED_TYPE_PARAM_BUG)
1.41 +# define size_type size_t
1.42 +#endif
1.43
1.44 _STLP_BEGIN_NAMESPACE
1.45
1.46 -template <class _Tp, class _Alloc>
1.47 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.48 +
1.49 +template <class _Tp, class _Alloc>
1.50 _Slist_node_base*
1.51 _Slist_base<_Tp,_Alloc>::_M_erase_after(_Slist_node_base* __before_first,
1.52 _Slist_node_base* __last_node) {
1.53 - _Slist_node<_Tp>* __cur = (_Slist_node<_Tp>*) (__before_first->_M_next);
1.54 + _Slist_node_base* __cur = __before_first->_M_next;
1.55 while (__cur != __last_node) {
1.56 - _Slist_node<_Tp>* __tmp = __cur;
1.57 - __cur = (_Slist_node<_Tp>*) __cur->_M_next;
1.58 + _Node* __tmp = __STATIC_CAST(_Node*, __cur);
1.59 + __cur = __cur->_M_next;
1.60 _STLP_STD::_Destroy(&__tmp->_M_data);
1.61 _M_head.deallocate(__tmp,1);
1.62 }
1.63 @@ -46,23 +54,34 @@
1.64 return __last_node;
1.65 }
1.66
1.67 +#if defined (_STLP_USE_PTR_SPECIALIZATIONS)
1.68 +# define slist _STLP_PTR_IMPL_NAME(slist)
1.69 +#elif defined (_STLP_DEBUG)
1.70 +# define slist _STLP_NON_DBG_NAME(slist)
1.71 +#else
1.72 +_STLP_MOVE_TO_STD_NAMESPACE
1.73 +#endif
1.74 +
1.75 +/* When building STLport lib Digital Mars Compiler complains on the _M_data assignment
1.76 + * problem which would be perfertly right if we were using it. Hiding it during build
1.77 + * fix this issue.
1.78 + */
1.79 template <class _Tp, class _Alloc>
1.80 -slist<_Tp,_Alloc>& slist<_Tp,_Alloc>::operator=(const slist<_Tp,_Alloc>& __x)
1.81 -{
1.82 +slist<_Tp,_Alloc>& slist<_Tp,_Alloc>::operator=(const slist<_Tp,_Alloc>& __x) {
1.83 if (&__x != this) {
1.84 _Node_base* __p1 = &this->_M_head._M_data;
1.85 - _Node* __n1 = (_Node*) this->_M_head._M_data._M_next;
1.86 - const _Node* __n2 = (const _Node*) __x._M_head._M_data._M_next;
1.87 + _Node_base* __n1 = this->_M_head._M_data._M_next;
1.88 + const _Node_base* __n2 = __x._M_head._M_data._M_next;
1.89 while (__n1 && __n2) {
1.90 - __n1->_M_data = __n2->_M_data;
1.91 + __STATIC_CAST(_Node*, __n1)->_M_data = __STATIC_CAST(const _Node*, __n2)->_M_data;
1.92 __p1 = __n1;
1.93 - __n1 = (_Node*) __n1->_M_next;
1.94 - __n2 = (const _Node*) __n2->_M_next;
1.95 + __n1 = __n1->_M_next;
1.96 + __n2 = __n2->_M_next;
1.97 }
1.98 if (__n2 == 0)
1.99 this->_M_erase_after(__p1, 0);
1.100 else
1.101 - _M_insert_after_range(__p1, const_iterator((_Node*)__n2),
1.102 + _M_insert_after_range(__p1, const_iterator(__CONST_CAST(_Node_base*, __n2)),
1.103 const_iterator(0));
1.104 }
1.105 return *this;
1.106 @@ -71,11 +90,11 @@
1.107 template <class _Tp, class _Alloc>
1.108 void slist<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) {
1.109 _Node_base* __prev = &this->_M_head._M_data;
1.110 - _Node* __node = (_Node*) this->_M_head._M_data._M_next;
1.111 + _Node_base* __node = this->_M_head._M_data._M_next;
1.112 for ( ; __node != 0 && __n > 0 ; --__n) {
1.113 - __node->_M_data = __val;
1.114 + __STATIC_CAST(_Node*, __node)->_M_data = __val;
1.115 __prev = __node;
1.116 - __node = (_Node*) __node->_M_next;
1.117 + __node = __node->_M_next;
1.118 }
1.119 if (__n > 0)
1.120 _M_insert_after_fill(__prev, __n, __val);
1.121 @@ -83,95 +102,128 @@
1.122 this->_M_erase_after(__prev, 0);
1.123 }
1.124
1.125 -
1.126 template <class _Tp, class _Alloc>
1.127 -void slist<_Tp,_Alloc>::resize(size_type __len, const _Tp& __x)
1.128 -{
1.129 +void slist<_Tp,_Alloc>::resize(size_type __len, const _Tp& __x) {
1.130 _Node_base* __cur = &this->_M_head._M_data;
1.131 while (__cur->_M_next != 0 && __len > 0) {
1.132 --__len;
1.133 __cur = __cur->_M_next;
1.134 }
1.135 - if (__cur->_M_next)
1.136 + if (__cur->_M_next)
1.137 this->_M_erase_after(__cur, 0);
1.138 else
1.139 _M_insert_after_fill(__cur, __len, __x);
1.140 }
1.141
1.142 template <class _Tp, class _Alloc>
1.143 -void slist<_Tp,_Alloc>::remove(const _Tp& __val)
1.144 -{
1.145 +void slist<_Tp,_Alloc>::remove(const _Tp& __val) {
1.146 _Node_base* __cur = &this->_M_head._M_data;
1.147 while (__cur && __cur->_M_next) {
1.148 - if (((_Node*) __cur->_M_next)->_M_data == __val)
1.149 + if (__STATIC_CAST(_Node*, __cur->_M_next)->_M_data == __val)
1.150 this->_M_erase_after(__cur);
1.151 else
1.152 __cur = __cur->_M_next;
1.153 }
1.154 }
1.155
1.156 -template <class _Tp, class _Alloc>
1.157 -void slist<_Tp,_Alloc>::unique()
1.158 -{
1.159 - _Node_base* __cur = this->_M_head._M_data._M_next;
1.160 - if (__cur) {
1.161 - while (__cur->_M_next) {
1.162 - if (((_Node*)__cur)->_M_data ==
1.163 - ((_Node*)(__cur->_M_next))->_M_data)
1.164 - this->_M_erase_after(__cur);
1.165 +#if !defined (slist)
1.166 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.167 +#endif
1.168 +
1.169 +template <class _Tp, class _Alloc, class _BinaryPredicate>
1.170 +void _Slist_unique(slist<_Tp, _Alloc>& __that, _BinaryPredicate __pred) {
1.171 + typedef _Slist_node<_Tp> _Node;
1.172 + typename slist<_Tp, _Alloc>::iterator __ite(__that.begin());
1.173 + if (__ite != __that.end()) {
1.174 + while (__ite._M_node->_M_next) {
1.175 + if (__pred(*__ite, __STATIC_CAST(_Node*, __ite._M_node->_M_next)->_M_data))
1.176 + __that.erase_after(__ite);
1.177 else
1.178 - __cur = __cur->_M_next;
1.179 + ++__ite;
1.180 }
1.181 }
1.182 }
1.183
1.184 -template <class _Tp, class _Alloc>
1.185 -void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x)
1.186 -{
1.187 - _Node_base* __n1 = &this->_M_head._M_data;
1.188 - while (__n1->_M_next && __x._M_head._M_data._M_next) {
1.189 - if (((_Node*) __x._M_head._M_data._M_next)->_M_data <
1.190 - ((_Node*) __n1->_M_next)->_M_data)
1.191 - _Sl_global_inst::__splice_after(__n1, &__x._M_head._M_data, __x._M_head._M_data._M_next);
1.192 - __n1 = __n1->_M_next;
1.193 +template <class _Tp, class _Alloc, class _StrictWeakOrdering>
1.194 +void _Slist_merge(slist<_Tp, _Alloc>& __that, slist<_Tp, _Alloc>& __x,
1.195 + _StrictWeakOrdering __comp) {
1.196 + typedef _Slist_node<_Tp> _Node;
1.197 + typedef _STLP_PRIV _Slist_node_base _Node_base;
1.198 + if (__that.get_allocator() == __x.get_allocator()) {
1.199 + typename slist<_Tp, _Alloc>::iterator __ite(__that.before_begin());
1.200 + while (__ite._M_node->_M_next && !__x.empty()) {
1.201 + if (__comp(__x.front(), __STATIC_CAST(_Node*, __ite._M_node->_M_next)->_M_data)) {
1.202 + _STLP_VERBOSE_ASSERT(!__comp(__STATIC_CAST(_Node*, __ite._M_node->_M_next)->_M_data, __x.front()),
1.203 + _StlMsg_INVALID_STRICT_WEAK_PREDICATE)
1.204 + __that.splice_after(__ite, __x, __x.before_begin());
1.205 + }
1.206 + ++__ite;
1.207 + }
1.208 + if (!__x.empty()) {
1.209 + __that.splice_after(__ite, __x);
1.210 + }
1.211 }
1.212 - if (__x._M_head._M_data._M_next) {
1.213 - __n1->_M_next = __x._M_head._M_data._M_next;
1.214 - __x._M_head._M_data._M_next = 0;
1.215 + else {
1.216 + typename slist<_Tp, _Alloc>::iterator __i1(__that.before_begin()), __i2(__x.begin());
1.217 + while (__i1._M_node->_M_next && __i2._M_node) {
1.218 + if (__comp(__STATIC_CAST(_Node*, __i1._M_node->_M_next)->_M_data, *__i2)) {
1.219 + _STLP_VERBOSE_ASSERT(!__comp(*__i2, __STATIC_CAST(_Node*, __i1._M_node->_M_next)->_M_data),
1.220 + _StlMsg_INVALID_STRICT_WEAK_PREDICATE)
1.221 + ++__i1;
1.222 + }
1.223 + else {
1.224 + __i1 = __that.insert_after(__i1, *(__i2++));
1.225 + }
1.226 + }
1.227 + __that.insert_after(__i1, __i2, __x.end());
1.228 + __x.clear();
1.229 }
1.230 }
1.231
1.232 -template <class _Tp, class _Alloc>
1.233 -void slist<_Tp,_Alloc>::sort()
1.234 -{
1.235 - if (this->_M_head._M_data._M_next && this->_M_head._M_data._M_next->_M_next) {
1.236 - _Self __carry;
1.237 - _Self __counter[64];
1.238 - int __fill = 0;
1.239 - while (!empty()) {
1.240 - _Sl_global_inst::__splice_after(&__carry._M_head._M_data, &this->_M_head._M_data, this->_M_head._M_data._M_next);
1.241 - int __i = 0;
1.242 - while (__i < __fill && !__counter[__i].empty()) {
1.243 - __counter[__i].merge(__carry);
1.244 - __carry.swap(__counter[__i]);
1.245 - ++__i;
1.246 +template <class _Tp, class _Alloc, class _StrictWeakOrdering>
1.247 +void _Slist_sort(slist<_Tp, _Alloc>& __that, _StrictWeakOrdering __comp) {
1.248 + if (!__that.begin()._M_node || !__that.begin()._M_node->_M_next)
1.249 + return;
1.250 +
1.251 + slist<_Tp, _Alloc> __carry(__that.get_allocator());
1.252 + const int NB = 64;
1.253 + _STLP_PRIV _CArray<slist<_Tp, _Alloc>, NB> __counter(__carry);
1.254 + int __fill = 0;
1.255 + while (!__that.empty()) {
1.256 + __carry.splice_after(__carry.before_begin(), __that, __that.before_begin());
1.257 + int __i = 0;
1.258 + while (__i < __fill && !__counter[__i].empty()) {
1.259 + _STLP_PRIV _Slist_merge(__counter[__i], __carry, __comp);
1.260 + __carry.swap(__counter[__i]);
1.261 + ++__i;
1.262 + }
1.263 + __carry.swap(__counter[__i]);
1.264 + if (__i == __fill) {
1.265 + ++__fill;
1.266 + if (__fill >= NB) {
1.267 + //Looks like the slist has too many elements to be sorted with this algorithm:
1.268 + __stl_throw_overflow_error("slist::sort");
1.269 }
1.270 - __carry.swap(__counter[__i]);
1.271 - if (__i == __fill)
1.272 - ++__fill;
1.273 }
1.274 + }
1.275
1.276 - for (int __i = 1; __i < __fill; ++__i)
1.277 - __counter[__i].merge(__counter[__i-1]);
1.278 - this->swap(__counter[__fill-1]);
1.279 - }
1.280 + for (int __i = 1; __i < __fill; ++__i)
1.281 + _STLP_PRIV _Slist_merge(__counter[__i], __counter[__i - 1], __comp);
1.282 + __that.swap(__counter[__fill-1]);
1.283 }
1.284
1.285 -# undef slist
1.286 -# undef size_type
1.287 +#if defined (slist)
1.288 +# undef slist
1.289 +#endif
1.290 +
1.291 +_STLP_MOVE_TO_STD_NAMESPACE
1.292
1.293 _STLP_END_NAMESPACE
1.294
1.295 +#if defined (_STLP_NESTED_TYPE_PARAM_BUG)
1.296 +# undef size_type
1.297 +#endif
1.298 +
1.299 #endif /* _STLP_SLIST_C */
1.300
1.301 // Local Variables: