epoc32/include/stdapis/stlport/stl/_list.c
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
     1.1 --- a/epoc32/include/stdapis/stlport/stl/_list.c	Tue Nov 24 13:55:44 2009 +0000
     1.2 +++ b/epoc32/include/stdapis/stlport/stl/_list.c	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -1,1 +1,252 @@
     1.4 -_list.c
     1.5 +/*
     1.6 + *
     1.7 + *
     1.8 + * Copyright (c) 1994
     1.9 + * Hewlett-Packard Company
    1.10 + *
    1.11 + * Copyright (c) 1996,1997
    1.12 + * Silicon Graphics Computer Systems, Inc.
    1.13 + *
    1.14 + * Copyright (c) 1997
    1.15 + * Moscow Center for SPARC Technology
    1.16 + *
    1.17 + * Copyright (c) 1999 
    1.18 + * Boris Fomitchev
    1.19 + *
    1.20 + * This material is provided "as is", with absolutely no warranty expressed
    1.21 + * or implied. Any use is at your own risk.
    1.22 + *
    1.23 + * Permission to use or copy this software for any purpose is hereby granted 
    1.24 + * without fee, provided the above notices are retained on all copies.
    1.25 + * Permission to modify the code and to distribute modified code is granted,
    1.26 + * provided the above notices are retained, and a notice that the code was
    1.27 + * modified is included with the above copyright notice.
    1.28 + *
    1.29 + */
    1.30 +#ifndef _STLP_LIST_C
    1.31 +#define _STLP_LIST_C
    1.32 +
    1.33 +#ifndef _STLP_INTERNAL_LIST_H
    1.34 +# include <stl/_list.h>
    1.35 +#endif
    1.36 +
    1.37 +#if defined (__WATCOMC__) || defined (_STLP_USE_TRAP_LEAVE)
    1.38 +#include <vector>
    1.39 +#endif
    1.40 +
    1.41 +# undef list
    1.42 +# define  list  __WORKAROUND_DBG_RENAME(list)
    1.43 +
    1.44 +_STLP_BEGIN_NAMESPACE
    1.45 +
    1.46 +# if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION)
    1.47 +
    1.48 +template <class _Dummy>
    1.49 +void _STLP_CALL
    1.50 +_List_global<_Dummy>::_Transfer(_List_node_base* __position, 
    1.51 +				_List_node_base* __first, _List_node_base* __last) {
    1.52 +  if (__position != __last) {
    1.53 +    // Remove [first, last) from its old position.
    1.54 +    ((_Node*) (__last->_M_prev))->_M_next = __position;
    1.55 +    ((_Node*) (__first->_M_prev))->_M_next    = __last;
    1.56 +    ((_Node*) (__position->_M_prev))->_M_next = __first; 
    1.57 +    
    1.58 +    // Splice [first, last) into its new position.
    1.59 +    _Node* __tmp = (_Node*) (__position->_M_prev);
    1.60 +    __position->_M_prev = __last->_M_prev;
    1.61 +    __last->_M_prev      = __first->_M_prev; 
    1.62 +    __first->_M_prev    = __tmp;
    1.63 +  }
    1.64 +}
    1.65 +
    1.66 +#endif /* defined (__BUILDING_STLPORT) || ! defined (_STLP_OWN_IOSTREAMS) */
    1.67 +
    1.68 +
    1.69 +template <class _Tp, class _Alloc>
    1.70 +void 
    1.71 +_List_base<_Tp,_Alloc>::clear() 
    1.72 +{
    1.73 +  _List_node<_Tp>* __cur = this->_M_node._M_data;
    1.74 +  if (!__cur)
    1.75 +	return;
    1.76 +  __cur = (_List_node<_Tp>*)__cur->_M_next;
    1.77 +  while (__cur != this->_M_node._M_data) {
    1.78 +    _List_node<_Tp>* __tmp = __cur;
    1.79 +    __cur = (_List_node<_Tp>*) __cur->_M_next;
    1.80 +    _STLP_STD::_Destroy(&__tmp->_M_data);
    1.81 +    this->_M_node.deallocate(__tmp, 1);
    1.82 +  }
    1.83 +  this->_M_node._M_data->_M_next = this->_M_node._M_data;
    1.84 +  this->_M_node._M_data->_M_prev = this->_M_node._M_data;
    1.85 +}
    1.86 +
    1.87 +# if defined (_STLP_NESTED_TYPE_PARAM_BUG) 
    1.88 +#  define size_type      size_t
    1.89 +# endif
    1.90 +
    1.91 +template <class _Tp, class _Alloc>
    1.92 +void list<_Tp, _Alloc>::resize(size_type __new_size, _Tp __x)
    1.93 +{
    1.94 +  iterator __i = begin();
    1.95 +  size_type __len = 0;
    1.96 +  for ( ; __i != end() && __len < __new_size; ++__i, ++__len);
    1.97 +
    1.98 +  if (__len == __new_size)
    1.99 +    erase(__i, end());
   1.100 +  else                          // __i == end()
   1.101 +    insert(end(), __new_size - __len, __x);
   1.102 +}
   1.103 +
   1.104 +template <class _Tp, class _Alloc>
   1.105 +list<_Tp, _Alloc>& list<_Tp, _Alloc>::operator=(const list<_Tp, _Alloc>& __x)
   1.106 +{
   1.107 +  if (this != &__x) {
   1.108 +    iterator __first1 = begin();
   1.109 +    iterator __last1 = end();
   1.110 +    const_iterator __first2 = __x.begin();
   1.111 +    const_iterator __last2 = __x.end();
   1.112 +    while (__first1 != __last1 && __first2 != __last2) 
   1.113 +      *__first1++ = *__first2++;
   1.114 +    if (__first2 == __last2)
   1.115 +      erase(__first1, __last1);
   1.116 +    else
   1.117 +      insert(__last1, __first2, __last2);
   1.118 +  }
   1.119 +  return *this;
   1.120 +}
   1.121 +
   1.122 +template <class _Tp, class _Alloc>
   1.123 +void list<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) {
   1.124 +  iterator __i = begin();
   1.125 +  for ( ; __i != end() && __n > 0; ++__i, --__n)
   1.126 +    *__i = __val;
   1.127 +  if (__n > 0)
   1.128 +    insert(end(), __n, __val);
   1.129 +  else
   1.130 +    erase(__i, end());
   1.131 +}
   1.132 +
   1.133 +template <class _Tp, class _Alloc, class _Predicate> 
   1.134 +void _S_remove_if(list<_Tp, _Alloc>& __that, _Predicate __pred)  {
   1.135 +  typename list<_Tp, _Alloc>::iterator __first = __that.begin();
   1.136 +  typename list<_Tp, _Alloc>::iterator __last = __that.end();
   1.137 +  while (__first != __last) {
   1.138 +    typename list<_Tp, _Alloc>::iterator __next = __first;
   1.139 +    ++__next;
   1.140 +    if (__pred(*__first)) __that.erase(__first);
   1.141 +    __first = __next;
   1.142 +  }
   1.143 +}
   1.144 +
   1.145 +template <class _Tp, class _Alloc, class _BinaryPredicate>
   1.146 +void _S_unique(list<_Tp, _Alloc>& __that, _BinaryPredicate __binary_pred) {
   1.147 +  typename list<_Tp, _Alloc>::iterator __first = __that.begin();
   1.148 +  typename list<_Tp, _Alloc>::iterator __last = __that.end();
   1.149 +  if (__first == __last) return;
   1.150 +  typename list<_Tp, _Alloc>::iterator __next = __first;
   1.151 +  while (++__next != __last) {
   1.152 +    if (__binary_pred(*__first, *__next))
   1.153 +      __that.erase(__next);
   1.154 +    else
   1.155 +      __first = __next;
   1.156 +    __next = __first;
   1.157 +  }
   1.158 +}
   1.159 +
   1.160 +template <class _Tp, class _Alloc, class _StrictWeakOrdering>
   1.161 +void _S_merge(list<_Tp, _Alloc>& __that, list<_Tp, _Alloc>& __x,
   1.162 +	      _StrictWeakOrdering __comp) {
   1.163 +  typedef typename list<_Tp, _Alloc>::iterator _Literator;
   1.164 +  _Literator __first1 = __that.begin();
   1.165 +  _Literator __last1 = __that.end();
   1.166 +  _Literator __first2 = __x.begin();
   1.167 +  _Literator __last2 = __x.end();
   1.168 +  while (__first1 != __last1 && __first2 != __last2)
   1.169 +    if (__comp(*__first2, *__first1)) {
   1.170 +      _Literator __next = __first2;
   1.171 +      _List_global_inst::_Transfer(__first1._M_node, __first2._M_node, (++__next)._M_node);
   1.172 +      __first2 = __next;
   1.173 +    }
   1.174 +    else
   1.175 +      ++__first1;
   1.176 +  if (__first2 != __last2) _List_global_inst::_Transfer(__last1._M_node, __first2._M_node, __last2._M_node);
   1.177 +}
   1.178 +
   1.179 +template <class _Tp, class _Alloc, class _StrictWeakOrdering>
   1.180 +void _S_sort(list<_Tp, _Alloc>& __that, _StrictWeakOrdering __comp) {
   1.181 +  // Do nothing if the list has length 0 or 1.
   1.182 +  if (__that._M_node._M_data->_M_next != __that._M_node._M_data &&
   1.183 +      (__that._M_node._M_data->_M_next)->_M_next != __that._M_node._M_data) {
   1.184 +
   1.185 +#if !defined (__WATCOMC__)
   1.186 +#ifdef _STLP_USE_TRAP_LEAVE
   1.187 +    typedef vector<list<_Tp, _Alloc>*, _Alloc>  _TmpVec;
   1.188 +    _TmpVec* __pTmp = new _TmpVec();
   1.189 +    _TmpVec& __counter = *__pTmp;
   1.190 +    for (int i = 0; 1< 64; ++i) {
   1.191 +      list<_Tp, _Alloc>* __pTmp2 = new list<_Tp, _Alloc>;
   1.192 +      __counter.push_back (__pTmp2);
   1.193 +    }
   1.194 +    list<_Tp, _Alloc>* __pcarry = new list<_Tp, _Alloc>;
   1.195 +    list<_Tp, _Alloc>& __carry = *__pcarry;
   1.196 +#else
   1.197 +    list<_Tp, _Alloc> __counter[64];
   1.198 +    list<_Tp, _Alloc> __carry;
   1.199 +#endif
   1.200 +#else
   1.201 +    list<_Tp, _Alloc> __carry;
   1.202 +    __vector__<list<_Tp, _Alloc>, _Alloc> __counter(64);		
   1.203 +#endif
   1.204 +    int __fill = 0;
   1.205 +#ifdef _STLP_USE_TRAP_LEAVE
   1.206 +    while (!__that.empty()) {
   1.207 +      __carry.splice(__carry.begin(), __that, __that.begin());
   1.208 +      int __i = 0;
   1.209 +
   1.210 +      while(__i < __fill && !__counter[__i]->empty()) {
   1.211 +	_S_merge(*__counter[__i], __carry, __comp);
   1.212 +	__carry.swap(*__counter[__i++]);
   1.213 +      }
   1.214 +      __carry.swap(*__counter[__i]);         
   1.215 +      if (__i == __fill) ++__fill;
   1.216 +    } 
   1.217 +    
   1.218 +    for (int __i = 1; __i < __fill; ++__i) 
   1.219 +      _S_merge(*__counter[__i], *__counter[__i-1], __comp);
   1.220 +    __that.swap(*__counter[__fill-1]);
   1.221 +
   1.222 +    // those objects won't just go away
   1.223 +    __counter.clear();
   1.224 +    CleanupStack::Pop(66);
   1.225 +  }    
   1.226 +# else
   1.227 +    while (!__that.empty()) {
   1.228 +      __carry.splice(__carry.begin(), __that, __that.begin());
   1.229 +      int __i = 0;
   1.230 +
   1.231 +      while(__i < __fill && !__counter[__i].empty()) {
   1.232 +	_S_merge(__counter[__i], __carry, __comp);
   1.233 +	__carry.swap(__counter[__i++]);
   1.234 +      }
   1.235 +      __carry.swap(__counter[__i]);         
   1.236 +      if (__i == __fill) ++__fill;
   1.237 +    } 
   1.238 +    
   1.239 +    for (int __i = 1; __i < __fill; ++__i) 
   1.240 +      _S_merge(__counter[__i], __counter[__i-1], __comp);
   1.241 +    __that.swap(__counter[__fill-1]);
   1.242 +  }
   1.243 +# endif
   1.244 +
   1.245 +}
   1.246 +
   1.247 +# undef  list
   1.248 +# undef  size_type
   1.249 +
   1.250 +_STLP_END_NAMESPACE
   1.251 +
   1.252 +#endif /*  _STLP_LIST_C */
   1.253 +
   1.254 +// Local Variables:
   1.255 +// mode:C++
   1.256 +// End: