epoc32/include/stdapis/stlport/stl/_slist.c
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
     1.1 --- a/epoc32/include/stdapis/stlport/stl/_slist.c	Tue Nov 24 13:55:44 2009 +0000
     1.2 +++ b/epoc32/include/stdapis/stlport/stl/_slist.c	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -1,1 +1,179 @@
     1.4 -_slist.c
     1.5 +/*
     1.6 + *
     1.7 + * Copyright (c) 1996,1997
     1.8 + * Silicon Graphics Computer Systems, Inc.
     1.9 + *
    1.10 + * Copyright (c) 1999 
    1.11 + * Boris Fomitchev
    1.12 + *
    1.13 + * This material is provided "as is", with absolutely no warranty expressed
    1.14 + * or implied. Any use is at your own risk.
    1.15 + *
    1.16 + * Permission to use or copy this software for any purpose is hereby granted 
    1.17 + * without fee, provided the above notices are retained on all copies.
    1.18 + * Permission to modify the code and to distribute modified code is granted,
    1.19 + * provided the above notices are retained, and a notice that the code was
    1.20 + * modified is included with the above copyright notice.
    1.21 + *
    1.22 + */
    1.23 +#ifndef _STLP_SLIST_C
    1.24 +#define _STLP_SLIST_C
    1.25 +
    1.26 +#ifndef _STLP_INTERNAL_SLIST_H
    1.27 +# include <stl/_slist.h>
    1.28 +#endif
    1.29 +
    1.30 +# undef slist
    1.31 +# define  slist  __WORKAROUND_DBG_RENAME(slist)
    1.32 +# if defined (_STLP_NESTED_TYPE_PARAM_BUG) 
    1.33 +#  define size_type          size_t
    1.34 +# endif
    1.35 +
    1.36 +_STLP_BEGIN_NAMESPACE
    1.37 +
    1.38 +template <class _Tp, class _Alloc> 
    1.39 +_Slist_node_base*
    1.40 +_Slist_base<_Tp,_Alloc>::_M_erase_after(_Slist_node_base* __before_first,
    1.41 +                                        _Slist_node_base* __last_node) {
    1.42 +  _Slist_node<_Tp>* __cur = (_Slist_node<_Tp>*) (__before_first->_M_next);
    1.43 +  while (__cur != __last_node) {
    1.44 +    _Slist_node<_Tp>* __tmp = __cur;
    1.45 +    __cur = (_Slist_node<_Tp>*) __cur->_M_next;
    1.46 +    _STLP_STD::_Destroy(&__tmp->_M_data);
    1.47 +    _M_head.deallocate(__tmp,1);
    1.48 +  }
    1.49 +  __before_first->_M_next = __last_node;
    1.50 +  return __last_node;
    1.51 +}
    1.52 +
    1.53 +template <class _Tp, class _Alloc>
    1.54 +slist<_Tp,_Alloc>& slist<_Tp,_Alloc>::operator=(const slist<_Tp,_Alloc>& __x)
    1.55 +{
    1.56 +  if (&__x != this) {
    1.57 +    _Node_base* __p1 = &this->_M_head._M_data;
    1.58 +    _Node* __n1 = (_Node*) this->_M_head._M_data._M_next;
    1.59 +    const _Node* __n2 = (const _Node*) __x._M_head._M_data._M_next;
    1.60 +    while (__n1 && __n2) {
    1.61 +      __n1->_M_data = __n2->_M_data;
    1.62 +      __p1 = __n1;
    1.63 +      __n1 = (_Node*) __n1->_M_next;
    1.64 +      __n2 = (const _Node*) __n2->_M_next;
    1.65 +    }
    1.66 +    if (__n2 == 0)
    1.67 +      this->_M_erase_after(__p1, 0);
    1.68 +    else
    1.69 +      _M_insert_after_range(__p1, const_iterator((_Node*)__n2), 
    1.70 +                                  const_iterator(0));
    1.71 +  }
    1.72 +  return *this;
    1.73 +}
    1.74 +
    1.75 +template <class _Tp, class _Alloc>
    1.76 +void slist<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) {
    1.77 +  _Node_base* __prev = &this->_M_head._M_data;
    1.78 +  _Node* __node = (_Node*) this->_M_head._M_data._M_next;
    1.79 +  for ( ; __node != 0 && __n > 0 ; --__n) {
    1.80 +    __node->_M_data = __val;
    1.81 +    __prev = __node;
    1.82 +    __node = (_Node*) __node->_M_next;
    1.83 +  }
    1.84 +  if (__n > 0)
    1.85 +    _M_insert_after_fill(__prev, __n, __val);
    1.86 +  else
    1.87 +    this->_M_erase_after(__prev, 0);
    1.88 +}
    1.89 +
    1.90 +
    1.91 +template <class _Tp, class _Alloc>
    1.92 +void slist<_Tp,_Alloc>::resize(size_type __len, const _Tp& __x)
    1.93 +{
    1.94 +  _Node_base* __cur = &this->_M_head._M_data;
    1.95 +  while (__cur->_M_next != 0 && __len > 0) {
    1.96 +    --__len;
    1.97 +    __cur = __cur->_M_next;
    1.98 +  }
    1.99 +  if (__cur->_M_next) 
   1.100 +    this->_M_erase_after(__cur, 0);
   1.101 +  else
   1.102 +    _M_insert_after_fill(__cur, __len, __x);
   1.103 +}
   1.104 +
   1.105 +template <class _Tp, class _Alloc>
   1.106 +void slist<_Tp,_Alloc>::remove(const _Tp& __val)
   1.107 +{
   1.108 +  _Node_base* __cur = &this->_M_head._M_data;
   1.109 +  while (__cur && __cur->_M_next) {
   1.110 +    if (((_Node*) __cur->_M_next)->_M_data == __val)
   1.111 +      this->_M_erase_after(__cur);
   1.112 +    else
   1.113 +      __cur = __cur->_M_next;
   1.114 +  }
   1.115 +}
   1.116 +
   1.117 +template <class _Tp, class _Alloc> 
   1.118 +void slist<_Tp,_Alloc>::unique()
   1.119 +{
   1.120 +  _Node_base* __cur = this->_M_head._M_data._M_next;
   1.121 +  if (__cur) {
   1.122 +    while (__cur->_M_next) {
   1.123 +      if (((_Node*)__cur)->_M_data == 
   1.124 +          ((_Node*)(__cur->_M_next))->_M_data)
   1.125 +        this->_M_erase_after(__cur);
   1.126 +      else
   1.127 +        __cur = __cur->_M_next;
   1.128 +    }
   1.129 +  }
   1.130 +}
   1.131 +
   1.132 +template <class _Tp, class _Alloc>
   1.133 +void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x)
   1.134 +{
   1.135 +  _Node_base* __n1 = &this->_M_head._M_data;
   1.136 +  while (__n1->_M_next && __x._M_head._M_data._M_next) {
   1.137 +    if (((_Node*) __x._M_head._M_data._M_next)->_M_data < 
   1.138 +        ((_Node*)       __n1->_M_next)->_M_data) 
   1.139 +      _Sl_global_inst::__splice_after(__n1, &__x._M_head._M_data, __x._M_head._M_data._M_next);
   1.140 +    __n1 = __n1->_M_next;
   1.141 +  }
   1.142 +  if (__x._M_head._M_data._M_next) {
   1.143 +    __n1->_M_next = __x._M_head._M_data._M_next;
   1.144 +    __x._M_head._M_data._M_next = 0;
   1.145 +  }
   1.146 +}
   1.147 +
   1.148 +template <class _Tp, class _Alloc>
   1.149 +void slist<_Tp,_Alloc>::sort()
   1.150 +{
   1.151 +  if (this->_M_head._M_data._M_next && this->_M_head._M_data._M_next->_M_next) {
   1.152 +    _Self __carry;
   1.153 +    _Self __counter[64];
   1.154 +    int __fill = 0;
   1.155 +    while (!empty()) {
   1.156 +      _Sl_global_inst::__splice_after(&__carry._M_head._M_data, &this->_M_head._M_data, this->_M_head._M_data._M_next);
   1.157 +      int __i = 0;
   1.158 +      while (__i < __fill && !__counter[__i].empty()) {
   1.159 +        __counter[__i].merge(__carry);
   1.160 +        __carry.swap(__counter[__i]);
   1.161 +        ++__i;
   1.162 +      }
   1.163 +      __carry.swap(__counter[__i]);
   1.164 +      if (__i == __fill)
   1.165 +        ++__fill;
   1.166 +    }
   1.167 +
   1.168 +    for (int __i = 1; __i < __fill; ++__i)
   1.169 +      __counter[__i].merge(__counter[__i-1]);
   1.170 +    this->swap(__counter[__fill-1]);
   1.171 +  }
   1.172 +}
   1.173 +
   1.174 +# undef slist
   1.175 +# undef size_type
   1.176 +
   1.177 +_STLP_END_NAMESPACE
   1.178 +
   1.179 +#endif /*  _STLP_SLIST_C */
   1.180 +
   1.181 +// Local Variables:
   1.182 +// mode:C++
   1.183 +// End: