1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/stlport/stl/_slist.c Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,179 @@
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 +# undef slist
1.30 +# define slist __WORKAROUND_DBG_RENAME(slist)
1.31 +# if defined (_STLP_NESTED_TYPE_PARAM_BUG)
1.32 +# define size_type size_t
1.33 +# endif
1.34 +
1.35 +_STLP_BEGIN_NAMESPACE
1.36 +
1.37 +template <class _Tp, class _Alloc>
1.38 +_Slist_node_base*
1.39 +_Slist_base<_Tp,_Alloc>::_M_erase_after(_Slist_node_base* __before_first,
1.40 + _Slist_node_base* __last_node) {
1.41 + _Slist_node<_Tp>* __cur = (_Slist_node<_Tp>*) (__before_first->_M_next);
1.42 + while (__cur != __last_node) {
1.43 + _Slist_node<_Tp>* __tmp = __cur;
1.44 + __cur = (_Slist_node<_Tp>*) __cur->_M_next;
1.45 + _STLP_STD::_Destroy(&__tmp->_M_data);
1.46 + _M_head.deallocate(__tmp,1);
1.47 + }
1.48 + __before_first->_M_next = __last_node;
1.49 + return __last_node;
1.50 +}
1.51 +
1.52 +template <class _Tp, class _Alloc>
1.53 +slist<_Tp,_Alloc>& slist<_Tp,_Alloc>::operator=(const slist<_Tp,_Alloc>& __x)
1.54 +{
1.55 + if (&__x != this) {
1.56 + _Node_base* __p1 = &this->_M_head._M_data;
1.57 + _Node* __n1 = (_Node*) this->_M_head._M_data._M_next;
1.58 + const _Node* __n2 = (const _Node*) __x._M_head._M_data._M_next;
1.59 + while (__n1 && __n2) {
1.60 + __n1->_M_data = __n2->_M_data;
1.61 + __p1 = __n1;
1.62 + __n1 = (_Node*) __n1->_M_next;
1.63 + __n2 = (const _Node*) __n2->_M_next;
1.64 + }
1.65 + if (__n2 == 0)
1.66 + this->_M_erase_after(__p1, 0);
1.67 + else
1.68 + _M_insert_after_range(__p1, const_iterator((_Node*)__n2),
1.69 + const_iterator(0));
1.70 + }
1.71 + return *this;
1.72 +}
1.73 +
1.74 +template <class _Tp, class _Alloc>
1.75 +void slist<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) {
1.76 + _Node_base* __prev = &this->_M_head._M_data;
1.77 + _Node* __node = (_Node*) this->_M_head._M_data._M_next;
1.78 + for ( ; __node != 0 && __n > 0 ; --__n) {
1.79 + __node->_M_data = __val;
1.80 + __prev = __node;
1.81 + __node = (_Node*) __node->_M_next;
1.82 + }
1.83 + if (__n > 0)
1.84 + _M_insert_after_fill(__prev, __n, __val);
1.85 + else
1.86 + this->_M_erase_after(__prev, 0);
1.87 +}
1.88 +
1.89 +
1.90 +template <class _Tp, class _Alloc>
1.91 +void slist<_Tp,_Alloc>::resize(size_type __len, const _Tp& __x)
1.92 +{
1.93 + _Node_base* __cur = &this->_M_head._M_data;
1.94 + while (__cur->_M_next != 0 && __len > 0) {
1.95 + --__len;
1.96 + __cur = __cur->_M_next;
1.97 + }
1.98 + if (__cur->_M_next)
1.99 + this->_M_erase_after(__cur, 0);
1.100 + else
1.101 + _M_insert_after_fill(__cur, __len, __x);
1.102 +}
1.103 +
1.104 +template <class _Tp, class _Alloc>
1.105 +void slist<_Tp,_Alloc>::remove(const _Tp& __val)
1.106 +{
1.107 + _Node_base* __cur = &this->_M_head._M_data;
1.108 + while (__cur && __cur->_M_next) {
1.109 + if (((_Node*) __cur->_M_next)->_M_data == __val)
1.110 + this->_M_erase_after(__cur);
1.111 + else
1.112 + __cur = __cur->_M_next;
1.113 + }
1.114 +}
1.115 +
1.116 +template <class _Tp, class _Alloc>
1.117 +void slist<_Tp,_Alloc>::unique()
1.118 +{
1.119 + _Node_base* __cur = this->_M_head._M_data._M_next;
1.120 + if (__cur) {
1.121 + while (__cur->_M_next) {
1.122 + if (((_Node*)__cur)->_M_data ==
1.123 + ((_Node*)(__cur->_M_next))->_M_data)
1.124 + this->_M_erase_after(__cur);
1.125 + else
1.126 + __cur = __cur->_M_next;
1.127 + }
1.128 + }
1.129 +}
1.130 +
1.131 +template <class _Tp, class _Alloc>
1.132 +void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x)
1.133 +{
1.134 + _Node_base* __n1 = &this->_M_head._M_data;
1.135 + while (__n1->_M_next && __x._M_head._M_data._M_next) {
1.136 + if (((_Node*) __x._M_head._M_data._M_next)->_M_data <
1.137 + ((_Node*) __n1->_M_next)->_M_data)
1.138 + _Sl_global_inst::__splice_after(__n1, &__x._M_head._M_data, __x._M_head._M_data._M_next);
1.139 + __n1 = __n1->_M_next;
1.140 + }
1.141 + if (__x._M_head._M_data._M_next) {
1.142 + __n1->_M_next = __x._M_head._M_data._M_next;
1.143 + __x._M_head._M_data._M_next = 0;
1.144 + }
1.145 +}
1.146 +
1.147 +template <class _Tp, class _Alloc>
1.148 +void slist<_Tp,_Alloc>::sort()
1.149 +{
1.150 + if (this->_M_head._M_data._M_next && this->_M_head._M_data._M_next->_M_next) {
1.151 + _Self __carry;
1.152 + _Self __counter[64];
1.153 + int __fill = 0;
1.154 + while (!empty()) {
1.155 + _Sl_global_inst::__splice_after(&__carry._M_head._M_data, &this->_M_head._M_data, this->_M_head._M_data._M_next);
1.156 + int __i = 0;
1.157 + while (__i < __fill && !__counter[__i].empty()) {
1.158 + __counter[__i].merge(__carry);
1.159 + __carry.swap(__counter[__i]);
1.160 + ++__i;
1.161 + }
1.162 + __carry.swap(__counter[__i]);
1.163 + if (__i == __fill)
1.164 + ++__fill;
1.165 + }
1.166 +
1.167 + for (int __i = 1; __i < __fill; ++__i)
1.168 + __counter[__i].merge(__counter[__i-1]);
1.169 + this->swap(__counter[__fill-1]);
1.170 + }
1.171 +}
1.172 +
1.173 +# undef slist
1.174 +# undef size_type
1.175 +
1.176 +_STLP_END_NAMESPACE
1.177 +
1.178 +#endif /* _STLP_SLIST_C */
1.179 +
1.180 +// Local Variables:
1.181 +// mode:C++
1.182 +// End: