1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/_slist.c Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,231 @@
1.4 +/*
1.5 + *
1.6 + * Copyright (c) 1996,1997
1.7 + * Silicon Graphics Computer Systems, Inc.
1.8 + *
1.9 + * Copyright (c) 1999
1.10 + * Boris Fomitchev
1.11 + *
1.12 + * This material is provided "as is", with absolutely no warranty expressed
1.13 + * or implied. Any use is at your own risk.
1.14 + *
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 + * modified is included with the above copyright notice.
1.20 + *
1.21 + */
1.22 +#ifndef _STLP_SLIST_C
1.23 +#define _STLP_SLIST_C
1.24 +
1.25 +#ifndef _STLP_INTERNAL_SLIST_H
1.26 +# include <stl/_slist.h>
1.27 +#endif
1.28 +
1.29 +#ifndef _STLP_CARRAY_H
1.30 +# include <stl/_carray.h>
1.31 +#endif
1.32 +
1.33 +#ifndef _STLP_RANGE_ERRORS_H
1.34 +# include <stl/_range_errors.h>
1.35 +#endif
1.36 +
1.37 +#if defined (_STLP_NESTED_TYPE_PARAM_BUG)
1.38 +# define size_type size_t
1.39 +#endif
1.40 +
1.41 +_STLP_BEGIN_NAMESPACE
1.42 +
1.43 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.44 +
1.45 +template <class _Tp, class _Alloc>
1.46 +_Slist_node_base*
1.47 +_Slist_base<_Tp,_Alloc>::_M_erase_after(_Slist_node_base* __before_first,
1.48 + _Slist_node_base* __last_node) {
1.49 + _Slist_node_base* __cur = __before_first->_M_next;
1.50 + while (__cur != __last_node) {
1.51 + _Node* __tmp = __STATIC_CAST(_Node*, __cur);
1.52 + __cur = __cur->_M_next;
1.53 + _STLP_STD::_Destroy(&__tmp->_M_data);
1.54 + _M_head.deallocate(__tmp,1);
1.55 + }
1.56 + __before_first->_M_next = __last_node;
1.57 + return __last_node;
1.58 +}
1.59 +
1.60 +#if defined (_STLP_USE_PTR_SPECIALIZATIONS)
1.61 +# define slist _STLP_PTR_IMPL_NAME(slist)
1.62 +#elif defined (_STLP_DEBUG)
1.63 +# define slist _STLP_NON_DBG_NAME(slist)
1.64 +#else
1.65 +_STLP_MOVE_TO_STD_NAMESPACE
1.66 +#endif
1.67 +
1.68 +/* When building STLport lib Digital Mars Compiler complains on the _M_data assignment
1.69 + * problem which would be perfertly right if we were using it. Hiding it during build
1.70 + * fix this issue.
1.71 + */
1.72 +template <class _Tp, class _Alloc>
1.73 +slist<_Tp,_Alloc>& slist<_Tp,_Alloc>::operator=(const slist<_Tp,_Alloc>& __x) {
1.74 + if (&__x != this) {
1.75 + _Node_base* __p1 = &this->_M_head._M_data;
1.76 + _Node_base* __n1 = this->_M_head._M_data._M_next;
1.77 + const _Node_base* __n2 = __x._M_head._M_data._M_next;
1.78 + while (__n1 && __n2) {
1.79 + __STATIC_CAST(_Node*, __n1)->_M_data = __STATIC_CAST(const _Node*, __n2)->_M_data;
1.80 + __p1 = __n1;
1.81 + __n1 = __n1->_M_next;
1.82 + __n2 = __n2->_M_next;
1.83 + }
1.84 + if (__n2 == 0)
1.85 + this->_M_erase_after(__p1, 0);
1.86 + else
1.87 + _M_insert_after_range(__p1, const_iterator(__CONST_CAST(_Node_base*, __n2)),
1.88 + const_iterator(0));
1.89 + }
1.90 + return *this;
1.91 +}
1.92 +
1.93 +template <class _Tp, class _Alloc>
1.94 +void slist<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) {
1.95 + _Node_base* __prev = &this->_M_head._M_data;
1.96 + _Node_base* __node = this->_M_head._M_data._M_next;
1.97 + for ( ; __node != 0 && __n > 0 ; --__n) {
1.98 + __STATIC_CAST(_Node*, __node)->_M_data = __val;
1.99 + __prev = __node;
1.100 + __node = __node->_M_next;
1.101 + }
1.102 + if (__n > 0)
1.103 + _M_insert_after_fill(__prev, __n, __val);
1.104 + else
1.105 + this->_M_erase_after(__prev, 0);
1.106 +}
1.107 +
1.108 +template <class _Tp, class _Alloc>
1.109 +void slist<_Tp,_Alloc>::resize(size_type __len, const _Tp& __x) {
1.110 + _Node_base* __cur = &this->_M_head._M_data;
1.111 + while (__cur->_M_next != 0 && __len > 0) {
1.112 + --__len;
1.113 + __cur = __cur->_M_next;
1.114 + }
1.115 + if (__cur->_M_next)
1.116 + this->_M_erase_after(__cur, 0);
1.117 + else
1.118 + _M_insert_after_fill(__cur, __len, __x);
1.119 +}
1.120 +
1.121 +template <class _Tp, class _Alloc>
1.122 +void slist<_Tp,_Alloc>::remove(const _Tp& __val) {
1.123 + _Node_base* __cur = &this->_M_head._M_data;
1.124 + while (__cur && __cur->_M_next) {
1.125 + if (__STATIC_CAST(_Node*, __cur->_M_next)->_M_data == __val)
1.126 + this->_M_erase_after(__cur);
1.127 + else
1.128 + __cur = __cur->_M_next;
1.129 + }
1.130 +}
1.131 +
1.132 +#if !defined (slist)
1.133 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.134 +#endif
1.135 +
1.136 +template <class _Tp, class _Alloc, class _BinaryPredicate>
1.137 +void _Slist_unique(slist<_Tp, _Alloc>& __that, _BinaryPredicate __pred) {
1.138 + typedef _Slist_node<_Tp> _Node;
1.139 + typename slist<_Tp, _Alloc>::iterator __ite(__that.begin());
1.140 + if (__ite != __that.end()) {
1.141 + while (__ite._M_node->_M_next) {
1.142 + if (__pred(*__ite, __STATIC_CAST(_Node*, __ite._M_node->_M_next)->_M_data))
1.143 + __that.erase_after(__ite);
1.144 + else
1.145 + ++__ite;
1.146 + }
1.147 + }
1.148 +}
1.149 +
1.150 +template <class _Tp, class _Alloc, class _StrictWeakOrdering>
1.151 +void _Slist_merge(slist<_Tp, _Alloc>& __that, slist<_Tp, _Alloc>& __x,
1.152 + _StrictWeakOrdering __comp) {
1.153 + typedef _Slist_node<_Tp> _Node;
1.154 + typedef _STLP_PRIV _Slist_node_base _Node_base;
1.155 + if (__that.get_allocator() == __x.get_allocator()) {
1.156 + typename slist<_Tp, _Alloc>::iterator __ite(__that.before_begin());
1.157 + while (__ite._M_node->_M_next && !__x.empty()) {
1.158 + if (__comp(__x.front(), __STATIC_CAST(_Node*, __ite._M_node->_M_next)->_M_data)) {
1.159 + _STLP_VERBOSE_ASSERT(!__comp(__STATIC_CAST(_Node*, __ite._M_node->_M_next)->_M_data, __x.front()),
1.160 + _StlMsg_INVALID_STRICT_WEAK_PREDICATE)
1.161 + __that.splice_after(__ite, __x, __x.before_begin());
1.162 + }
1.163 + ++__ite;
1.164 + }
1.165 + if (!__x.empty()) {
1.166 + __that.splice_after(__ite, __x);
1.167 + }
1.168 + }
1.169 + else {
1.170 + typename slist<_Tp, _Alloc>::iterator __i1(__that.before_begin()), __i2(__x.begin());
1.171 + while (__i1._M_node->_M_next && __i2._M_node) {
1.172 + if (__comp(__STATIC_CAST(_Node*, __i1._M_node->_M_next)->_M_data, *__i2)) {
1.173 + _STLP_VERBOSE_ASSERT(!__comp(*__i2, __STATIC_CAST(_Node*, __i1._M_node->_M_next)->_M_data),
1.174 + _StlMsg_INVALID_STRICT_WEAK_PREDICATE)
1.175 + ++__i1;
1.176 + }
1.177 + else {
1.178 + __i1 = __that.insert_after(__i1, *(__i2++));
1.179 + }
1.180 + }
1.181 + __that.insert_after(__i1, __i2, __x.end());
1.182 + __x.clear();
1.183 + }
1.184 +}
1.185 +
1.186 +template <class _Tp, class _Alloc, class _StrictWeakOrdering>
1.187 +void _Slist_sort(slist<_Tp, _Alloc>& __that, _StrictWeakOrdering __comp) {
1.188 + if (!__that.begin()._M_node || !__that.begin()._M_node->_M_next)
1.189 + return;
1.190 +
1.191 + slist<_Tp, _Alloc> __carry(__that.get_allocator());
1.192 + const int NB = 64;
1.193 + _STLP_PRIV _CArray<slist<_Tp, _Alloc>, NB> __counter(__carry);
1.194 + int __fill = 0;
1.195 + while (!__that.empty()) {
1.196 + __carry.splice_after(__carry.before_begin(), __that, __that.before_begin());
1.197 + int __i = 0;
1.198 + while (__i < __fill && !__counter[__i].empty()) {
1.199 + _STLP_PRIV _Slist_merge(__counter[__i], __carry, __comp);
1.200 + __carry.swap(__counter[__i]);
1.201 + ++__i;
1.202 + }
1.203 + __carry.swap(__counter[__i]);
1.204 + if (__i == __fill) {
1.205 + ++__fill;
1.206 + if (__fill >= NB) {
1.207 + //Looks like the slist has too many elements to be sorted with this algorithm:
1.208 + __stl_throw_overflow_error("slist::sort");
1.209 + }
1.210 + }
1.211 + }
1.212 +
1.213 + for (int __i = 1; __i < __fill; ++__i)
1.214 + _STLP_PRIV _Slist_merge(__counter[__i], __counter[__i - 1], __comp);
1.215 + __that.swap(__counter[__fill-1]);
1.216 +}
1.217 +
1.218 +#if defined (slist)
1.219 +# undef slist
1.220 +#endif
1.221 +
1.222 +_STLP_MOVE_TO_STD_NAMESPACE
1.223 +
1.224 +_STLP_END_NAMESPACE
1.225 +
1.226 +#if defined (_STLP_NESTED_TYPE_PARAM_BUG)
1.227 +# undef size_type
1.228 +#endif
1.229 +
1.230 +#endif /* _STLP_SLIST_C */
1.231 +
1.232 +// Local Variables:
1.233 +// mode:C++
1.234 +// End: