_list.h

00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Copyright (c) 1996,1997
00007  * Silicon Graphics Computer Systems, Inc.
00008  *
00009  * Copyright (c) 1997
00010  * Moscow Center for SPARC Technology
00011  *
00012  * Copyright (c) 1999 
00013  * Boris Fomitchev
00014  *
00015  * This material is provided "as is", with absolutely no warranty expressed
00016  * or implied. Any use is at your own risk.
00017  *
00018  * Permission to use or copy this software for any purpose is hereby granted 
00019  * without fee, provided the above notices are retained on all copies.
00020  * Permission to modify the code and to distribute modified code is granted,
00021  * provided the above notices are retained, and a notice that the code was
00022  * modified is included with the above copyright notice.
00023  *
00024  */
00025 
00026 /* NOTE: This is an internal header file, included by other STL headers.
00027  *   You should not attempt to use it directly.
00028  */
00029 
00030 #ifndef _STLP_INTERNAL_DBG_LIST_H
00031 #define _STLP_INTERNAL_DBG_LIST_H
00032 
00033 #include <stl/debug/_iterator.h>
00034 
00035 # ifndef _STLP_USE_WRAPPER_FOR_ALLOC_PARAM
00036 #  undef  _DBG_list
00037 #  define _DBG_list list
00038 # endif
00039 
00040 #  define _STLP_DBG_LIST_BASE \
00041 __WORKAROUND_DBG_RENAME(list) <_Tp, _Alloc>
00042 
00043 _STLP_BEGIN_NAMESPACE
00044 
00045 # ifdef _STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS
00046 template <class _Tp, class _Alloc>
00047 inline _Tp*
00048 value_type(const  _DBG_iter_base< _STLP_DBG_LIST_BASE >&) {
00049   return (_Tp*)0;
00050 }
00051 template <class _Tp, class _Alloc>
00052 inline bidirectional_iterator_tag
00053 iterator_category(const _DBG_iter_base< _STLP_DBG_LIST_BASE >&) {
00054   return bidirectional_iterator_tag();
00055 }
00056 # endif
00057 
00058 template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) >
00059 class _DBG_list : public _STLP_DBG_LIST_BASE {
00060 
00061   typedef _STLP_DBG_LIST_BASE _Base;
00062   typedef _DBG_list<_Tp, _Alloc> _Self;
00063 
00064 public:      
00065   __IMPORT_CONTAINER_TYPEDEFS(_Base)
00066 
00067 public:
00068   typedef _DBG_iter<_Base, _Nonconst_traits<value_type> >     iterator;
00069   typedef _DBG_iter<_Base, _Const_traits<value_type> >    const_iterator;
00070 
00071   _STLP_DECLARE_BIDIRECTIONAL_REVERSE_ITERATORS;
00072 
00073 protected:
00074   mutable __owned_list _M_iter_list;
00075   void _Invalidate_all() { _M_iter_list._Invalidate_all();}
00076 
00077 public:
00078   const _Base* _Get_base() const { return (const _Base*)this; }
00079   _Base* _Get_base() { return (_Base*)this; }
00080   explicit _DBG_list(const allocator_type& __a = allocator_type()) :
00081     _STLP_DBG_LIST_BASE(__a), _M_iter_list(_Get_base()) {}
00082   _DBG_list(size_type __n, const _Tp& __value,
00083             const allocator_type& __a = allocator_type())
00084     : _STLP_DBG_LIST_BASE(__n, __value, __a), _M_iter_list(_Get_base()) {}
00085   explicit _DBG_list(size_type __n)
00086     : _STLP_DBG_LIST_BASE(__n), _M_iter_list(_Get_base()) {}
00087   
00088 #ifdef _STLP_MEMBER_TEMPLATES
00089 
00090   // We don't need any dispatching tricks here, because insert does all of
00091   // that anyway.  
00092 #  ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
00093   template <class _InputIterator>
00094   _DBG_list(_InputIterator __first, _InputIterator __last)
00095     : _STLP_DBG_LIST_BASE(__first, __last, allocator_type()), _M_iter_list(_Get_base()) {}
00096 #  endif
00097   template <class _InputIterator>
00098   _DBG_list(_InputIterator __first, _InputIterator __last,
00099        const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
00100     : _STLP_DBG_LIST_BASE(__first, __last, __a), _M_iter_list(_Get_base()) {}
00101 #else /* _STLP_MEMBER_TEMPLATES */
00102 
00103   _DBG_list(const _Tp* __first, const _Tp* __last,
00104        const allocator_type& __a = allocator_type())
00105     : _STLP_DBG_LIST_BASE(__first, __last, __a), _M_iter_list(_Get_base()) {}
00106   _DBG_list(const_iterator __first, const_iterator __last,
00107        const allocator_type& __a = allocator_type()):
00108     _STLP_DBG_LIST_BASE(__first._M_iterator, __last._M_iterator, __a),
00109     _M_iter_list(_Get_base()) {}
00110 
00111 #endif /* _STLP_MEMBER_TEMPLATES */
00112 
00113   _DBG_list(const _Self& __x) : 
00114     _STLP_DBG_LIST_BASE(__x) , _M_iter_list(_Get_base()) {}
00115 
00116   _Self& operator=(const _Self& __x) {
00117     _Invalidate_all();
00118     _Base::operator=((const _Base&)__x);
00119     return *this;
00120   }
00121 
00122 public:
00123   iterator begin()             { return iterator(&_M_iter_list, _Base::begin()); }
00124   const_iterator begin() const { return const_iterator(&_M_iter_list, _Base::begin()); }
00125 
00126   iterator end()               { return iterator(&_M_iter_list, _Base::end()); }
00127   const_iterator end() const   { return const_iterator(&_M_iter_list, _Base::end()); }
00128 
00129   reverse_iterator rbegin()    { return reverse_iterator(end()); }
00130   reverse_iterator rend()      { return reverse_iterator(begin()); }
00131 
00132   const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
00133   const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
00134 
00135   // those are here to enforce checking
00136   reference front() { return *begin(); }
00137   const_reference front() const { return *begin(); }
00138   reference back() { return *(--end()); }
00139   const_reference back() const { return *(--end()); }
00140 
00141   void swap(_Self& __x) {
00142     _M_iter_list._Swap_owners(__x._M_iter_list);
00143     _Base::swap(__x); 
00144   }
00145 
00146   iterator insert(iterator __position, const _Tp& __x) {
00147     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position))
00148       return iterator(&_M_iter_list,_Base::insert(__position._M_iterator, __x) );
00149   }
00150 
00151 # ifndef _STLP_NO_ANACHRONISMS
00152   iterator insert(iterator __position) { return insert(__position, _Tp()); }
00153 # endif
00154 
00155 #ifdef _STLP_MEMBER_TEMPLATES
00156 
00157   template <class _InputIterator>
00158   void insert(iterator __position, _InputIterator __first, _InputIterator __last) {
00159     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position))
00160     _Base::insert(__position._M_iterator, __first, __last);
00161   }
00162 
00163 #else
00164 
00165   void insert(iterator __position, const _Tp* __first, const _Tp* __last) {
00166     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position))
00167     _Base::insert(__position._M_iterator, __first, __last);
00168   }
00169 
00170   void insert(iterator __position,
00171               const_iterator __first, const_iterator __last) {
00172     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position))
00173     _Base::insert(__position._M_iterator, __first._M_iterator, __last._M_iterator);
00174   }
00175   
00176 #endif /* _STLP_MEMBER_TEMPLATES */
00177 
00178   void insert(iterator __position, size_type __n, const _Tp& __x) {
00179     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position))
00180     _Base::insert(__position._M_iterator, __n, __x);    
00181   }
00182 
00183   void pop_back() {
00184     _STLP_VERBOSE_ASSERT(!this->empty(), _StlMsg_EMPTY_CONTAINER)
00185     __invalidate_iterator(&_M_iter_list,end());
00186     _Base::pop_back();
00187   }
00188 
00189   void pop_front() {
00190     _STLP_VERBOSE_ASSERT(!this->empty(), _StlMsg_EMPTY_CONTAINER)
00191     __invalidate_iterator(&_M_iter_list,begin());
00192     _Base::pop_front();
00193   }
00194 
00195   iterator erase(iterator __position) {
00196     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position))
00197     _STLP_VERBOSE_ASSERT(__position._M_iterator._M_node!=this->_M_node._M_data, 
00198                          _StlMsg_ERASE_PAST_THE_END)
00199     // fbp : CHECK !!!
00200     __invalidate_iterator(&_M_iter_list, __position);
00201     return iterator(&_M_iter_list,_Base::erase(__position._M_iterator));
00202   }
00203   iterator erase(iterator __first, iterator __last) {
00204     while (__first != __last)
00205       erase(__first++);
00206     return __last;
00207   }
00208 
00209   void resize(size_type __new_size, const _Tp& __x) {
00210     typename _Base::iterator __i = _Base::begin();
00211     size_type __len = 0;
00212     for ( ; __i != _Base::end() && __len < __new_size; ++__i, ++__len);
00213     
00214     if (__len == __new_size)
00215       erase(iterator(&_M_iter_list,__i), end());
00216     else                          // __i == end()
00217       _Base::insert(_Base::end(), __new_size - __len, __x);
00218   }
00219 
00220   void resize(size_type __new_size) { this->resize(__new_size, _Tp()); }
00221 
00222   void remove(const _Tp& __value) {
00223     typename _Base::iterator __first = _Base::begin();
00224     typename _Base::iterator __last = _Base::end();
00225     while (__first != __last) {
00226       typename _Base::iterator __next = __first;
00227       ++__next;
00228       if (__value == *__first) erase(iterator(&_M_iter_list,__first));
00229       __first = __next;
00230     }
00231   }
00232 
00233   void clear() {   
00234     _Invalidate_all();
00235     _Base::clear(); 
00236   }
00237 
00238 public:
00239   void splice(iterator __position, _Self& __x) {
00240     _STLP_VERBOSE_ASSERT(&__x!=this, _StlMsg_INVALID_ARGUMENT)
00241     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position))
00242     _Base::splice(__position._M_iterator, __x);
00243     __x._Invalidate_all();
00244   }
00245 
00246   void splice(iterator __position, _Self& __x, iterator __i) {
00247       _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list,__position) &&
00248                         __check_if_owner(&__x._M_iter_list ,__i))
00249     _STLP_DEBUG_CHECK(_Dereferenceable(__i))
00250     // fbp : CHECK !!!
00251         // __invalidate_iterator(&__x._M_iter_list, __i);
00252     _Base::splice(__position._M_iterator, __x, __i._M_iterator);
00253   }
00254 
00255   void splice(iterator __position, _Self& __x, iterator __first, iterator __last) {
00256     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __position))
00257     _STLP_VERBOSE_ASSERT(__first._Owner()==&__x._M_iter_list && __last._Owner()==&__x._M_iter_list, 
00258                          _StlMsg_NOT_OWNER)
00259     _Base::splice(__position._M_iterator, __x, __first._M_iterator, __last._M_iterator);
00260   }
00261 
00262   void merge(_Self& __x) {   
00263     __x._Invalidate_all();
00264     _Base::merge(__x); 
00265   }
00266   void reverse() {
00267     _Invalidate_all();
00268     _Base::reverse();
00269   }
00270   void unique() {
00271     _Invalidate_all();
00272     _Base::unique();
00273   }
00274   void sort() {
00275     _Invalidate_all();
00276     _Base::sort();
00277   }
00278 
00279 #ifdef _STLP_MEMBER_TEMPLATES
00280 
00281   template <class _Predicate> void remove_if(_Predicate __pred)  {
00282     _Base::remove_if(__pred);
00283   }
00284   template <class _BinaryPredicate>
00285     void unique(_BinaryPredicate __binary_pred) {
00286     _Base::unique(__binary_pred);
00287   }
00288   template <class _StrictWeakOrdering>
00289     void merge(_Self& __x,
00290                _StrictWeakOrdering __comp) {
00291     __x._Invalidate_all();
00292     _Base::merge(__x, __comp);
00293   }
00294 
00295   template <class _StrictWeakOrdering>
00296   void sort(_StrictWeakOrdering __comp) {
00297       _Invalidate_all();
00298       _Base::sort(__comp);
00299   }
00300 #endif /* _STLP_MEMBER_TEMPLATES */
00301 
00302 };
00303 
00304 #ifdef _STLP_EXTRA_OPERATORS_FOR_DEBUG
00305 template <class _Tp, class _Alloc>
00306 _STLP_INLINE_LOOP bool operator==(const _DBG_list<_Tp,_Alloc>& __x,
00307                                   const _DBG_list<_Tp,_Alloc>& __y)
00308 {
00309   return (const _STLP_DBG_LIST_BASE&)__x == (const _STLP_DBG_LIST_BASE&)__y;
00310 }
00311 template <class _Tp, class _Alloc>
00312 inline bool operator<(const _DBG_list<_Tp,_Alloc>& __x,
00313                       const _DBG_list<_Tp,_Alloc>& __y)
00314 {
00315   return (const _STLP_DBG_LIST_BASE&)__x < (const _STLP_DBG_LIST_BASE&)__y;
00316 }
00317 #endif
00318 
00319 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
00320 template <class _Tp, class _Alloc>
00321 inline void 
00322 swap(_DBG_list<_Tp, _Alloc>& __x, _DBG_list<_Tp, _Alloc>& __y)
00323 {
00324   __x.swap(__y);
00325 }
00326 #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
00327 
00328 _STLP_END_NAMESPACE 
00329 
00330 #endif /* _STLP_INTERNAL_LIST_H */
00331 
00332 // Local Variables:
00333 // mode:C++
00334 // End:

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