/home/ntakagi/work/STLport-5.1.5/stlport/stl/pointers/_slist.hGo to the documentation of this file.00001 /* 00002 * Copyright (c) 2003 00003 * Francois Dumont 00004 * 00005 * This material is provided "as is", with absolutely no warranty expressed 00006 * or implied. Any use is at your own risk. 00007 * 00008 * Permission to use or copy this software for any purpose is hereby granted 00009 * without fee, provided the above notices are retained on all copies. 00010 * Permission to modify the code and to distribute modified code is granted, 00011 * provided the above notices are retained, and a notice that the code was 00012 * modified is included with the above copyright notice. 00013 * 00014 */ 00015 00016 /* NOTE: This is an internal header file, included by other STL headers. 00017 * You should not attempt to use it directly. 00018 */ 00019 00020 #ifndef _STLP_SPECIALIZED_SLIST_H 00021 #define _STLP_SPECIALIZED_SLIST_H 00022 00023 #ifndef _STLP_POINTERS_SPEC_TOOLS_H 00024 # include <stl/pointers/_tools.h> 00025 #endif 00026 00027 _STLP_BEGIN_NAMESPACE 00028 00029 #define SLIST_IMPL _STLP_PTR_IMPL_NAME(slist) 00030 00031 #if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00032 _STLP_MOVE_TO_PRIV_NAMESPACE 00033 00034 _STLP_EXPORT_TEMPLATE_CLASS _Slist_node<void*>; 00035 typedef _Slist_node<void*> _VoidPtrSNode; 00036 _STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<_Slist_node_base, _VoidPtrSNode, allocator<_VoidPtrSNode> >; 00037 _STLP_EXPORT_TEMPLATE_CLASS _Slist_base<void*, allocator<void*> >; 00038 _STLP_EXPORT_TEMPLATE_CLASS SLIST_IMPL<void*, allocator<void*> >; 00039 00040 _STLP_MOVE_TO_STD_NAMESPACE 00041 #endif 00042 00043 #if defined (_STLP_DEBUG) 00044 # define slist _STLP_NON_DBG_NAME(slist) 00045 _STLP_MOVE_TO_PRIV_NAMESPACE 00046 #endif 00047 00048 template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) > 00049 class slist 00050 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (slist) 00051 : public __stlport_class<slist<_Tp, _Alloc> > 00052 #endif 00053 { 00054 typedef typename _STLP_PRIV _StorageType<_Tp>::_Type _StorageType; 00055 typedef typename _Alloc_traits<_StorageType, _Alloc>::allocator_type _StorageTypeAlloc; 00056 typedef _STLP_PRIV SLIST_IMPL<_StorageType, _StorageTypeAlloc> _Base; 00057 typedef typename _Base::iterator _BaseIte; 00058 typedef typename _Base::const_iterator _BaseConstIte; 00059 typedef slist<_Tp, _Alloc> _Self; 00060 typedef _STLP_PRIV _CastTraits<_StorageType, _Tp> cast_traits; 00061 typedef _STLP_PRIV _Slist_node_base _Node_base; 00062 00063 public: 00064 typedef _Tp value_type; 00065 typedef value_type* pointer; 00066 typedef const value_type* const_pointer; 00067 typedef value_type& reference; 00068 typedef const value_type& const_reference; 00069 typedef size_t size_type; 00070 typedef ptrdiff_t difference_type; 00071 typedef forward_iterator_tag _Iterator_category; 00072 00073 typedef _STLP_PRIV _Slist_iterator<value_type, _Nonconst_traits<value_type> > iterator; 00074 typedef _STLP_PRIV _Slist_iterator<value_type, _Const_traits<value_type> > const_iterator; 00075 00076 _STLP_FORCE_ALLOCATORS(value_type, _Alloc) 00077 typedef typename _Alloc_traits<value_type, _Alloc>::allocator_type allocator_type; 00078 00079 public: 00080 allocator_type get_allocator() const 00081 { return _STLP_CONVERT_ALLOCATOR(_M_impl.get_allocator(), value_type); } 00082 00083 explicit slist(const allocator_type& __a = allocator_type()) 00084 : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {} 00085 00086 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) 00087 explicit slist(size_type __n, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type), 00088 #else 00089 slist(size_type __n, const value_type& __x, 00090 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 00091 const allocator_type& __a = allocator_type()) 00092 : _M_impl(__n, cast_traits::to_storage_type_cref(__x), _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {} 00093 00094 #if defined(_STLP_DONT_SUP_DFLT_PARAM) 00095 explicit slist(size_type __n) : _M_impl(__n) {} 00096 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 00097 00098 #if defined (_STLP_MEMBER_TEMPLATES) 00099 // We don't need any dispatching tricks here, because _M_insert_after_range 00100 // already does them. 00101 template <class _InputIterator> 00102 slist(_InputIterator __first, _InputIterator __last, 00103 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL) 00104 # if !defined (_STLP_USE_ITERATOR_WRAPPER) 00105 : _M_impl(__first, __last, _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {} 00106 # else 00107 : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) { 00108 insert_after(before_begin(), __first, __last); 00109 } 00110 # endif 00111 # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS) 00112 // VC++ needs this crazyness 00113 template <class _InputIterator> 00114 slist(_InputIterator __first, _InputIterator __last) 00115 # if !defined (_STLP_USE_WRAPPER_ITERATOR) 00116 : _M_impl(__first, __last) {} 00117 # else 00118 { insert_after(before_begin(), __first, __last); } 00119 # endif 00120 # endif 00121 #else /* _STLP_MEMBER_TEMPLATES */ 00122 slist(const_iterator __first, const_iterator __last, 00123 const allocator_type& __a = allocator_type() ) 00124 : _M_impl(_BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node), 00125 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {} 00126 slist(const value_type* __first, const value_type* __last, 00127 const allocator_type& __a = allocator_type()) 00128 : _M_impl(cast_traits::to_storage_type_cptr(__first), cast_traits::to_storage_type_cptr(__last), 00129 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {} 00130 #endif /* _STLP_MEMBER_TEMPLATES */ 00131 00132 slist(const _Self& __x) : _M_impl(__x._M_impl) {} 00133 slist(__move_source<_Self> src) 00134 : _M_impl(__move_source<_Base>(src.get()._M_impl)) {} 00135 00136 _Self& operator= (const _Self& __x) { _M_impl = __x._M_impl; return *this; } 00137 00138 void assign(size_type __n, const value_type& __val) 00139 { _M_impl.assign(__n, cast_traits::to_storage_type_cref(__val)); } 00140 00141 #if defined (_STLP_MEMBER_TEMPLATES) 00142 # if defined (_STLP_USE_ITERATOR_WRAPPER) 00143 private: 00144 template <class _Integer> 00145 void _M_assign_dispatch(_Integer __n, _Integer __val, 00146 const __true_type&) 00147 { _M_impl.assign(__n, __val); } 00148 00149 template <class _InputIterator> 00150 void _M_assign_dispatch(_InputIterator __first, _InputIterator __last, 00151 const __false_type&) { 00152 _M_impl.assign(typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first), 00153 typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last)); 00154 } 00155 00156 public: 00157 # endif 00158 00159 template <class _InputIterator> 00160 void assign(_InputIterator __first, _InputIterator __last) { 00161 # if defined (_STLP_USE_ITERATOR_WRAPPER) 00162 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 00163 _M_assign_dispatch(__first, __last, _Integral()); 00164 # else 00165 _M_impl.assign(__first, __last); 00166 # endif 00167 } 00168 #else 00169 void assign(const value_type *__first, const value_type *__last) { 00170 _M_impl.assign(cast_traits::to_storage_type_cptr(__first), 00171 cast_traits::to_storage_type_cptr(__last)); 00172 } 00173 void assign(const_iterator __first, const_iterator __last) { 00174 _M_impl.assign(_BaseConstIte(__first._M_node), 00175 _BaseConstIte(__last._M_node)); 00176 } 00177 #endif /* _STLP_MEMBER_TEMPLATES */ 00178 00179 iterator before_begin() { return iterator(_M_impl.before_begin()._M_node); } 00180 const_iterator before_begin() const { return const_iterator(const_cast<_Node_base*>(_M_impl.before_begin()._M_node)); } 00181 00182 iterator begin() { return iterator(_M_impl.begin()._M_node); } 00183 const_iterator begin() const { return const_iterator(const_cast<_Node_base*>(_M_impl.begin()._M_node));} 00184 00185 iterator end() { return iterator(_M_impl.end()._M_node); } 00186 const_iterator end() const { return iterator(_M_impl.end()._M_node); } 00187 00188 size_type size() const { return _M_impl.size(); } 00189 size_type max_size() const { return _M_impl.max_size(); } 00190 bool empty() const { return _M_impl.empty(); } 00191 00192 void swap(_Self& __x) { _M_impl.swap(__x._M_impl); } 00193 00194 public: 00195 reference front() { return *begin(); } 00196 const_reference front() const { return *begin(); } 00197 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS) 00198 void push_front(const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type)) 00199 #else 00200 void push_front(const value_type& __x) 00201 #endif 00202 { _M_impl.push_front(cast_traits::to_storage_type_cref(__x)); } 00203 00204 # if defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS) 00205 void push_front() { _M_impl.push_front();} 00206 # endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/ 00207 00208 void pop_front() { _M_impl.pop_front(); } 00209 00210 iterator previous(const_iterator __pos) 00211 { return iterator(_M_impl.previous(_BaseConstIte(__pos._M_node))._M_node); } 00212 const_iterator previous(const_iterator __pos) const 00213 { return const_iterator(const_cast<_Node_base*>(_M_impl.previous(_BaseConstIte(__pos._M_node))._M_node)); } 00214 00215 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) 00216 iterator insert_after(iterator __pos, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type)) 00217 #else 00218 iterator insert_after(iterator __pos, const value_type& __x) 00219 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 00220 { return iterator(_M_impl.insert_after(_BaseIte(__pos._M_node), 00221 cast_traits::to_storage_type_cref(__x))._M_node); } 00222 00223 #if defined(_STLP_DONT_SUP_DFLT_PARAM) 00224 iterator insert_after(iterator __pos) 00225 { return iterator(_M_impl.insert_after(_BaseIte(__pos._M_node))._M_node);} 00226 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 00227 00228 void insert_after(iterator __pos, size_type __n, const value_type& __x) 00229 { _M_impl.insert_after(_BaseIte(__pos._M_node), __n, cast_traits::to_storage_type_cref(__x)); } 00230 00231 #if defined (_STLP_MEMBER_TEMPLATES) 00232 # if defined (_STLP_USE_ITERATOR_WRAPPER) 00233 private: 00234 template <class _Integer> 00235 void _M_insert_after_dispatch(iterator __pos, _Integer __n, _Integer __val, 00236 const __true_type&) { 00237 _M_impl.insert_after(_BaseIte(__pos._M_node), __n, __val); 00238 } 00239 00240 template <class _InputIterator> 00241 void _M_insert_after_dispatch(iterator __pos, 00242 _InputIterator __first, _InputIterator __last, 00243 const __false_type&) { 00244 _M_impl.insert_after(_BaseIte(__pos._M_node), 00245 typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first), 00246 typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last)); 00247 } 00248 00249 public: 00250 # endif 00251 00252 template <class _InputIterator> 00253 void insert_after(iterator __pos, _InputIterator __first, _InputIterator __last) { 00254 # if defined (_STLP_USE_ITERATOR_WRAPPER) 00255 // Check whether it's an integral type. If so, it's not an iterator. 00256 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 00257 _M_insert_after_dispatch(__pos, __first, __last, _Integral()); 00258 # else 00259 _M_impl.insert_after(_BaseIte(__pos._M_node), __first, __last); 00260 # endif 00261 } 00262 00263 #else /* _STLP_MEMBER_TEMPLATES */ 00264 void insert_after(iterator __pos, 00265 const_iterator __first, const_iterator __last) 00266 { _M_impl.insert_after(_BaseIte(__pos._M_node), 00267 _BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node)); } 00268 void insert_after(iterator __pos, 00269 const value_type* __first, const value_type* __last) { 00270 _M_impl.insert_after(_BaseIte(__pos._M_node), 00271 cast_traits::to_storage_type_cptr(__first), 00272 cast_traits::to_storage_type_cptr(__last)); 00273 } 00274 #endif /* _STLP_MEMBER_TEMPLATES */ 00275 00276 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) 00277 iterator insert(iterator __pos, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type)) 00278 #else 00279 iterator insert(iterator __pos, const value_type& __x) 00280 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 00281 { return iterator(_M_impl.insert(_BaseIte(__pos._M_node), 00282 cast_traits::to_storage_type_cref(__x))._M_node); } 00283 00284 #if defined(_STLP_DONT_SUP_DFLT_PARAM) 00285 iterator insert(iterator __pos) 00286 { return iterator(_M_impl.insert(_BaseIte(__pos._M_node))._M_node); } 00287 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 00288 00289 void insert(iterator __pos, size_type __n, const value_type& __x) 00290 { _M_impl.insert(_BaseIte(__pos._M_node), __n, cast_traits::to_storage_type_cref(__x)); } 00291 00292 #if defined (_STLP_MEMBER_TEMPLATES) 00293 # if defined (_STLP_USE_ITERATOR_WRAPPER) 00294 private: 00295 template <class _Integer> 00296 void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val, 00297 const __true_type&) { 00298 _M_impl.insert(_BaseIte(__pos._M_node), __n, __val); 00299 } 00300 00301 template <class _InputIterator> 00302 void _M_insert_dispatch(iterator __pos, 00303 _InputIterator __first, _InputIterator __last, 00304 const __false_type&) { 00305 _M_impl.insert(_BaseIte(__pos._M_node), typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first), 00306 typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last)); 00307 } 00308 00309 public: 00310 # endif 00311 00312 template <class _InputIterator> 00313 void insert(iterator __pos, _InputIterator __first, _InputIterator __last) { 00314 # if defined (_STLP_USE_ITERATOR_WRAPPER) 00315 // Check whether it's an integral type. If so, it's not an iterator. 00316 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 00317 _M_insert_dispatch(__pos, __first, __last, _Integral()); 00318 # else 00319 _M_impl.insert(_BaseIte(__pos._M_node), __first, __last); 00320 # endif 00321 } 00322 00323 #else /* _STLP_MEMBER_TEMPLATES */ 00324 void insert(iterator __pos, const_iterator __first, const_iterator __last) 00325 { _M_impl.insert(_BaseIte(__pos._M_node), _BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node)); } 00326 void insert(iterator __pos, const value_type* __first, const value_type* __last) 00327 { _M_impl.insert(_BaseIte(__pos._M_node), cast_traits::to_storage_type_cptr(__first), 00328 cast_traits::to_storage_type_cptr(__last)); } 00329 #endif /* _STLP_MEMBER_TEMPLATES */ 00330 00331 iterator erase_after(iterator __pos) 00332 { return iterator(_M_impl.erase_after(_BaseIte(__pos._M_node))._M_node); } 00333 iterator erase_after(iterator __before_first, iterator __last) 00334 { return iterator(_M_impl.erase_after(_BaseIte(__before_first._M_node), 00335 _BaseIte(__last._M_node))._M_node); } 00336 00337 iterator erase(iterator __pos) 00338 { return iterator(_M_impl.erase(_BaseIte(__pos._M_node))._M_node); } 00339 iterator erase(iterator __first, iterator __last) 00340 { return iterator(_M_impl.erase(_BaseIte(__first._M_node), _BaseIte(__last._M_node))._M_node); } 00341 00342 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) 00343 void resize(size_type __new_size, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type)) 00344 #else 00345 void resize(size_type __new_size, const value_type& __x) 00346 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 00347 { _M_impl.resize(__new_size, cast_traits::to_storage_type_cref(__x));} 00348 00349 #if defined(_STLP_DONT_SUP_DFLT_PARAM) 00350 void resize(size_type __new_size) { _M_impl.resize(__new_size); } 00351 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 00352 00353 void clear() { _M_impl.clear(); } 00354 00355 void splice_after(iterator __pos, _Self& __x, 00356 iterator __before_first, iterator __before_last) 00357 { _M_impl.splice_after(_BaseIte(__pos._M_node), __x._M_impl, 00358 _BaseIte(__before_first._M_node), _BaseIte(__before_last._M_node)); } 00359 void splice_after(iterator __pos, _Self& __x, iterator __prev) 00360 { _M_impl.splice_after(_BaseIte(__pos._M_node), __x._M_impl, _BaseIte(__prev._M_node)); } 00361 void splice_after(iterator __pos, _Self& __x) 00362 { _M_impl.splice_after(_BaseIte(__pos._M_node), __x._M_impl); } 00363 void splice(iterator __pos, _Self& __x) 00364 { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl); } 00365 void splice(iterator __pos, _Self& __x, iterator __i) 00366 { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl, _BaseIte(__i._M_node)); } 00367 void splice(iterator __pos, _Self& __x, iterator __first, iterator __last) 00368 { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl, 00369 _BaseIte(__first._M_node), _BaseIte(__last._M_node)); } 00370 00371 void reverse() { _M_impl.reverse(); } 00372 00373 void remove(const value_type& __val) { _M_impl.remove(cast_traits::to_storage_type_cref(__val)); } 00374 void unique() { _M_impl.unique(); } 00375 void merge(_Self& __x) { _M_impl.merge(__x._M_impl); } 00376 void sort() {_M_impl.sort(); } 00377 00378 #ifdef _STLP_MEMBER_TEMPLATES 00379 template <class _Predicate> 00380 void remove_if(_Predicate __pred) 00381 { _M_impl.remove_if(_STLP_PRIV _UnaryPredWrapper<_StorageType, _Tp, _Predicate>(__pred)); } 00382 00383 template <class _BinaryPredicate> 00384 void unique(_BinaryPredicate __pred) 00385 { _M_impl.unique(_STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _BinaryPredicate>(__pred)); } 00386 00387 template <class _StrictWeakOrdering> 00388 void merge(_Self& __x, _StrictWeakOrdering __comp) 00389 { _M_impl.merge(__x._M_impl, _STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _StrictWeakOrdering>(__comp)); } 00390 00391 template <class _StrictWeakOrdering> 00392 void sort(_StrictWeakOrdering __comp) 00393 { _M_impl.sort(_STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _StrictWeakOrdering>(__comp)); } 00394 #endif /* _STLP_MEMBER_TEMPLATES */ 00395 00396 private: 00397 _Base _M_impl; 00398 }; 00399 00400 #if defined (slist) 00401 # undef slist 00402 _STLP_MOVE_TO_STD_NAMESPACE 00403 #endif 00404 00405 #undef SLIST_IMPL 00406 00407 _STLP_END_NAMESPACE 00408 00409 #endif /* _STLP_SPECIALIZED_SLIST_H */ 00410 00411 // Local Variables: 00412 // mode:C++ 00413 // End:
Generated on Mon Mar 10 15:32:36 2008 by ![]() |