1/* 2 * Copyright (c) 2003 3 * Francois Dumont 4 * 5 * This material is provided "as is", with absolutely no warranty expressed 6 * or implied. Any use is at your own risk. 7 * 8 * Permission to use or copy this software for any purpose is hereby granted 9 * without fee, provided the above notices are retained on all copies. 10 * Permission to modify the code and to distribute modified code is granted, 11 * provided the above notices are retained, and a notice that the code was 12 * modified is included with the above copyright notice. 13 * 14 */ 15 16/* NOTE: This is an internal header file, included by other STL headers. 17 * You should not attempt to use it directly. 18 */ 19 20#ifndef _STLP_PTR_SPECIALIZED_LIST_H 21#define _STLP_PTR_SPECIALIZED_LIST_H 22 23#ifndef _STLP_POINTERS_SPEC_TOOLS_H 24# include <stl/pointers/_tools.h> 25#endif 26 27_STLP_BEGIN_NAMESPACE 28 29#define LIST_IMPL _STLP_PTR_IMPL_NAME(list) 30#if defined (__BORLANDC__) || defined (__DMC__) 31# define typename 32#endif 33 34#if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 35 36_STLP_MOVE_TO_PRIV_NAMESPACE 37 38_STLP_EXPORT_TEMPLATE_CLASS _List_node<void*>; 39 40_STLP_MOVE_TO_STD_NAMESPACE 41 42_STLP_EXPORT_TEMPLATE_CLASS allocator<_STLP_PRIV _List_node<void*> >; 43 44_STLP_MOVE_TO_PRIV_NAMESPACE 45 46_STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<_List_node_base, _List_node<void*>, allocator<_List_node<void*> > >; 47_STLP_EXPORT_TEMPLATE_CLASS _List_base<void*, allocator<void*> >; 48_STLP_EXPORT_TEMPLATE_CLASS LIST_IMPL<void*, allocator<void*> >; 49 50_STLP_MOVE_TO_STD_NAMESPACE 51#endif 52 53#if defined (_STLP_DEBUG) 54# define list _STLP_NON_DBG_NAME(list) 55_STLP_MOVE_TO_PRIV_NAMESPACE 56#endif 57 58template <class _Tp, _STLP_DFL_TMPL_PARAM(_Alloc, allocator<_Tp>) > 59class list 60#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (list) 61 : public __stlport_class<list<_Tp, _Alloc> > 62#endif 63{ 64 typedef _STLP_TYPENAME _STLP_PRIV _StorageType<_Tp>::_Type _StorageType; 65 typedef typename _Alloc_traits<_StorageType, _Alloc>::allocator_type _StorageTypeAlloc; 66 typedef _STLP_PRIV LIST_IMPL<_StorageType, _StorageTypeAlloc> _Base; 67 typedef typename _Base::iterator _BaseIte; 68 typedef typename _Base::const_iterator _BaseConstIte; 69 typedef _STLP_PRIV _CastTraits<_StorageType, _Tp> cast_traits; 70 typedef list<_Tp, _Alloc> _Self; 71 72public: 73 typedef _Tp value_type; 74 typedef value_type* pointer; 75 typedef const value_type* const_pointer; 76 typedef value_type& reference; 77 typedef const value_type& const_reference; 78 typedef size_t size_type; 79 typedef ptrdiff_t difference_type; 80 _STLP_FORCE_ALLOCATORS(value_type, _Alloc) 81 typedef typename _Alloc_traits<value_type, _Alloc>::allocator_type allocator_type; 82 typedef bidirectional_iterator_tag _Iterator_category; 83 84 typedef _STLP_PRIV _List_iterator<value_type, _Nonconst_traits<value_type> > iterator; 85 typedef _STLP_PRIV _List_iterator<value_type, _Const_traits<value_type> > const_iterator; 86 87 _STLP_DECLARE_BIDIRECTIONAL_REVERSE_ITERATORS; 88 89 allocator_type get_allocator() const 90 { return _STLP_CONVERT_ALLOCATOR(_M_impl.get_allocator(), value_type); } 91 92 explicit list(const allocator_type& __a = allocator_type()) 93 : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {} 94 95#if !defined(_STLP_DONT_SUP_DFLT_PARAM) 96 explicit list(size_type __n, const value_type& __val = _STLP_DEFAULT_CONSTRUCTED(value_type), 97#else 98 list(size_type __n, const value_type& __val, 99#endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 100 const allocator_type& __a = allocator_type()) 101 : _M_impl(__n, cast_traits::to_storage_type_cref(__val), 102 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {} 103 104#if defined(_STLP_DONT_SUP_DFLT_PARAM) 105 explicit list(size_type __n) 106 : _M_impl(__n) {} 107#endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 108 109#if defined (_STLP_MEMBER_TEMPLATES) 110 template <class _InputIterator> 111 list(_InputIterator __first, _InputIterator __last, 112 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL) 113# if !defined (_STLP_USE_ITERATOR_WRAPPER) 114 : _M_impl(__first, __last, _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {} 115# else 116 : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) { 117 insert(begin(), __first, __last); 118 } 119# endif 120 121# if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS) 122 template <class _InputIterator> 123 list(_InputIterator __first, _InputIterator __last) 124# if !defined (_STLP_USE_WRAPPER_ITERATOR) 125 : _M_impl(__first, __last) {} 126# else 127 { insert(begin(), __first, __last); } 128# endif 129# endif 130 131#else /* _STLP_MEMBER_TEMPLATES */ 132 133 list(const value_type *__first, const value_type *__last, 134 const allocator_type& __a = allocator_type()) 135 : _M_impl(cast_traits::to_storage_type_cptr(__first), 136 cast_traits::to_storage_type_cptr(__last), 137 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {} 138 list(const_iterator __first, const_iterator __last, 139 const allocator_type& __a = allocator_type()) 140 : _M_impl(_BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node), 141 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {} 142 143#endif /* _STLP_MEMBER_TEMPLATES */ 144 145 list(const _Self& __x) : _M_impl(__x._M_impl) {} 146 147#if !defined (_STLP_NO_MOVE_SEMANTIC) 148 list(__move_source<_Self> src) 149 : _M_impl(__move_source<_Base>(src.get()._M_impl)) {} 150#endif 151 152 iterator begin() { return iterator(_M_impl.begin()._M_node); } 153 const_iterator begin() const { return const_iterator(_M_impl.begin()._M_node); } 154 155 iterator end() { return iterator(_M_impl.end()._M_node); } 156 const_iterator end() const { return const_iterator(_M_impl.end()._M_node); } 157 158 reverse_iterator rbegin() { return reverse_iterator(end()); } 159 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } 160 161 reverse_iterator rend() { return reverse_iterator(begin()); } 162 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } 163 164 bool empty() const { return _M_impl.empty(); } 165 size_type size() const { return _M_impl.size(); } 166 size_type max_size() const { return _M_impl.max_size(); } 167 168 reference front() { return *begin(); } 169 const_reference front() const { return *begin(); } 170 reference back() { return *(--end()); } 171 const_reference back() const { return *(--end()); } 172 173 void swap(_Self &__x) { _M_impl.swap(__x._M_impl); } 174#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) 175 void _M_swap_workaround(_Self& __x) { swap(__x); } 176#endif 177 void clear() { _M_impl.clear(); } 178 179#if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS) 180 iterator insert(iterator __pos, const_reference __x = _STLP_DEFAULT_CONSTRUCTED(value_type)) 181#else 182 iterator insert(iterator __pos, const_reference __x) 183#endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/ 184 { return iterator(_M_impl.insert(_BaseIte(__pos._M_node), 185 cast_traits::to_storage_type_cref(__x))._M_node); } 186 187#if defined (_STLP_MEMBER_TEMPLATES) 188# if defined (_STLP_USE_ITERATOR_WRAPPER) 189private: 190 template <class _Integer> 191 void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val, 192 const __true_type&) 193 { _M_impl.insert(_BaseIte(__pos._M_node), __n, __val); } 194 195 template <class _InputIterator> 196 void _M_insert_dispatch(iterator __pos, 197 _InputIterator __first, _InputIterator __last, 198 const __false_type&) { 199 _M_impl.insert(_BaseIte(__pos._M_node), 200 _STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first), 201 _STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last)); 202 } 203 204public: 205# endif 206 207 template <class _InputIterator> 208 void insert(iterator __pos, _InputIterator __first, _InputIterator __last) { 209# if defined (_STLP_USE_ITERATOR_WRAPPER) 210 // Check whether it's an integral type. If so, it's not an iterator. 211 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 212 _M_insert_dispatch(__pos, __first, __last, _Integral()); 213# else 214 _M_impl.insert(_BaseIte(__pos._M_node), __first, __last); 215# endif 216 } 217#else /* _STLP_MEMBER_TEMPLATES */ 218 void insert(iterator __pos, const value_type *__first, const value_type *__last) 219 { _M_impl.insert(_BaseIte(__pos._M_node), cast_traits::to_storage_type_cptr(__first), 220 cast_traits::to_storage_type_cptr(__last)); } 221 void insert(iterator __pos, const_iterator __first, const_iterator __last) 222 { _M_impl.insert(_BaseIte(__pos._M_node), _BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node)); } 223#endif /* _STLP_MEMBER_TEMPLATES */ 224 225 void insert(iterator __pos, size_type __n, const value_type& __x) 226 { _M_impl.insert(_BaseIte(__pos._M_node), __n, cast_traits::to_storage_type_cref(__x)); } 227 228 void push_front(const value_type& __x) { _M_impl.push_front(cast_traits::to_storage_type_cref(__x)); } 229 void push_back(const value_type& __x) { _M_impl.push_back(cast_traits::to_storage_type_cref(__x)); } 230 231#if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS) 232 iterator insert(iterator __pos) { return iterator(_M_impl.insert(__pos._M_node)._M_node); } 233 void push_front() { _M_impl.push_front();} 234 void push_back() { _M_impl.push_back();} 235# endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/ 236 237 iterator erase(iterator __pos) 238 { return iterator(_M_impl.erase(_BaseIte(__pos._M_node))._M_node); } 239 iterator erase(iterator __first, iterator __last) 240 { return iterator(_M_impl.erase(_BaseIte(__first._M_node), _BaseIte(__last._M_node))._M_node); } 241 242#if !defined(_STLP_DONT_SUP_DFLT_PARAM) 243 void resize(size_type __new_size, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type)) 244#else 245 void resize(size_type __new_size) { _M_impl.resize(__new_size); } 246 void resize(size_type __new_size, const value_type& __x) 247#endif /*!_STLP_DONT_SUP_DFLT_PARAM*/ 248 {_M_impl.resize(__new_size, cast_traits::to_storage_type_cref(__x));} 249 250 void pop_front() { _M_impl.pop_front(); } 251 void pop_back() { _M_impl.pop_back(); } 252 253 _Self& operator=(const _Self& __x) 254 { _M_impl = __x._M_impl; return *this; } 255 void assign(size_type __n, const value_type& __val) 256 { _M_impl.assign(__n, cast_traits::to_storage_type_cref(__val)); } 257 258#if defined (_STLP_MEMBER_TEMPLATES) 259# if defined (_STLP_USE_ITERATOR_WRAPPER) 260private: 261 template <class _Integer> 262 void _M_assign_dispatch(_Integer __n, _Integer __val, const __true_type&) 263 { _M_impl.assign(__n, __val); } 264 265 template <class _InputIterator> 266 void _M_assign_dispatch(_InputIterator __first, _InputIterator __last, 267 const __false_type&) { 268 _M_impl.assign(_STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first), 269 _STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last)); 270 } 271 272public: 273# endif 274 275 template <class _InputIterator> 276 void assign(_InputIterator __first, _InputIterator __last) { 277# if defined (_STLP_USE_ITERATOR_WRAPPER) 278 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 279 _M_assign_dispatch(__first, __last, _Integral()); 280# else 281 _M_impl.assign(__first, __last); 282# endif 283 } 284#else 285 void assign(const value_type *__first, const value_type *__last) { 286 _M_impl.assign(cast_traits::to_storage_type_cptr(__first), 287 cast_traits::to_storage_type_cptr(__last)); 288 } 289 void assign(const_iterator __first, const_iterator __last) 290 { _M_impl.assign(_BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node)); } 291#endif 292 293 void splice(iterator __pos, _Self& __x) 294 { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl); } 295 void splice(iterator __pos, _Self& __x, iterator __i) 296 { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl, _BaseIte(__i._M_node)); } 297 void splice(iterator __pos, _Self& __x, iterator __first, iterator __last) 298 { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl, 299 _BaseIte(__first._M_node), _BaseIte(__last._M_node)); } 300 301 void remove(const_reference __val) 302 { _M_impl.remove(cast_traits::to_storage_type_cref(__val)); } 303 void unique() { _M_impl.unique(); } 304 void merge(_Self& __x) { _M_impl.merge(__x._M_impl); } 305 void reverse() { _M_impl.reverse(); } 306 void sort() { _M_impl.sort(); } 307 308#if defined (_STLP_MEMBER_TEMPLATES) 309 template <class _Predicate> 310 void remove_if(_Predicate __pred) 311 { _M_impl.remove_if(_STLP_PRIV _UnaryPredWrapper<_StorageType, _Tp, _Predicate>(__pred)); } 312 template <class _BinaryPredicate> 313 void unique(_BinaryPredicate __bin_pred) 314 { _M_impl.unique(_STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _BinaryPredicate>(__bin_pred)); } 315 316 template <class _StrictWeakOrdering> 317 void merge(_Self &__x, _StrictWeakOrdering __comp) 318 { _M_impl.merge(__x._M_impl, _STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _StrictWeakOrdering>(__comp)); } 319 320 template <class _StrictWeakOrdering> 321 void sort(_StrictWeakOrdering __comp) 322 { _M_impl.sort(_STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _StrictWeakOrdering>(__comp)); } 323#endif /* _STLP_MEMBER_TEMPLATES */ 324 325private: 326 _Base _M_impl; 327}; 328 329#if defined (list) 330# undef list 331_STLP_MOVE_TO_STD_NAMESPACE 332#endif 333 334#undef LIST_IMPL 335#if defined (__BORLANDC__) || defined (__DMC__) 336# undef typename 337#endif 338 339_STLP_END_NAMESPACE 340 341#endif /* _STLP_PTR_SPECIALIZED_LIST_H */ 342 343// Local Variables: 344// mode:C++ 345// End: 346