_deque.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_DEQUE_H
00031 #define _STLP_INTERNAL_DBG_DEQUE_H
00032 
00033 #include <stl/debug/_iterator.h>
00034 
00035 # if !defined (_STLP_USE_WRAPPER_FOR_ALLOC_PARAM) && !defined (_STLP_NO_DEFAULT_NON_TYPE_PARAM)
00036 #  undef  _DBG_deque
00037 #  define _DBG_deque deque
00038 # endif
00039 
00040 # define _DEQUE_WRAPPER _DBG_deque<_Tp,_Alloc>
00041 
00042 # define _STLP_DEQUE_SUPER   __WORKAROUND_DBG_RENAME(deque) <_Tp,_Alloc>
00043 
00044 _STLP_BEGIN_NAMESPACE
00045 
00046 # ifdef _STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS
00047 template <class _Tp, class _Alloc>
00048 inline _Tp* value_type(const  _DBG_iter_base< _STLP_DEQUE_SUPER >&) {
00049   return (_Tp*)0;
00050 }
00051 template <class _Tp, class _Alloc>
00052 inline random_access_iterator_tag iterator_category(const  _DBG_iter_base< _STLP_DEQUE_SUPER >&) {
00053   return random_access_iterator_tag();
00054 }
00055 # endif
00056 
00057 template <class _Tp, _STLP_DBG_ALLOCATOR_SELECT(_Tp) >
00058 class _DBG_deque : public _STLP_DEQUE_SUPER {
00059 
00060   typedef _DBG_deque<_Tp,_Alloc> _Self;
00061   typedef _STLP_DEQUE_SUPER _Base;
00062 
00063 public:                         // Basic types
00064 
00065   __IMPORT_CONTAINER_TYPEDEFS(_Base)
00066 
00067 public:                         // Iterators
00068   typedef _DBG_iter< _STLP_DEQUE_SUPER, _Nonconst_traits<value_type> >    iterator;
00069   typedef _DBG_iter< _STLP_DEQUE_SUPER, _Const_traits<value_type> >   const_iterator;
00070 
00071   _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
00072 
00073 protected:
00074   __owned_list _M_iter_list;
00075   void _Invalidate_iterator(const iterator& __it) { 
00076     __invalidate_iterator(&_M_iter_list,__it);
00077   }
00078   void _Invalidate_all() {
00079       _M_iter_list._Invalidate_all();
00080   }
00081 
00082 public:                         // Basic accessors
00083   iterator begin() { return iterator(&_M_iter_list, this->_M_start); }
00084   iterator end() { return iterator(&_M_iter_list, this->_M_finish); }
00085   const_iterator begin() const { 
00086     return const_iterator(&_M_iter_list, this->_M_start); 
00087   }
00088   const_iterator end() const { 
00089     return const_iterator(&_M_iter_list,  this->_M_finish); 
00090   }
00091 
00092   reverse_iterator rbegin() { return reverse_iterator(end()); }
00093   reverse_iterator rend() { return reverse_iterator(begin()); }
00094   const_reverse_iterator rbegin() const 
00095     { return const_reverse_iterator(end()); }
00096   const_reverse_iterator rend() const 
00097     { return const_reverse_iterator(begin()); }
00098 
00099   reference operator[](size_type __n)
00100     { return begin()[difference_type(__n)]; }
00101   const_reference operator[](size_type __n) const 
00102     { return begin()[difference_type(__n)]; }
00103 
00104   reference front() { return *begin(); }
00105   reference back() {
00106     iterator __tmp = end();
00107     --__tmp;
00108     return *__tmp;
00109   }
00110   const_reference front() const { return *begin(); }
00111   const_reference back() const {
00112     const_iterator __tmp = end();
00113     --__tmp;
00114     return *__tmp;
00115   }
00116 
00117 public:                         // Constructor, destructor.
00118 
00119   const _Base* _Get_base() const { return (const _Base*)this; }
00120 
00121   explicit _DBG_deque(const allocator_type& __a = allocator_type()) :
00122     _STLP_DEQUE_SUPER(__a), _M_iter_list(_Get_base()) {}
00123   _DBG_deque(const _Self& __x) : _STLP_DEQUE_SUPER(__x), _M_iter_list(_Get_base()) {}
00124   _DBG_deque(size_type __n, const value_type& __value,
00125         const allocator_type& __a = allocator_type()) : 
00126     _STLP_DEQUE_SUPER(__n, __value, __a), _M_iter_list(_Get_base()) {}
00127   explicit _DBG_deque(size_type __n) : _STLP_DEQUE_SUPER(__n), _M_iter_list(_Get_base()) {}
00128 
00129 #ifdef _STLP_MEMBER_TEMPLATES
00130   template <class _InputIterator>
00131   _DBG_deque(_InputIterator __first, _InputIterator __last,
00132         const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL) : 
00133     _STLP_DEQUE_SUPER(__first, __last, __a) , _M_iter_list(_Get_base()) {}
00134 # ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
00135   template <class _InputIterator>
00136   _DBG_deque(_InputIterator __first, _InputIterator __last):
00137     _STLP_DEQUE_SUPER(__first, __last, allocator_type()) , _M_iter_list(_Get_base()) {}
00138 # endif
00139 #else /* _STLP_MEMBER_TEMPLATES */
00140   _DBG_deque(const value_type* __first, const value_type* __last,
00141         const allocator_type& __a = allocator_type()) 
00142     : _STLP_DEQUE_SUPER(__first, __last, __a), _M_iter_list(_Get_base()) {}
00143 
00144   _DBG_deque(const_iterator __first, const_iterator __last,
00145         const allocator_type& __a = allocator_type()) 
00146     : _STLP_DEQUE_SUPER(__first._M_iterator, __last._M_iterator, __a), 
00147       _M_iter_list(_Get_base()) {}
00148 #endif /* _STLP_MEMBER_TEMPLATES */
00149 
00150   _Self& operator= (const _Self& __x) {
00151     _Invalidate_all();
00152     (_Base&)*this = (const _Base&)__x; 
00153     return *this;
00154   }
00155 
00156   void swap(_Self& __x) {
00157     _M_iter_list._Swap_owners(__x._M_iter_list);
00158     _Base::swap(__x);
00159   }
00160 
00161 public: 
00162   void assign(size_type __n, const _Tp& __val) {
00163     _Base::assign(__n, __val);
00164   }
00165 
00166 #ifdef _STLP_MEMBER_TEMPLATES
00167 
00168   template <class _InputIterator>
00169   void assign(_InputIterator __first, _InputIterator __last) {
00170     _Base::assign(__first, __last);
00171   }
00172 #endif /* _STLP_MEMBER_TEMPLATES */
00173 
00174 public:                         // push_* and pop_*
00175   
00176   void push_back(const value_type& __t) {
00177     _Invalidate_all();
00178     _Base::push_back(__t);
00179   }
00180 
00181   void push_back() {
00182     _Invalidate_all();
00183     _Base::push_back();
00184   }
00185 
00186   void push_front(const value_type& __t) {
00187     _Invalidate_all();
00188     _Base::push_front(__t);
00189   }
00190 
00191   void push_front() {
00192     _Base::push_front();
00193     _Invalidate_all();
00194   }
00195 
00196 
00197   void pop_back() {
00198     _Invalidate_iterator(end());
00199     _Base::pop_back();
00200   }
00201 
00202   void pop_front() {
00203     _Invalidate_iterator(begin());        
00204     _Base::pop_front();
00205   }
00206 
00207 public:                         // Insert
00208 
00209   iterator insert(iterator __position, const value_type& __x) {
00210     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __position))
00211     // fbp : invalidation !
00212     return iterator(&_M_iter_list, _Base::insert(__position._M_iterator, __x));
00213   }
00214 
00215   iterator insert(iterator __position) { 
00216     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __position))
00217     // fbp : invalidation !
00218     return iterator(&_M_iter_list, _Base::insert(__position._M_iterator));
00219   }
00220 
00221   void insert(iterator __position, size_type __n, const value_type& __x) {
00222     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __position))
00223     // fbp : invalidation !
00224     _Base::insert(__position._M_iterator, __n, __x);
00225   }
00226 
00227 #ifdef _STLP_MEMBER_TEMPLATES  
00228   template <class _InputIterator>
00229   void insert(iterator __position, _InputIterator __first, _InputIterator __last) {
00230     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __position))
00231     // fbp : invalidation !
00232     _Base::insert(__position._M_iterator, __first, __last);
00233   }
00234 #else /* _STLP_MEMBER_TEMPLATES */
00235   void insert(iterator __position,
00236               const value_type* __first, const value_type* __last) {
00237     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __position))
00238     _Base::insert(__position._M_iterator, __first, __last);
00239   }
00240   void insert(iterator __position,
00241               const_iterator __first, const_iterator __last) {
00242     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __position))
00243     _Base::insert(__position._M_iterator, __first._M_iterator, __last._M_iterator);
00244   }
00245 #endif /* _STLP_MEMBER_TEMPLATES */
00246 
00247   //  void resize(size_type __new_size, const value_type& __x) {
00248   //    _Base::resize(__new_size, __x);
00249   //  }
00250 
00251   //  void resize(size_type new_size) { resize(new_size, value_type()); }
00252 
00253 public:                         // Erase
00254   iterator erase(iterator __pos) {
00255     _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __pos) && (__pos != end()))
00256     return iterator (&_M_iter_list, _Base::erase(__pos._M_iterator));
00257   }
00258 
00259   iterator erase(iterator __first, iterator __last) {
00260     _STLP_DEBUG_CHECK(__first >= begin() && __last <= end())
00261     return iterator (&_M_iter_list, _Base::erase(__first._M_iterator, __last._M_iterator));
00262   }
00263   
00264   void clear() {
00265     _Invalidate_all();
00266     _Base::clear();
00267   }
00268 };
00269 
00270 # ifdef _STLP_EXTRA_OPERATORS_FOR_DEBUG
00271 // Nonmember functions.
00272 
00273 template<class _Tp, class _Alloc>
00274 inline bool operator==(const _DBG_deque<_Tp,_Alloc >& __x, const _DBG_deque<_Tp,_Alloc >& __y)
00275 {
00276     return (const _STLP_DEQUE_SUPER&)__x == (const _STLP_DEQUE_SUPER&)__y;
00277 }
00278 
00279 template<class _Tp, class _Alloc>
00280 inline bool operator<(const _DBG_deque<_Tp,_Alloc >& __x, const _DBG_deque<_Tp,_Alloc >& __y)
00281 {
00282   return (const _STLP_DEQUE_SUPER&)__x < (const _STLP_DEQUE_SUPER&)__y;
00283 }
00284 
00285 #if defined(_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
00286 
00287 template<class _Tp, class _Alloc>
00288 inline bool operator>(const _DBG_deque<_Tp,_Alloc >& __x, const _DBG_deque<_Tp,_Alloc >& __y)
00289 {
00290   return __y < __x; 
00291 }
00292 
00293 template<class _Tp, class _Alloc>
00294 inline bool operator>=(const _DBG_deque<_Tp,_Alloc >& __x, const _DBG_deque<_Tp,_Alloc >& __y)
00295 {
00296   return !(__x < __y); 
00297 }
00298 
00299 template<class _Tp, class _Alloc>
00300 inline bool operator<=(const _DBG_deque<_Tp,_Alloc >& __x,
00301                        const _DBG_deque<_Tp,_Alloc >& __y)
00302 {
00303  return !(__y < __x); 
00304 }
00305 # endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
00306 #endif /* _STLP_EXTRA_OPERATORS_FOR_DEBUG */
00307 
00308 
00309 #if defined(_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
00310 template<class _Tp, class _Alloc>
00311 inline void 
00312 swap(_DBG_deque<_Tp,_Alloc>& __x, _DBG_deque<_Tp,_Alloc>& __y)
00313 {
00314   __x.swap(__y);
00315 }
00316 #endif
00317 
00318 _STLP_END_NAMESPACE 
00319 
00320 # undef _DBG_deque
00321 # undef _STLP_DEQUE_SUPER
00322   
00323 #endif /* _STLP_INTERNAL_DEQUE_H */
00324 
00325 // Local Variables:
00326 // mode:C++
00327 // End:

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