_slist.h

00001 /*
00002  *
00003  * Copyright (c) 1996,1997
00004  * Silicon Graphics Computer Systems, Inc.
00005  *
00006  * Copyright (c) 1997
00007  * Moscow Center for SPARC Technology
00008  *
00009  * Copyright (c) 1999 
00010  * Boris Fomitchev
00011  *
00012  * This material is provided "as is", with absolutely no warranty expressed
00013  * or implied. Any use is at your own risk.
00014  *
00015  * Permission to use or copy this software for any purpose is hereby granted 
00016  * without fee, provided the above notices are retained on all copies.
00017  * Permission to modify the code and to distribute modified code is granted,
00018  * provided the above notices are retained, and a notice that the code was
00019  * modified is included with the above copyright notice.
00020  *
00021  */
00022 
00023 /* NOTE: This is an internal header file, included by other STL headers.
00024  *   You should not attempt to use it directly.
00025  */
00026 
00027 #ifndef _STLP_INTERNAL_DBG_SLIST_H
00028 #define _STLP_INTERNAL_DBG_SLIST_H
00029 
00030 #include <stl/debug/_iterator.h>
00031 
00032 # ifndef _STLP_USE_WRAPPER_FOR_ALLOC_PARAM
00033 #  undef  _DBG_slist
00034 #  define _DBG_slist slist
00035 # endif
00036 
00037 #  define _STLP_DBG_SLIST_BASE __WORKAROUND_DBG_RENAME(slist) <_Tp, _Alloc>
00038 
00039 _STLP_BEGIN_NAMESPACE
00040 
00041 # ifdef _STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS
00042 template <class _Tp, class _Alloc>
00043 inline _Tp*
00044 value_type(const _DBG_iter_base< _STLP_DBG_SLIST_BASE >&) {
00045   return (_Tp*)0;
00046 }
00047 
00048 template <class _Tp, class _Alloc>
00049 inline forward_iterator_tag
00050 iterator_category(const _DBG_iter_base< _STLP_DBG_SLIST_BASE >&) {
00051   return forward_iterator_tag();
00052 }
00053 # endif
00054 
00055 template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) >
00056 class _DBG_slist : public _STLP_DBG_SLIST_BASE
00057 {
00058 private:
00059   typedef _STLP_DBG_SLIST_BASE _Base;
00060   typedef _DBG_slist<_Tp,_Alloc> _Self;
00061 
00062 public:
00063 
00064   __IMPORT_CONTAINER_TYPEDEFS(_Base)
00065 
00066   typedef _DBG_iter<_Base, _Nonconst_traits<value_type> >      iterator;
00067   typedef _DBG_iter<_Base, _Const_traits<value_type> >     const_iterator;
00068 
00069 protected:
00070   friend class __owned_link;
00071   mutable __owned_list _M_iter_list;
00072   void _Invalidate_all() { _M_iter_list._Invalidate_all();}
00073   void _Invalidate_iterator(const iterator& __it) {__invalidate_iterator(&_M_iter_list, __it); }
00074 
00075 public:
00076   const _Base* _Get_base() const { return (const _Base*)this; }
00077   _Base* _Get_base() { return (_Base*)this; }
00078 
00079 public:
00080 
00081   explicit _DBG_slist(const allocator_type& __a = allocator_type()) :
00082     _STLP_DBG_SLIST_BASE(__a) , _M_iter_list(_Get_base()) {}
00083   
00084   _DBG_slist(size_type __n, const value_type& __x,
00085              const allocator_type& __a =  allocator_type()) :
00086     _STLP_DBG_SLIST_BASE(__n, __x, __a), _M_iter_list(_Get_base()) {}
00087   
00088   explicit _DBG_slist(size_type __n) : _STLP_DBG_SLIST_BASE(__n) , _M_iter_list(_Get_base()) {}
00089   
00090 #ifdef _STLP_MEMBER_TEMPLATES
00091   // We don't need any dispatching tricks here, because _M_insert_after_range
00092   // already does them.
00093 # ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
00094   template <class _InputIterator>
00095   _DBG_slist(_InputIterator __first, _InputIterator __last) :
00096     _STLP_DBG_SLIST_BASE(__first, __last, allocator_type()), _M_iter_list(_Get_base()) {} 
00097 # endif
00098   template <class _InputIterator>
00099   _DBG_slist(_InputIterator __first, _InputIterator __last,
00100              const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL) : 
00101     _STLP_DBG_SLIST_BASE(__first, __last, __a), _M_iter_list(_Get_base()) {} 
00102 
00103 #else /* _STLP_MEMBER_TEMPLATES */
00104 
00105   _DBG_slist(const_iterator __first, const_iterator __last,
00106              const allocator_type& __a = allocator_type() ) :
00107     _STLP_DBG_SLIST_BASE(__first._M_iterator, __last._M_iterator, __a),
00108     _M_iter_list(_Get_base()) {}
00109   
00110   _DBG_slist(const value_type* __first, const value_type* __last,
00111         const allocator_type& __a =  allocator_type()) : 
00112     _STLP_DBG_SLIST_BASE(__first, __last, __a), _M_iter_list(_Get_base())  {}
00113 
00114 #endif /* _STLP_MEMBER_TEMPLATES */
00115 
00116   _DBG_slist(const _Self& __x) : _STLP_DBG_SLIST_BASE(__x), _M_iter_list(_Get_base()) {}
00117   
00118   _Self& operator= (const _Self& __x) {
00119     _Invalidate_all();
00120     (_Base&)*this = (const _Base&)__x;
00121     return *this;
00122   }
00123   
00124   ~_DBG_slist() {}
00125 
00126 public:
00127   void assign(size_type __n, const _Tp& __val) {
00128     // fbp :check invalidation here !
00129     _Base::assign(__n, __val); 
00130   }
00131 
00132 public:
00133 
00134   iterator before_begin() { return iterator(&_M_iter_list, _Base::before_begin()); }
00135   const_iterator before_begin() const
00136     { return const_iterator(&_M_iter_list, _Base::before_begin()); }
00137 
00138   iterator begin() { return iterator(&_M_iter_list, _Base::begin()); }
00139   const_iterator begin() const 
00140     { return const_iterator(&_M_iter_list,_Base::begin());}
00141 
00142   iterator end() { return iterator(&_M_iter_list, _Base::end()); }
00143   const_iterator end() const { return const_iterator(&_M_iter_list, _Base::end()); }
00144 
00145   void swap(_Self& __x) { 
00146     _M_iter_list._Swap_owners(__x._M_iter_list);
00147     _Base::swap(__x); 
00148   }
00149 
00150 public:
00151   // fbp : checks here !
00152   reference front() { 
00153     _STLP_VERBOSE_ASSERT(!this->empty(), _StlMsg_EMPTY_CONTAINER)
00154     return _Base::front(); 
00155   }
00156   const_reference front() const { 
00157     _STLP_VERBOSE_ASSERT(!this->empty(), _StlMsg_EMPTY_CONTAINER)
00158     return _Base::front(); 
00159   }
00160   void pop_front() {
00161     _STLP_VERBOSE_ASSERT(!this->empty(), _StlMsg_EMPTY_CONTAINER)
00162     _Base::pop_front();
00163   }
00164   iterator previous(const_iterator __pos) {
00165     return iterator(&_M_iter_list,_Base::previous(__pos._M_iterator));
00166   }
00167   const_iterator previous(const_iterator __pos) const {
00168     return const_iterator(&_M_iter_list,_Base::previous(__pos._M_iterator));
00169   }
00170 
00171 public:
00172 
00173   iterator insert_after(iterator __pos, const value_type& __x) {
00174     return iterator(&_M_iter_list,_Base::insert_after(__pos._M_iterator, __x));
00175   }
00176 
00177   iterator insert_after(iterator __pos) {
00178     return iterator(&_M_iter_list,_Base::insert_after(__pos._M_iterator));
00179   }
00180 
00181   void insert_after(iterator __pos, size_type __n, const value_type& __x) {
00182     _Base::insert_after(__pos._M_iterator, __n, __x);
00183   }
00184 
00185 #ifdef _STLP_MEMBER_TEMPLATES
00186 
00187   template <class _InputIterator>
00188   void assign(_InputIterator __first, _InputIterator __last) {
00189     // fbp :check invalidation here !
00190     _Base::assign(__first, __last);
00191   }
00192 
00193   // We don't need any dispatching tricks here, because _M_insert_after_range
00194   // already does them.
00195   template <class _InIter>
00196   void insert_after(iterator __pos, _InIter __first, _InIter __last) {
00197     _Base::insert_after(__pos._M_iterator, __first, __last);
00198   }
00199 
00200   // We don't need any dispatching tricks here, because _M_insert_after_range
00201   // already does them.
00202   template <class _InIter>
00203   void insert(iterator __pos, _InIter __first, _InIter __last) {
00204     _Base::insert(__pos._M_iterator, __first, __last);
00205 
00206   }
00207 
00208 #else /* _STLP_MEMBER_TEMPLATES */
00209 
00210   void insert_after(iterator __pos,
00211                     const_iterator __first, const_iterator __last) {
00212     _Base::insert_after(__pos._M_iterator, __first._M_iterator, __last._M_iterator);
00213   }
00214   void insert_after(iterator __pos,
00215                     const value_type* __first, const value_type* __last) {
00216     _Base::insert_after(__pos._M_iterator, __first, __last);
00217   }
00218 
00219   void insert(iterator __pos, const_iterator __first, const_iterator __last) {
00220     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos))
00221     _Base::insert(__pos._M_iterator, __first._M_iterator, __last._M_iterator);
00222   }
00223   void insert(iterator __pos, const value_type* __first, 
00224                               const value_type* __last) {
00225     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos))
00226     _Base::insert(__pos._M_iterator, __first, __last);
00227   }
00228 
00229 #endif /* _STLP_MEMBER_TEMPLATES */
00230 
00231   iterator insert(iterator __pos, const value_type& __x) {
00232     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos))
00233     return iterator(&_M_iter_list, _Base::insert(__pos._M_iterator, __x));
00234   }
00235 
00236   iterator insert(iterator __pos) {
00237     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos))
00238     return iterator(&_M_iter_list, _Base::insert(__pos._M_iterator));
00239   }
00240 
00241   void insert(iterator __pos, size_type __n, const value_type& __x) {
00242     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos))
00243     _Base::insert(__pos._M_iterator, __n, __x);
00244   } 
00245     
00246 public:
00247   iterator erase_after(iterator __pos) {
00248     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos))
00249     return iterator(&_M_iter_list, _Base::erase_after(__pos._M_iterator));
00250   }
00251   iterator erase_after(iterator __before_first, iterator __last) {
00252     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__before_first))
00253     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__last))
00254     return iterator(&_M_iter_list, 
00255                     _Base::erase_after(__before_first._M_iterator, __last._M_iterator));
00256   } 
00257 
00258   iterator erase(iterator __pos) {
00259     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos))
00260     return iterator(&_M_iter_list, _Base::erase(__pos._M_iterator));
00261   }
00262   iterator erase(iterator __first, iterator __last) {
00263     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__first))
00264     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__last))
00265     return iterator(&_M_iter_list, 
00266                     _Base::erase(__first._M_iterator, __last._M_iterator));
00267   }
00268 
00269   void resize(size_type __new_size, const _Tp& __x) {
00270     _Base::resize(__new_size, __x);
00271   }
00272   void resize(size_type new_size) { resize(new_size, _Tp()); }
00273 
00274   void clear() {
00275     _Invalidate_all();      
00276     _Base::clear();
00277   }
00278 
00279 public:
00280   // Moves the range [__before_first + 1, __before_last + 1) to *this,
00281   //  inserting it immediately after __pos.  This is constant time.
00282   void splice_after(iterator __pos, 
00283                     iterator __before_first, iterator __before_last)
00284   {
00285     if (__before_first != __before_last) {
00286       _Base::splice_after(__pos._M_iterator, 
00287                           __before_first._M_iterator, __before_last._M_iterator);
00288       __before_first++;
00289       __before_last++;
00290       __invalidate_range(__before_first._Owner(), 
00291                          __before_first, __before_last);
00292     }
00293   }
00294 
00295   // Moves the element that follows __prev to *this, inserting it immediately
00296   //  after __pos.  This is constant time.
00297   void splice_after(iterator __pos, iterator __prev)
00298   {
00299     _Base::splice_after(__pos._M_iterator, __prev._M_iterator);
00300     __invalidate_iterator(__prev._Owner(), ++__prev);
00301   }
00302 
00303   // Removes all of the elements from the list __x to *this, inserting
00304   // them immediately after __pos.  __x must not be *this.  Complexity:
00305   // linear in __x.size().
00306   void splice_after(iterator __pos, _Self& __x)
00307   {
00308     _Base::splice_after(__pos._M_iterator, (_Base&)__x);
00309     __x._Invalidate_all();
00310   }
00311 
00312   // Linear in distance(begin(), __pos), and linear in __x.size().
00313   void splice(iterator __pos, _Self& __x) {
00314     _STLP_VERBOSE_ASSERT(!(&__x==this), _StlMsg_INVALID_ARGUMENT)
00315     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos))
00316     _Base::splice(__pos._M_iterator, (_Base&)__x);
00317     __x._Invalidate_all();
00318   }
00319 
00320   // Linear in distance(begin(), __pos), and in distance(__x.begin(), __i).
00321   void splice(iterator __pos, _Self& __x, iterator __i) {
00322     _STLP_VERBOSE_ASSERT(&__x!=this, _StlMsg_INVALID_ARGUMENT)
00323     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos) && 
00324                       __check_if_owner(&__x._M_iter_list ,__i))
00325     _Base::splice(__pos._M_iterator, (_Base&)__x, __i._M_iterator);
00326     __x._Invalidate_iterator(__i);
00327   }
00328 
00329   // Linear in distance(begin(), __pos), in distance(__x.begin(), __first),
00330   // and in distance(__first, __last).
00331   void splice(iterator __pos, _Self& __x, iterator __first, iterator __last)
00332   {
00333     _STLP_VERBOSE_ASSERT(&__x!=this, _StlMsg_INVALID_ARGUMENT)
00334     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__pos))
00335     if (__first != __last)
00336       _Base::splice(__pos._M_iterator, (_Base&)__x, __first._M_iterator, __last._M_iterator);      
00337     __invalidate_range(&__x._M_iter_list, __first, __last);
00338   }
00339 
00340 public:
00341 
00342   void remove(const _Tp& __val) {
00343     _Base::remove(__val);
00344     //    __x._Invalidate_all();    
00345   }
00346   void unique() {
00347     _Base::unique();
00348   }
00349   void merge(_Self& __x) {
00350     _Base::merge((_Base&)__x);
00351     __x._Invalidate_all();
00352   }
00353   void sort() {
00354     _Invalidate_all();
00355     _Base::sort();
00356   }
00357 
00358 #ifdef _STLP_MEMBER_TEMPLATES
00359 
00360   template <class _Predicate> 
00361   void remove_if(_Predicate __pred) {
00362     _Base::remove_if(__pred);
00363   }
00364 
00365   template <class _BinaryPredicate> 
00366   void unique(_BinaryPredicate __pred) {
00367     _Base::unique(__pred);
00368   }
00369 
00370   template <class _StrictWeakOrdering> 
00371   void merge(_Self& __x, _StrictWeakOrdering __ord) {
00372     _Base::merge((_Base&)__x, __ord);
00373     __x._Invalidate_all();    
00374   }
00375 
00376   template <class _StrictWeakOrdering>
00377   void sort(_StrictWeakOrdering __comp) {
00378       _Invalidate_all();
00379       _Base::sort(__comp);
00380   }
00381 #endif /* _STLP_MEMBER_TEMPLATES */
00382 
00383 };
00384 
00385 #ifdef _STLP_EXTRA_OPERATORS_FOR_DEBUG
00386 
00387 template <class _Tp, class _Alloc>
00388 inline bool 
00389 operator==(const  _DBG_slist<_Tp,_Alloc>& _SL1, 
00390            const  _DBG_slist<_Tp,_Alloc>& _SL2)
00391 {
00392   return (const _STLP_DBG_SLIST_BASE&)_SL1 == (const _STLP_DBG_SLIST_BASE&)_SL2;
00393 }
00394 
00395 template <class _Tp, class _Alloc>
00396 inline bool operator<(const  _DBG_slist<_Tp,_Alloc>& _SL1,
00397                       const  _DBG_slist<_Tp,_Alloc>& _SL2)
00398 {
00399   return (const _STLP_DBG_SLIST_BASE&)_SL1 < (const _STLP_DBG_SLIST_BASE&)_SL2;
00400 }
00401 
00402 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
00403 
00404 template <class _Tp, class _Alloc>
00405 inline bool 
00406 operator!=(const  _DBG_slist<_Tp,_Alloc>& _SL1, 
00407            const  _DBG_slist<_Tp,_Alloc>& _SL2) {
00408   return !(_SL1 == _SL2);
00409 }
00410 
00411 template <class _Tp, class _Alloc>
00412 inline bool 
00413 operator>(const  _DBG_slist<_Tp,_Alloc>& _SL1, 
00414           const  _DBG_slist<_Tp,_Alloc>& _SL2) {
00415   return _SL2 < _SL1;
00416 }
00417 
00418 template <class _Tp, class _Alloc>
00419 inline bool 
00420 operator<=(const  _DBG_slist<_Tp,_Alloc>& _SL1, 
00421            const  _DBG_slist<_Tp,_Alloc>& _SL2) {
00422   return !(_SL2 < _SL1);
00423 }
00424 
00425 template <class _Tp, class _Alloc>
00426 inline bool 
00427 operator>=(const  _DBG_slist<_Tp,_Alloc>& _SL1, 
00428            const  _DBG_slist<_Tp,_Alloc>& _SL2) {
00429   return !(_SL1 < _SL2);
00430 }
00431 #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
00432 #endif /* _STLP_EXTRA_OPERATORS_FOR_DEBUG */
00433 
00434 #ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
00435 template <class _Tp, class _Alloc>
00436 inline void swap( _DBG_slist<_Tp,_Alloc>& __x, 
00437                   _DBG_slist<_Tp,_Alloc>& __y) {
00438   __x.swap(__y);
00439 }
00440 #endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
00441 
00442 _STLP_END_NAMESPACE
00443 
00444 #endif /* _STLP_INTERNAL_DBG_SLIST_H */
00445 
00446 // Local Variables:
00447 // mode:C++
00448 // End:

Generated on Mon Jun 5 10:20:47 2006 for Intelligence.kdevelop by  doxygen 1.4.6