ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

_vector.h
Go to the documentation of this file.
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 #ifndef _STLP_DBG_ITERATOR_H
00034 #  include <stl/debug/_iterator.h>
00035 #endif
00036 
00037 #define _STLP_NON_DBG_VECTOR _STLP_PRIV _STLP_NON_DBG_NAME(vector) <_Tp, _Alloc>
00038 
00039 _STLP_BEGIN_NAMESPACE
00040 
00041 #if defined (_STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS)
00042 template <class _Tp, class _Alloc>
00043 inline _Tp*
00044 value_type(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_VECTOR >&)
00045 { return (_Tp*)0; }
00046 template <class _Tp, class _Alloc>
00047 inline random_access_iterator_tag
00048 iterator_category(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_VECTOR >&)
00049 { return random_access_iterator_tag(); }
00050 #endif
00051 
00052 _STLP_MOVE_TO_PRIV_NAMESPACE
00053 
00054 template <class _Tp, class _NcIt>
00055 struct _Vector_const_traits;
00056 
00057 template <class _Tp, class _NcIt>
00058 struct _Vector_nonconst_traits {
00059   typedef _Nonconst_traits<_Tp> _BaseT;
00060   typedef _Tp value_type;
00061   typedef _Tp& reference;
00062   typedef _Tp* pointer;
00063   typedef _Vector_const_traits<_Tp, _NcIt> _ConstTraits;
00064   typedef _Vector_nonconst_traits<_Tp, _NcIt> _NonConstTraits;
00065 };
00066 
00067 template <class _Tp, class _NcIt>
00068 struct _Vector_const_traits {
00069   typedef _Const_traits<_Tp> _BaseT;
00070   typedef _Tp value_type;
00071   typedef const _Tp& reference;
00072   typedef const _Tp* pointer;
00073   typedef _Vector_const_traits<_Tp, _NcIt> _ConstTraits;
00074   typedef _Vector_nonconst_traits<_Tp, _NcIt> _NonConstTraits;
00075 };
00076 
00077 _STLP_TEMPLATE_NULL
00078 struct _Vector_nonconst_traits<bool, _Bit_iterator> {
00079   typedef _Bit_iterator::value_type value_type;
00080   typedef _Bit_iterator::reference reference;
00081   typedef _Bit_iterator::pointer pointer;
00082   typedef _Vector_const_traits<bool, _Bit_iterator> _ConstTraits;
00083   typedef _Vector_nonconst_traits<bool, _Bit_iterator> _NonConstTraits;
00084 };
00085 
00086 _STLP_TEMPLATE_NULL
00087 struct _Vector_const_traits<bool, _Bit_iterator> {
00088   typedef _Bit_const_iterator::value_type value_type;
00089   typedef _Bit_const_iterator::reference reference;
00090   typedef _Bit_const_iterator::pointer pointer;
00091   typedef _Vector_const_traits<bool, _Bit_iterator> _ConstTraits;
00092   typedef _Vector_nonconst_traits<bool, _Bit_iterator> _NonConstTraits;
00093 };
00094 
00095 _STLP_MOVE_TO_STD_NAMESPACE
00096 
00097 template <class _Tp, _STLP_DFL_TMPL_PARAM(_Alloc, allocator<_Tp>) >
00098 class vector :
00099 #if !defined (__DMC__)
00100              private
00101 #endif
00102                      _STLP_PRIV __construct_checker< _STLP_NON_DBG_VECTOR >
00103 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
00104              , public __stlport_class<vector<_Tp, _Alloc> >
00105 #endif
00106 {
00107 private:
00108   typedef _STLP_NON_DBG_VECTOR _Base;
00109   typedef vector<_Tp, _Alloc> _Self;
00110   typedef _STLP_PRIV __construct_checker<_STLP_NON_DBG_VECTOR > _ConstructCheck;
00111   _Base _M_non_dbg_impl;
00112   _STLP_PRIV __owned_list _M_iter_list;
00113 
00114 public:
00115   __IMPORT_CONTAINER_TYPEDEFS(_Base)
00116 
00117   typedef _STLP_PRIV _DBG_iter<_Base,
00118     _STLP_PRIV _DbgTraits<_STLP_PRIV _Vector_nonconst_traits<value_type, typename _Base::iterator> > > iterator;
00119 
00120   typedef _STLP_PRIV _DBG_iter<_Base,
00121     _STLP_PRIV _DbgTraits<_STLP_PRIV _Vector_const_traits<value_type, typename _Base::iterator> > > const_iterator;
00122 
00123 private:
00124   void _Invalidate_all()
00125   { _M_iter_list._Invalidate_all(); }
00126   void _Invalidate_iterator(const iterator& __it)
00127   { _STLP_PRIV __invalidate_iterator(&_M_iter_list, __it); }
00128   void _Invalidate_iterators(const iterator& __first, const iterator& __last)
00129   { _STLP_PRIV __invalidate_range(&_M_iter_list, __first, __last); }
00130 
00131   void _Check_Overflow(size_type __nb) {
00132     if (size() + __nb > capacity())
00133       _Invalidate_all();
00134   }
00135   void _Compare_Capacity (size_type __old_capacity) {
00136     if (capacity() > __old_capacity) {
00137       _Invalidate_all();
00138     }
00139   }
00140 
00141 public:
00142   _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
00143 
00144   allocator_type get_allocator() const { return _M_non_dbg_impl.get_allocator(); }
00145 
00146   iterator begin()             { return iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
00147   const_iterator begin() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
00148   iterator end()               { return iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
00149   const_iterator end() const   { return const_iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
00150 
00151   reverse_iterator rbegin()             { return reverse_iterator(end()); }
00152   const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
00153   reverse_iterator rend()               { return reverse_iterator(begin()); }
00154   const_reverse_iterator rend() const   { return const_reverse_iterator(begin()); }
00155 
00156   size_type size() const        { return _M_non_dbg_impl.size(); }
00157   size_type max_size() const    { return _M_non_dbg_impl.max_size(); }
00158   size_type capacity() const    { return _M_non_dbg_impl.capacity(); }
00159   bool empty() const            { return _M_non_dbg_impl.empty(); }
00160 
00161   reference operator[](size_type __n) {
00162     _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
00163     return _M_non_dbg_impl[__n];
00164   }
00165 
00166   const_reference operator[](size_type __n) const {
00167     _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
00168     return _M_non_dbg_impl[__n];
00169   }
00170 
00171   reference at(size_type __n) { return _M_non_dbg_impl.at(__n); }
00172   const_reference at(size_type __n) const { return _M_non_dbg_impl.at(__n); }
00173 
00174   explicit vector(const allocator_type& __a = allocator_type())
00175     : _M_non_dbg_impl(__a), _M_iter_list(&_M_non_dbg_impl)  {}
00176 
00177 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
00178   explicit vector(size_type __n, const _Tp& __x = _Tp(),
00179 #else
00180   vector(size_type __n, const _Tp& __x,
00181 #endif
00182          const allocator_type& __a = allocator_type())
00183     : _M_non_dbg_impl(__n, __x, __a), _M_iter_list(&_M_non_dbg_impl) {}
00184 
00185 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
00186   explicit vector(size_type __n)
00187     : _M_non_dbg_impl(__n), _M_iter_list(&_M_non_dbg_impl) {}
00188 #endif
00189 
00190   vector(const _Self& __x)
00191     : _ConstructCheck(__x), _M_non_dbg_impl(__x._M_non_dbg_impl), _M_iter_list(&_M_non_dbg_impl) {}
00192 
00193 #if !defined (_STLP_NO_MOVE_SEMANTIC)
00194   vector(__move_source<_Self> src)
00195     : _M_non_dbg_impl(__move_source<_Base>(src.get()._M_non_dbg_impl)),
00196       _M_iter_list(&_M_non_dbg_impl) {
00197 #  if defined (_STLP_NO_EXTENSIONS) || (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
00198     src.get()._M_iter_list._Invalidate_all();
00199 #  else
00200     src.get()._M_iter_list._Set_owner(_M_iter_list);
00201 #  endif
00202   }
00203 #endif
00204 
00205 #if defined (_STLP_MEMBER_TEMPLATES)
00206   template <class _InputIterator>
00207   vector(_InputIterator __first, _InputIterator __last,
00208          const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
00209     : _ConstructCheck(__first, __last),
00210       _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last), __a),
00211       _M_iter_list(&_M_non_dbg_impl) {}
00212 
00213 #  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
00214   template <class _InputIterator>
00215   vector(_InputIterator __first, _InputIterator __last)
00216     : _ConstructCheck(__first, __last),
00217       _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last)),
00218       _M_iter_list(&_M_non_dbg_impl) {}
00219 #  endif
00220 #else
00221   vector(const _Tp* __first, const _Tp* __last,
00222          const allocator_type& __a = allocator_type())
00223     : _ConstructCheck(__first, __last), _M_non_dbg_impl(__first, __last, __a),
00224     _M_iter_list(&_M_non_dbg_impl) {}
00225 
00226   // mysterious VC++ bug ?
00227   vector(const_iterator __first, const_iterator __last ,
00228          const allocator_type& __a = allocator_type())
00229     : _ConstructCheck(__first, __last),
00230       _M_non_dbg_impl(__first._M_iterator, __last._M_iterator, __a),
00231     _M_iter_list(&_M_non_dbg_impl) {}
00232 #endif /* _STLP_MEMBER_TEMPLATES */
00233 
00234   _Self& operator=(const _Self& __x) {
00235     if (this != &__x) {
00236       _Invalidate_all();
00237       _M_non_dbg_impl = __x._M_non_dbg_impl;
00238     }
00239     return *this;
00240   }
00241 
00242   void reserve(size_type __n) {
00243     if (capacity() < __n)
00244       _Invalidate_all();
00245     _M_non_dbg_impl.reserve(__n);
00246   }
00247 
00248   reference front() {
00249     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
00250     return *begin();
00251   }
00252   const_reference front() const {
00253     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
00254     return *begin();
00255   }
00256   reference back() {
00257     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
00258     return *(--end());
00259   }
00260   const_reference back() const {
00261     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
00262     return *(--end());
00263   }
00264 
00265   void swap(_Self& __x) {
00266     _M_iter_list._Swap_owners(__x._M_iter_list);
00267     _M_non_dbg_impl.swap(__x._M_non_dbg_impl);
00268   }
00269 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
00270   void _M_swap_workaround(_Self& __x) { swap(__x); }
00271 #endif
00272 
00273 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
00274   iterator insert(iterator __pos, const _Tp& __x = _Tp()) {
00275 #else
00276   iterator insert(iterator __pos, const _Tp& __x) {
00277 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
00278     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
00279     _Check_Overflow(1);
00280     return iterator(&_M_iter_list, _M_non_dbg_impl.insert(__pos._M_iterator, __x));
00281   }
00282 
00283 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
00284   iterator insert(iterator __pos)
00285   { return insert(__pos, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
00286 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
00287 
00288 #if defined (_STLP_MEMBER_TEMPLATES)
00289   // Check whether it's an integral type.  If so, it's not an iterator.
00290   template <class _InputIterator>
00291   void insert(iterator __pos,
00292               _InputIterator __first, _InputIterator __last) {
00293     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00294     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
00295     size_type __old_capacity = capacity();
00296     _M_non_dbg_impl.insert(__pos._M_iterator,
00297                            _STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
00298     _Compare_Capacity(__old_capacity);
00299   }
00300 #endif
00301 #if !defined (_STLP_MEMBER_TEMPLATES)
00302   void insert (iterator __pos,
00303                const value_type *__first, const value_type *__last) {
00304     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first,__last))
00305     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
00306     size_type __old_capacity = capacity();
00307     _M_non_dbg_impl.insert(__pos._M_iterator, __first, __last);
00308     _Compare_Capacity(__old_capacity);
00309   }
00310 #endif
00311 
00312 #if !defined (_STLP_MEMBER_TEMPLATES) || !defined (_STLP_NO_METHOD_SPECIALIZATION)
00313   void insert(iterator __pos,
00314               const_iterator __first, const_iterator __last) {
00315     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first,__last))
00316     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
00317     //Sequence requirements 23.1.1 Table 67:
00318     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first));
00319     size_type __old_capacity = capacity();
00320     _M_non_dbg_impl.insert(__pos._M_iterator, __first._M_iterator, __last._M_iterator);
00321     _Compare_Capacity(__old_capacity);
00322   }
00323   void insert(iterator __pos,
00324               iterator __first, iterator __last) {
00325     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first,__last))
00326     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
00327     //Sequence requirements 23.1.1 Table 67:
00328     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first));
00329     size_type __old_capacity = capacity();
00330     _M_non_dbg_impl.insert(__pos._M_iterator, __first._M_iterator, __last._M_iterator);
00331     _Compare_Capacity(__old_capacity);
00332   }
00333 #endif
00334 
00335   void insert (iterator __pos, size_type __n, const _Tp& __x){
00336     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
00337     _Check_Overflow(__n);
00338     _M_non_dbg_impl.insert(__pos._M_iterator, __n, __x);
00339   }
00340 
00341   void pop_back() {
00342     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
00343     _Invalidate_iterator(end());
00344     _M_non_dbg_impl.pop_back();
00345   }
00346   iterator erase(iterator __pos) {
00347     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
00348     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
00349     _Invalidate_iterators(__pos, end());
00350     return iterator(&_M_iter_list, _M_non_dbg_impl.erase(__pos._M_iterator));
00351   }
00352   iterator erase(iterator __first, iterator __last) {
00353     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last, begin(), end()))
00354     _Invalidate_iterators(__first, end());
00355     return iterator(&_M_iter_list, _M_non_dbg_impl.erase(__first._M_iterator, __last._M_iterator));
00356   }
00357 
00358 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
00359   void resize(size_type __new_size, const _Tp& __x = _STLP_DEFAULT_CONSTRUCTED(_Tp)) {
00360 #else
00361   void resize(size_type __new_size, const _Tp& __x) {
00362 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
00363     if (__new_size > capacity()) {
00364       _Invalidate_all();
00365     }
00366     else if (__new_size < size()) {
00367       _Invalidate_iterators(begin() + __new_size, end());
00368     }
00369     _M_non_dbg_impl.resize(__new_size, __x);
00370   }
00371 
00372 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
00373   void resize(size_type __new_size) { resize(__new_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
00374 #endif
00375 
00376 #if defined (_STLP_MEMBER_TEMPLATES)
00377   template <class _InputIterator>
00378   void assign(_InputIterator __first, _InputIterator __last) {
00379     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first,__last))
00380     _Invalidate_all();
00381     _M_non_dbg_impl.assign(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
00382   }
00383 #else
00384 private:
00385   void _M_assign(const value_type *__first, const value_type *__last) {
00386     _Invalidate_all();
00387     _M_non_dbg_impl.assign(__first, __last);
00388   }
00389 public:
00390   void assign(const value_type *__first, const value_type *__last) {
00391     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first,__last))
00392     _M_assign(__first, __last);
00393   }
00394 
00395   void assign(const_iterator __first, const_iterator __last) {
00396     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first,__last))
00397     _M_assign(__first._M_iterator, __last._M_iterator);
00398   }
00399 #endif
00400 
00401 public:
00402   void assign(size_type __n, const _Tp& __val) {
00403     _Invalidate_all();
00404     _M_non_dbg_impl.assign(__n, __val);
00405   }
00406 
00407   void clear() {
00408     _Invalidate_all();
00409     _M_non_dbg_impl.clear();
00410   }
00411   void push_back(const _Tp& __x) {
00412     _Check_Overflow(1);
00413     _M_non_dbg_impl.push_back(__x);
00414   }
00415 };
00416 
00417 _STLP_END_NAMESPACE
00418 
00419 #undef _STLP_NON_DBG_VECTOR
00420 
00421 #endif /* _STLP_DBG_VECTOR_H */
00422 
00423 // Local Variables:
00424 // mode:C++
00425 // End:

Generated on Sat May 26 2012 04:28:23 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.