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

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