/home/ntakagi/work/STLport-5.1.5/stlport/stl/debug/_deque.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_DEQUE_H
00031 #define _STLP_INTERNAL_DBG_DEQUE_H
00032 
00033 #ifndef _STLP_DBG_ITERATOR_H
00034 #  include <stl/debug/_iterator.h>
00035 #endif
00036 
00037 #define _STLP_NON_DBG_DEQUE _STLP_PRIV _STLP_NON_DBG_NAME(deque) <_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* value_type(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_DEQUE >&)
00044 { return (_Tp*)0; }
00045 template <class _Tp, class _Alloc>
00046 inline random_access_iterator_tag iterator_category(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_DEQUE >&)
00047 { return random_access_iterator_tag(); }
00048 #endif
00049 
00050 template <class _Tp, _STLP_DBG_ALLOCATOR_SELECT(_Tp) >
00051 class deque :
00052 #if !defined (__DMC__)
00053              private
00054 #endif
00055                      _STLP_PRIV __construct_checker<_STLP_NON_DBG_DEQUE >
00056 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
00057             , public __stlport_class<deque<_Tp, _Alloc> >
00058 #endif
00059 {
00060   typedef deque<_Tp,_Alloc> _Self;
00061   typedef _STLP_NON_DBG_DEQUE _Base;
00062   typedef _STLP_PRIV __construct_checker<_STLP_NON_DBG_DEQUE > _ConstructCheck;
00063 
00064 public:
00065   // Basic types
00066   __IMPORT_CONTAINER_TYPEDEFS(_Base)
00067 
00068   // Iterators
00069   typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _DbgTraits<_Nonconst_traits<value_type> > > iterator;
00070   typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _DbgTraits<_Const_traits<value_type> > >    const_iterator;
00071 
00072   _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
00073 
00074 protected:
00075   _Base _M_non_dbg_impl;
00076   _STLP_PRIV __owned_list _M_iter_list;
00077 
00078   void _Invalidate_all()
00079   { _M_iter_list._Invalidate_all(); }
00080   void _Invalidate_iterator(const iterator& __it)
00081   { _STLP_PRIV __invalidate_iterator(&_M_iter_list,__it); }
00082   void _Invalidate_iterators(const iterator& __first, const iterator& __last)
00083   { _STLP_PRIV __invalidate_range(&_M_iter_list, __first, __last); }
00084 
00085 public:
00086   // Basic accessors
00087   allocator_type get_allocator() const { return _M_non_dbg_impl.get_allocator(); }
00088 
00089   iterator begin() { return iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
00090   iterator end() { return iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
00091   const_iterator begin() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
00092   const_iterator end() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
00093 
00094   reverse_iterator rbegin() { return reverse_iterator(end()); }
00095   reverse_iterator rend() { return reverse_iterator(begin()); }
00096   const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
00097   const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
00098 
00099   reference operator[](size_type __n) {
00100     _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
00101     return _M_non_dbg_impl[__n];
00102   }
00103   const_reference operator[](size_type __n) const {
00104     _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
00105     return _M_non_dbg_impl[__n];
00106   }
00107 
00108   reference at(size_type __n) { return _M_non_dbg_impl.at(__n); }
00109   const_reference at(size_type __n) const { return _M_non_dbg_impl.at(__n); }
00110 
00111   reference front() {
00112     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
00113     return *begin();
00114   }
00115   const_reference front() const {
00116     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
00117     return *begin();
00118   }
00119   reference back() {
00120     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
00121     return *(--end());
00122   }
00123   const_reference back() const {
00124     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
00125     return *(--end());
00126   }
00127 
00128   // Constructor, destructor.
00129   explicit deque(const allocator_type& __a = allocator_type()) :
00130     _M_non_dbg_impl(__a), _M_iter_list(&_M_non_dbg_impl) {}
00131   deque(const _Self& __x) :
00132     _ConstructCheck(__x), _M_non_dbg_impl(__x._M_non_dbg_impl),
00133     _M_iter_list(&_M_non_dbg_impl) {}
00134 
00135 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
00136   explicit deque(size_type __n, const value_type& __x = _Tp(),
00137 #else
00138   deque(size_type __n, param_type __x,
00139 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
00140             const allocator_type& __a = allocator_type()) :
00141     _M_non_dbg_impl(__n, __x, __a), _M_iter_list(&_M_non_dbg_impl) {}
00142 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
00143   explicit deque(size_type __n) :
00144     _M_non_dbg_impl(__n), _M_iter_list(&_M_non_dbg_impl) {}
00145 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
00146 
00147   deque(__move_source<_Self> src)
00148     : _M_non_dbg_impl(__move_source<_Base>(src.get()._M_non_dbg_impl)),
00149       _M_iter_list(&_M_non_dbg_impl) {
00150 #if defined (_STLP_NO_EXTENSIONS) || (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
00151     src.get()._M_iter_list._Invalidate_all();
00152 #else
00153     src.get()._M_iter_list._Set_owner(_M_iter_list);
00154 #endif
00155   }
00156 
00157 #if defined (_STLP_MEMBER_TEMPLATES)
00158   template <class _InputIterator>
00159   deque(_InputIterator __first, _InputIterator __last,
00160         const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
00161     : _ConstructCheck(__first, __last),
00162       _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last), __a),
00163       _M_iter_list(&_M_non_dbg_impl) {
00164     }
00165 #  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
00166   template <class _InputIterator>
00167   deque(_InputIterator __first, _InputIterator __last)
00168     : _ConstructCheck(__first, __last),
00169       _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last)),
00170       _M_iter_list(&_M_non_dbg_impl) {
00171     }
00172 #  endif
00173 #else
00174   deque(const value_type* __first, const value_type* __last,
00175         const allocator_type& __a = allocator_type())
00176     : _ConstructCheck(__first, __last),
00177       _M_non_dbg_impl(__first, __last, __a),
00178       _M_iter_list(&_M_non_dbg_impl) {
00179     }
00180 
00181   deque(const_iterator __first, const_iterator __last,
00182         const allocator_type& __a = allocator_type())
00183     : _ConstructCheck(__first, __last),
00184       _M_non_dbg_impl(__first._M_iterator, __last._M_iterator, __a),
00185       _M_iter_list(&_M_non_dbg_impl) {
00186     }
00187 #endif
00188 
00189   _Self& operator=(const _Self& __x) {
00190     if (this != &__x) {
00191       _Invalidate_all();
00192       _M_non_dbg_impl = __x._M_non_dbg_impl;
00193     }
00194     return *this;
00195   }
00196 
00197   bool empty() const { return _M_non_dbg_impl.empty(); }
00198   size_type size() const { return _M_non_dbg_impl.size(); }
00199   size_type max_size() const { return _M_non_dbg_impl.max_size(); }
00200 
00201   void swap(_Self& __x) {
00202     _M_iter_list._Swap_owners(__x._M_iter_list);
00203     _M_non_dbg_impl.swap(__x._M_non_dbg_impl);
00204   }
00205 
00206 public:
00207   void assign(size_type __n, const _Tp& __val) {
00208     _Invalidate_all();
00209     _M_non_dbg_impl.assign(__n, __val);
00210   }
00211 
00212 #if defined (_STLP_MEMBER_TEMPLATES)
00213   template <class _InputIterator>
00214   void assign(_InputIterator __first, _InputIterator __last) {
00215     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00216     _Invalidate_all();
00217     _M_non_dbg_impl.assign(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
00218   }
00219 #else
00220   void assign(const_iterator __first, const_iterator __last) {
00221     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00222     _Invalidate_all();
00223     _M_non_dbg_impl.assign(__first._M_iterator, __last._M_iterator);
00224   }
00225   void assign(const value_type *__first, const value_type *__last) {
00226     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first, __last))
00227     _Invalidate_all();
00228     _M_non_dbg_impl.assign(__first, __last);
00229   }
00230 #endif
00231 
00232 public:                         // push_* and pop_*
00233 
00234 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
00235   void push_back(const value_type& __t = _Tp()) {
00236 #else
00237   void push_back(const value_type& __t) {
00238 #endif 
00239     _Invalidate_all();
00240     _M_non_dbg_impl.push_back(__t);
00241   }
00242 
00243 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
00244   void push_back() {
00245     _Invalidate_all();
00246     _M_non_dbg_impl.push_back();
00247   }
00248 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
00249 
00250 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
00251   void push_front(const value_type& __t = _Tp()) {
00252 #else
00253   void push_front(const value_type& __t) {
00254 #endif 
00255     _Invalidate_all();
00256     _M_non_dbg_impl.push_front(__t);
00257   }
00258 
00259 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
00260   void push_front() {
00261     _Invalidate_all();
00262     _M_non_dbg_impl.push_front();
00263   }
00264 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
00265 
00266   void pop_back() {
00267     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
00268     _Invalidate_iterator(end());
00269     _M_non_dbg_impl.pop_back();
00270   }
00271 
00272   void pop_front() {
00273     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
00274     _Invalidate_iterator(begin());
00275     _M_non_dbg_impl.pop_front();
00276   }
00277 
00278 public:                         // Insert
00279 
00280 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
00281   iterator insert(iterator __pos, const value_type& __x = _Tp()) {
00282 #else
00283   iterator insert(iterator __pos, const value_type& __x) {
00284 #endif 
00285     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
00286     _Invalidate_all();
00287     return iterator(&_M_iter_list, _M_non_dbg_impl.insert(__pos._M_iterator, __x));
00288   }
00289 
00290 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
00291   iterator insert(iterator __pos) {
00292     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
00293     _Invalidate_all();
00294     return iterator(&_M_iter_list, _M_non_dbg_impl.insert(__pos._M_iterator));
00295   }
00296 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
00297 
00298   void insert(iterator __pos, size_type __n, const value_type& __x) {
00299     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
00300     if (__n != 0) _Invalidate_all();
00301     _M_non_dbg_impl.insert(__pos._M_iterator, __n, __x);
00302   }
00303 
00304 #if defined (_STLP_MEMBER_TEMPLATES)
00305   template <class _InputIterator>
00306   void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
00307     typedef typename _AreSameUnCVTypes<_InputIterator, iterator>::_Ret _IsNonConstIterator;
00308     typedef typename _AreSameUnCVTypes<_InputIterator, const_iterator>::_Ret _IsConstIterator;
00309     typedef typename _Lor2<_IsNonConstIterator, _IsConstIterator>::_Ret _DoCheck;
00310     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
00311     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00312     //Sequence requirements 23.1.1 Table 67:
00313     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first, _DoCheck()));
00314     _M_non_dbg_impl.insert(__pos._M_iterator,
00315                            _STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
00316     //dums: because of self insertion iterators must be invalidated after insertion.
00317     if (__first != __last) _Invalidate_all();
00318   }
00319 #else
00320   void insert(iterator __pos,
00321               const value_type* __first, const value_type* __last) {
00322     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
00323     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first, __last))
00324     _M_non_dbg_impl.insert(__pos._M_iterator, __first, __last);
00325     //dums: because of self insertion iterators must be invalidated after insertion.
00326     if (__first != __last) _Invalidate_all();
00327   }
00328   void insert(iterator __pos,
00329               const_iterator __first, const_iterator __last) {
00330     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
00331     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
00332     //Sequence requirements 23.1.1 Table 67:
00333     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first, __true_type()));
00334     _M_non_dbg_impl.insert(__pos._M_iterator, __first._M_iterator, __last._M_iterator);
00335     //dums: because of self insertion iterators must be invalidated after insertion.
00336     if (__first != __last) _Invalidate_all();
00337   }
00338 #endif
00339 
00340 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
00341   void resize(size_type __new_size, const value_type& __x = _Tp()) {
00342 #else
00343   void resize(size_type __new_size, const value_type& __x) {
00344 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
00345     if (__new_size != size()) {
00346       if ((__new_size > size()) || (__new_size < size() - 1))
00347         _Invalidate_all();
00348       else
00349         _Invalidate_iterator(end());
00350     }
00351     _M_non_dbg_impl.resize(__new_size, __x);
00352   }
00353 
00354 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
00355   void resize(size_type new_size) { resize(new_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
00356 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
00357 
00358   // Erase
00359   iterator erase(iterator __pos) {
00360     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
00361     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
00362     if (__pos._M_iterator == _M_non_dbg_impl.begin())
00363       _Invalidate_iterator(__pos);
00364     else {
00365       typename _Base::iterator __tmp = --(_M_non_dbg_impl.end());
00366       if (__pos._M_iterator == __tmp)
00367         _Invalidate_iterator(__pos);
00368       else
00369         _Invalidate_all();
00370     }
00371     return iterator (&_M_iter_list, _M_non_dbg_impl.erase(__pos._M_iterator));
00372   }
00373 
00374   iterator erase(iterator __first, iterator __last) {
00375     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last, begin(), end()))
00376     if (!empty()) {
00377       if (__first._M_iterator == _M_non_dbg_impl.begin() ||
00378           __last._M_iterator == _M_non_dbg_impl.end())
00379         _Invalidate_iterators(__first, __last);
00380       else
00381         _Invalidate_all();
00382     }
00383     return iterator (&_M_iter_list, _M_non_dbg_impl.erase(__first._M_iterator, __last._M_iterator));
00384   }
00385 
00386   void clear() {
00387     _Invalidate_all();
00388     _M_non_dbg_impl.clear();
00389   }
00390 };
00391 
00392 _STLP_END_NAMESPACE
00393 
00394 #undef _STLP_NON_DBG_DEQUE
00395 
00396 #endif /* _STLP_INTERNAL_DEQUE_H */
00397 
00398 // Local Variables:
00399 // mode:C++
00400 // End:



Generated on Mon Mar 10 15:32:21 2008 by  doxygen 1.5.1