ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

_list.c
Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Copyright (c) 1994
00005  * Hewlett-Packard Company
00006  *
00007  * Copyright (c) 1996,1997
00008  * Silicon Graphics Computer Systems, Inc.
00009  *
00010  * Copyright (c) 1997
00011  * Moscow Center for SPARC Technology
00012  *
00013  * Copyright (c) 1999
00014  * Boris Fomitchev
00015  *
00016  * This material is provided "as is", with absolutely no warranty expressed
00017  * or implied. Any use is at your own risk.
00018  *
00019  * Permission to use or copy this software for any purpose is hereby granted
00020  * without fee, provided the above notices are retained on all copies.
00021  * Permission to modify the code and to distribute modified code is granted,
00022  * provided the above notices are retained, and a notice that the code was
00023  * modified is included with the above copyright notice.
00024  *
00025  */
00026 #ifndef _STLP_LIST_C
00027 #define _STLP_LIST_C
00028 
00029 #ifndef _STLP_INTERNAL_LIST_H
00030 #  include <stl/_list.h>
00031 #endif
00032 
00033 #ifndef _STLP_CARRAY_H
00034 #  include <stl/_carray.h>
00035 #endif
00036 
00037 #ifndef _STLP_RANGE_ERRORS_H
00038 #  include <stl/_range_errors.h>
00039 #endif
00040 
00041 _STLP_BEGIN_NAMESPACE
00042 
00043 _STLP_MOVE_TO_PRIV_NAMESPACE
00044 
00045 #if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION)
00046 template <class _Dummy>
00047 void _STLP_CALL
00048 _List_global<_Dummy>::_Transfer(_List_node_base* __position,
00049                                 _List_node_base* __first, _List_node_base* __last) {
00050   if (__position != __last) {
00051     // Remove [first, last) from its old position.
00052     __last->_M_prev->_M_next     = __position;
00053     __first->_M_prev->_M_next    = __last;
00054     __position->_M_prev->_M_next = __first;
00055 
00056     // Splice [first, last) into its new position.
00057     _Node_base* __tmp = __position->_M_prev;
00058     __position->_M_prev = __last->_M_prev;
00059     __last->_M_prev     = __first->_M_prev;
00060     __first->_M_prev    = __tmp;
00061   }
00062 }
00063 #endif /* _STLP_EXPOSE_GLOBALS_IMPLEMENTATION */
00064 
00065 template <class _Tp, class _Alloc>
00066 void _List_base<_Tp,_Alloc>::clear() {
00067   _Node* __cur = __STATIC_CAST(_Node*, _M_node._M_data._M_next);
00068   while (
00069 #if defined (__BORLANDC__) // runtime error
00070          __cur &&
00071 #endif
00072          __cur != &(_M_node._M_data)) {
00073     _Node* __tmp = __cur;
00074     __cur = __STATIC_CAST(_Node*, __cur->_M_next);
00075     _STLP_STD::_Destroy(&__tmp->_M_data);
00076     this->_M_node.deallocate(__tmp, 1);
00077   }
00078   _M_node._M_data._M_next = &_M_node._M_data;
00079   _M_node._M_data._M_prev = &_M_node._M_data;
00080 }
00081 
00082 #if defined (_STLP_NESTED_TYPE_PARAM_BUG)
00083 #  define size_type size_t
00084 #endif
00085 
00086 #if defined (_STLP_USE_PTR_SPECIALIZATIONS)
00087 #  define list _STLP_PTR_IMPL_NAME(list)
00088 #elif defined (_STLP_DEBUG)
00089 #  define list _STLP_NON_DBG_NAME(list)
00090 #else
00091 _STLP_MOVE_TO_STD_NAMESPACE
00092 #endif
00093 
00094 template <class _Tp, class _Alloc>
00095 void list<_Tp, _Alloc>::resize(size_type __new_size, const _Tp& __x) {
00096   iterator __i = begin();
00097   size_type __len = 0;
00098   for ( ; __i != end() && __len < __new_size; ++__i, ++__len);
00099 
00100   if (__len == __new_size)
00101     erase(__i, end());
00102   else // __i == end()
00103     insert(end(), __new_size - __len, __x);
00104 }
00105 
00106 template <class _Tp, class _Alloc>
00107 list<_Tp, _Alloc>& list<_Tp, _Alloc>::operator=(const list<_Tp, _Alloc>& __x) {
00108   if (this != &__x) {
00109     iterator __first1 = begin();
00110     iterator __last1 = end();
00111     const_iterator __first2 = __x.begin();
00112     const_iterator __last2 = __x.end();
00113     while (__first1 != __last1 && __first2 != __last2)
00114       *__first1++ = *__first2++;
00115     if (__first2 == __last2)
00116       erase(__first1, __last1);
00117     else
00118       insert(__last1, __first2, __last2);
00119   }
00120   return *this;
00121 }
00122 
00123 template <class _Tp, class _Alloc>
00124 void list<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) {
00125   iterator __i = begin();
00126   for ( ; __i != end() && __n > 0; ++__i, --__n)
00127     *__i = __val;
00128   if (__n > 0)
00129     insert(end(), __n, __val);
00130   else
00131     erase(__i, end());
00132 }
00133 
00134 #if !defined (list)
00135 _STLP_MOVE_TO_PRIV_NAMESPACE
00136 #endif
00137 
00138 template <class _Tp, class _Alloc, class _Predicate>
00139 void _S_remove_if(list<_Tp, _Alloc>& __that, _Predicate __pred)  {
00140   typedef typename list<_Tp, _Alloc>::iterator _Literator;
00141   _Literator __first = __that.begin();
00142   _Literator __last = __that.end();
00143   while (__first != __last) {
00144     _Literator __next = __first;
00145     ++__next;
00146     if (__pred(*__first)) __that.erase(__first);
00147     __first = __next;
00148   }
00149 }
00150 
00151 template <class _Tp, class _Alloc, class _BinaryPredicate>
00152 void _S_unique(list<_Tp, _Alloc>& __that, _BinaryPredicate __binary_pred) {
00153   typedef typename list<_Tp, _Alloc>::iterator _Literator;
00154   _Literator __first = __that.begin();
00155   _Literator __last = __that.end();
00156   if (__first == __last) return;
00157   _Literator __next = __first;
00158   while (++__next != __last) {
00159     if (__binary_pred(*__first, *__next))
00160       __that.erase(__next);
00161     else
00162       __first = __next;
00163     __next = __first;
00164   }
00165 }
00166 
00167 template <class _Tp, class _Alloc, class _StrictWeakOrdering>
00168 void _S_merge(list<_Tp, _Alloc>& __that, list<_Tp, _Alloc>& __x,
00169               _StrictWeakOrdering __comp) {
00170   typedef typename list<_Tp, _Alloc>::iterator _Literator;
00171   _Literator __first1 = __that.begin();
00172   _Literator __last1 = __that.end();
00173   _Literator __first2 = __x.begin();
00174   _Literator __last2 = __x.end();
00175   if (__that.get_allocator() == __x.get_allocator()) {
00176     while (__first1 != __last1 && __first2 != __last2) {
00177       if (__comp(*__first2, *__first1)) {
00178         _STLP_VERBOSE_ASSERT(!__comp(*__first1, *__first2), _StlMsg_INVALID_STRICT_WEAK_PREDICATE)
00179         _Literator __next = __first2;
00180         _List_global_inst::_Transfer(__first1._M_node, __first2._M_node, (++__next)._M_node);
00181         __first2 = __next;
00182       }
00183       else
00184         ++__first1;
00185     }
00186     if (__first2 != __last2)
00187       _List_global_inst::_Transfer(__last1._M_node, __first2._M_node, __last2._M_node);
00188   }
00189   else {
00190     while (__first1 != __last1 && __first2 != __last2) {
00191       if (__comp(*__first2, *__first1)) {
00192         _STLP_VERBOSE_ASSERT(!__comp(*__first1, *__first2), _StlMsg_INVALID_STRICT_WEAK_PREDICATE)
00193         __first1 = __that.insert(__first1, *__first2);
00194       }
00195       else
00196         ++__first1;
00197     }
00198     if (__first2 != __last2) {
00199       __that.insert(__first1, __first2, __last2);
00200     }
00201     __x.clear();
00202   }
00203 }
00204 
00205 template <class _Tp, class _Alloc, class _StrictWeakOrdering>
00206 void _S_sort(list<_Tp, _Alloc>& __that, _StrictWeakOrdering __comp) {
00207   // Do nothing if the list has length 0 or 1.
00208   if (__that._M_node._M_data._M_next == &__that._M_node._M_data ||
00209       __that._M_node._M_data._M_next->_M_next == &__that._M_node._M_data)
00210     return;
00211 
00212   list<_Tp, _Alloc> __carry(__that.get_allocator());
00213   const int NB = 64;
00214   _STLP_PRIV _CArray<list<_Tp, _Alloc>, NB> __counter(__carry);
00215   int __fill = 0;
00216   while (!__that.empty()) {
00217     __carry.splice(__carry.begin(), __that, __that.begin());
00218     int __i = 0;
00219     while (__i < __fill && !__counter[__i].empty()) {
00220       _S_merge(__counter[__i], __carry, __comp);
00221       __carry.swap(__counter[__i++]);
00222     }
00223     __carry.swap(__counter[__i]);
00224     if (__i == __fill) {
00225       ++__fill;
00226       if (__fill >= NB) {
00227         //Looks like the list has too many elements to be sorted with this algorithm:
00228         __stl_throw_overflow_error("list::sort");
00229       }
00230     }
00231   }
00232 
00233   for (int __i = 1; __i < __fill; ++__i)
00234     _S_merge(__counter[__i], __counter[__i - 1], __comp);
00235   __that.swap(__counter[__fill - 1]);
00236 }
00237 
00238 #if defined (list)
00239 #  undef list
00240 #endif
00241 
00242 _STLP_MOVE_TO_STD_NAMESPACE
00243 
00244 _STLP_END_NAMESPACE
00245 
00246 #endif /*  _STLP_LIST_C */
00247 
00248 // Local Variables:
00249 // mode:C++
00250 // End:

Generated on Fri May 25 2012 04:27:45 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.