/home/ntakagi/work/STLport-5.1.5/stlport/stl/pointers/_deque.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004
00003  * Francois Dumont
00004  *
00005  * This material is provided "as is", with absolutely no warranty expressed
00006  * or implied. Any use is at your own risk.
00007  *
00008  * Permission to use or copy this software for any purpose is hereby granted
00009  * without fee, provided the above notices are retained on all copies.
00010  * Permission to modify the code and to distribute modified code is granted,
00011  * provided the above notices are retained, and a notice that the code was
00012  * modified is included with the above copyright notice.
00013  *
00014  */
00015 
00016 /* NOTE: This is an internal header file, included by other STL headers.
00017  *   You should not attempt to use it directly.
00018  */
00019 
00020 #ifndef _STLP_SPECIALIZED_DEQUE_H
00021 #define _STLP_SPECIALIZED_DEQUE_H
00022 
00023 #ifndef _STLP_POINTERS_SPEC_TOOLS_H
00024 #  include <stl/pointers/_tools.h>
00025 #endif
00026 
00027 _STLP_BEGIN_NAMESPACE
00028 _STLP_MOVE_TO_PRIV_NAMESPACE
00029 
00030 /*
00031  * struct helper to cast deque iterators:
00032  */
00033 template <class _StorageT, class _ValueT>
00034 struct _DequeIteCast {
00035   typedef _Deque_iterator<_ValueT, _Nonconst_traits<_ValueT> > iterator;
00036   typedef _Deque_iterator<_ValueT, _Const_traits<_ValueT> >    const_iterator;
00037   typedef _Deque_iterator<_StorageT, _Nonconst_traits<_StorageT> > storage_iterator;
00038   typedef _Deque_iterator<_StorageT, _Const_traits<_StorageT> > const_storage_iterator;
00039   typedef _CastTraits<_StorageT, _ValueT> cast_traits;
00040 
00041   static iterator to_value_type_ite (storage_iterator const& __ite) {
00042     iterator tmp;
00043     tmp._M_cur = cast_traits::to_value_type_ptr(__ite._M_cur);
00044     tmp._M_first = cast_traits::to_value_type_ptr(__ite._M_first);
00045     tmp._M_last = cast_traits::to_value_type_ptr(__ite._M_last);
00046     tmp._M_node = cast_traits::to_value_type_pptr(__ite._M_node);
00047     return tmp;
00048   }
00049   static storage_iterator to_storage_type_ite (iterator const& __ite) {
00050     storage_iterator tmp;
00051     tmp._M_cur = cast_traits::to_storage_type_ptr(__ite._M_cur);
00052     tmp._M_first = cast_traits::to_storage_type_ptr(__ite._M_first);
00053     tmp._M_last = cast_traits::to_storage_type_ptr(__ite._M_last);
00054     tmp._M_node = cast_traits::to_storage_type_pptr(__ite._M_node);
00055     return tmp;
00056   }
00057 
00058   static const_iterator to_value_type_cite (const_storage_iterator const& __ite) {
00059     const_iterator tmp;
00060     tmp._M_cur = cast_traits::to_value_type_ptr(__ite._M_cur);
00061     tmp._M_first = cast_traits::to_value_type_ptr(__ite._M_first);
00062     tmp._M_last = cast_traits::to_value_type_ptr(__ite._M_last);
00063     tmp._M_node = cast_traits::to_value_type_pptr(__ite._M_node);
00064     return tmp;
00065   }
00066 
00067   static const_storage_iterator to_storage_type_cite (const_iterator const& __ite) {
00068     const_storage_iterator tmp;
00069     tmp._M_cur = cast_traits::to_storage_type_ptr(__ite._M_cur);
00070     tmp._M_first = cast_traits::to_storage_type_ptr(__ite._M_first);
00071     tmp._M_last = cast_traits::to_storage_type_ptr(__ite._M_last);
00072     tmp._M_node = cast_traits::to_storage_type_pptr(__ite._M_node);
00073     return tmp;
00074   }
00075 };
00076 
00077 #define DEQUE_IMPL _STLP_PTR_IMPL_NAME(deque)
00078 
00079 #if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
00080 _STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<size_t, void*,  allocator<void*> >;
00081 _STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<void***, void**,  allocator<void**> >;
00082 _STLP_EXPORT template struct _STLP_CLASS_DECLSPEC _Deque_iterator<void*, _Nonconst_traits<void*> >;
00083 _STLP_EXPORT_TEMPLATE_CLASS _Deque_base<void*,allocator<void*> >;
00084 _STLP_EXPORT_TEMPLATE_CLASS DEQUE_IMPL<void*,allocator<void*> >;
00085 #endif
00086 
00087 #if defined (_STLP_DEBUG)
00088 #  define deque _STLP_NON_DBG_NAME(deque)
00089 #else
00090 _STLP_MOVE_TO_STD_NAMESPACE
00091 #endif
00092 
00093 template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) >
00094 class deque
00095 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (deque)
00096             : public __stlport_class<deque<_Tp, _Alloc> >
00097 #endif
00098 {
00099   typedef typename _STLP_PRIV _StorageType<_Tp>::_Type _StorageType;
00100   typedef typename _Alloc_traits<_StorageType, _Alloc>::allocator_type _StorageTypeAlloc;
00101   typedef _STLP_PRIV DEQUE_IMPL<_StorageType, _StorageTypeAlloc> _Base;
00102   typedef deque<_Tp, _Alloc> _Self;
00103 
00104   typedef _STLP_PRIV _CastTraits<_StorageType, _Tp> cast_traits;
00105   typedef _STLP_PRIV _DequeIteCast<_StorageType, _Tp> ite_cast_traits;
00106 
00107 public:
00108   typedef _Tp value_type;
00109   typedef value_type* pointer;
00110   typedef const value_type* const_pointer;
00111   typedef value_type& reference;
00112   typedef const value_type& const_reference;
00113   typedef size_t size_type;
00114   typedef ptrdiff_t difference_type;
00115   typedef random_access_iterator_tag _Iterator_category;
00116   _STLP_FORCE_ALLOCATORS(value_type, _Alloc)
00117   typedef typename _Alloc_traits<value_type, _Alloc>::allocator_type allocator_type;
00118   typedef _STLP_PRIV _Deque_iterator<value_type, _Nonconst_traits<value_type> > iterator;
00119   typedef _STLP_PRIV _Deque_iterator<value_type, _Const_traits<value_type> >    const_iterator;
00120 
00121   _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
00122 
00123 public:                         // Basic accessors
00124   iterator begin() { return ite_cast_traits::to_value_type_ite(_M_impl.begin()); }
00125   iterator end()   { return ite_cast_traits::to_value_type_ite(_M_impl.end()); }
00126   const_iterator begin() const { return ite_cast_traits::to_value_type_cite(_M_impl.begin()); }
00127   const_iterator end() const   { return ite_cast_traits::to_value_type_cite(_M_impl.end()); }
00128 
00129   reverse_iterator rbegin() { return reverse_iterator(end()); }
00130   reverse_iterator rend()   { return reverse_iterator(begin()); }
00131   const_reverse_iterator rbegin() const
00132   { return const_reverse_iterator(end()); }
00133   const_reverse_iterator rend() const
00134   { return const_reverse_iterator(begin()); }
00135 
00136   reference operator[](size_type __n)
00137   { return cast_traits::to_value_type_ref(_M_impl[__n]); }
00138   const_reference operator[](size_type __n) const
00139   { return cast_traits::to_value_type_cref(_M_impl[__n]); }
00140 
00141   reference at(size_type __n)
00142   { return cast_traits::to_value_type_ref(_M_impl.at(__n)); }
00143   const_reference at(size_type __n) const
00144   { return cast_traits::to_value_type_cref(_M_impl.at(__n)); }
00145 
00146   reference front() { return cast_traits::to_value_type_ref(_M_impl.front()); }
00147   reference back()  { return cast_traits::to_value_type_ref(_M_impl.back()); }
00148   const_reference front() const { return cast_traits::to_value_type_cref(_M_impl.front()); }
00149   const_reference back() const  { return cast_traits::to_value_type_cref(_M_impl.back()); }
00150 
00151   size_type size() const     { return _M_impl.size(); }
00152   size_type max_size() const { return _M_impl.max_size(); }
00153   bool empty() const         { return _M_impl.empty(); }
00154   allocator_type get_allocator() const { return _STLP_CONVERT_ALLOCATOR(_M_impl.get_allocator(), value_type); }
00155 
00156   explicit deque(const allocator_type& __a = allocator_type())
00157     : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
00158 
00159   deque(const _Self& __x) : _M_impl(__x._M_impl) {}
00160 
00161 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
00162   explicit deque(size_type __n, const value_type& __val = _STLP_DEFAULT_CONSTRUCTED(value_type),
00163 #else
00164   deque(size_type __n, const value_type& __val,
00165 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
00166         const allocator_type& __a = allocator_type())
00167     : _M_impl(__n, cast_traits::to_storage_type_cref(__val), _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
00168   // int,long variants may be needed
00169 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
00170   explicit deque(size_type __n) : _M_impl(__n) {}
00171 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
00172 
00173 #if defined (_STLP_MEMBER_TEMPLATES)
00174   template <class _InputIterator>
00175   deque(_InputIterator __first, _InputIterator __last,
00176         const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
00177 #if !defined (_STLP_USE_ITERATOR_WRAPPER)
00178   : _M_impl(__first, __last,
00179             _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {
00180 #else
00181   : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {
00182 #endif
00183 #if defined (_STLP_USE_ITERATOR_WRAPPER)
00184     insert(end(), __first, __last);
00185 #endif
00186   }
00187 
00188 #  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
00189   template <class _InputIterator>
00190   deque(_InputIterator __first, _InputIterator __last)
00191 #    if !defined (_STLP_USE_ITERATOR_WRAPPER)
00192     : _M_impl(__first, __last) {}
00193 #    else
00194   { insert(end(), __first, __last); }
00195 #    endif
00196 #  endif
00197 
00198 #else
00199   deque(const_pointer __first, const_pointer __last,
00200         const allocator_type& __a = allocator_type() )
00201     : _M_impl(cast_traits::to_storage_type_cptr(__first),
00202               cast_traits::to_storage_type_cptr(__last),
00203               _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
00204 
00205   deque(const_iterator __first, const_iterator __last,
00206         const allocator_type& __a = allocator_type() )
00207     : _M_impl(ite_cast_traits::to_storage_type_cite(__first),
00208               ite_cast_traits::to_storage_type_cite(__last),
00209               _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
00210 #endif /* _STLP_MEMBER_TEMPLATES */
00211 
00212   deque(__move_source<_Self> src)
00213     : _M_impl(__move_source<_Base>(src.get()._M_impl)) {}
00214 
00215   _Self& operator= (const _Self& __x) { _M_impl = __x._M_impl; return *this; }
00216 
00217   void swap(_Self& __x) { _M_impl.swap(__x._M_impl); }
00218 
00219   void assign(size_type __n, const value_type& __val) {
00220     _M_impl.assign(__n, cast_traits::to_storage_type_cref(__val));
00221   }
00222 
00223 #if defined (_STLP_MEMBER_TEMPLATES)
00224 #  if defined (_STLP_USE_ITERATOR_WRAPPER)
00225 private:
00226   template <class _Integer>
00227   void _M_assign_dispatch(_Integer __n, _Integer __val,
00228                           const __true_type&)
00229   { _M_impl.assign(__n, __val); }
00230 
00231   template <class _InputIterator>
00232   void _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
00233                           const __false_type&) {
00234     _M_impl.assign(typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first),
00235                    typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last));
00236   }
00237 
00238 public:
00239 #  endif
00240   template <class _InputIterator>
00241   void assign(_InputIterator __first, _InputIterator __last) {
00242 #  if defined (_STLP_USE_ITERATOR_WRAPPER)
00243     typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
00244     _M_assign_dispatch(__first, __last, _Integral());
00245 #  else
00246     _M_impl.assign(__first, __last);
00247 #  endif
00248   }
00249 #else
00250   void assign(const_pointer __first, const_pointer __last)
00251   { _M_impl.assign(cast_traits::to_storage_type_cptr(__first),
00252                    cast_traits::to_storage_type_cptr(__last)); }
00253   void assign(const_iterator __first, const_iterator __last)
00254   { _M_impl.assign(ite_cast_traits::to_storage_type_cite(__first),
00255                    ite_cast_traits::to_storage_type_cite(__last)); }
00256 #endif /* _STLP_MEMBER_TEMPLATES */
00257 
00258 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
00259   void push_back(const value_type& __t = _STLP_DEFAULT_CONSTRUCTED(value_type))
00260 #else
00261   void push_back(const value_type& __t)
00262 #endif 
00263   { _M_impl.push_back(cast_traits::to_storage_type_cref(__t)); }
00264 
00265 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
00266   void push_front(const value_type& __t = _STLP_DEFAULT_CONSTRUCTED(value_type))
00267 #else
00268   void push_front(const value_type& __t)
00269 #endif 
00270   { _M_impl.push_front(cast_traits::to_storage_type_cref(__t)); }
00271 
00272 # if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
00273   void push_back()  { _M_impl.push_back(); }
00274   void push_front() { _M_impl.push_front(); }
00275 # endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
00276 
00277   void pop_back()  { _M_impl.pop_back(); }
00278   void pop_front() { _M_impl.pop_front(); }
00279 
00280 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
00281   iterator insert(iterator __pos, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
00282 #else
00283   iterator insert(iterator __pos, const value_type& __x)
00284 #endif 
00285   { return ite_cast_traits::to_value_type_ite(_M_impl.insert(ite_cast_traits::to_storage_type_ite(__pos),
00286                                                              cast_traits::to_storage_type_cref(__x))); }
00287 
00288 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
00289   iterator insert(iterator __pos) { return insert(__pos, _STLP_DEFAULT_CONSTRUCTED(value_type)); }
00290 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
00291 
00292   void insert(iterator __pos, size_type __n, const value_type& __x)
00293   { _M_impl.insert(ite_cast_traits::to_storage_type_ite(__pos), __n, cast_traits::to_storage_type_cref(__x)); }
00294 
00295 #if defined (_STLP_MEMBER_TEMPLATES)
00296 #  if defined (_STLP_USE_ITERATOR_WRAPPER)
00297 private:
00298   template <class _Integer>
00299   void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
00300                           const __true_type&) {
00301     _M_impl.insert(ite_cast_traits::to_storage_type_ite(__pos), __n, __val);
00302   }
00303 
00304   template <class _InputIterator>
00305   void _M_insert_dispatch(iterator __pos,
00306                           _InputIterator __first, _InputIterator __last,
00307                           const __false_type&) {
00308     _M_impl.insert(ite_cast_traits::to_storage_type_ite(__pos),
00309                    typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first),
00310                    typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last));
00311   }
00312 
00313 public:
00314 #  endif
00315 
00316   template <class _InputIterator>
00317   void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
00318 #  if defined (_STLP_USE_ITERATOR_WRAPPER)
00319     // Check whether it's an integral type.  If so, it's not an iterator.
00320     typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
00321     _M_insert_dispatch(__pos, __first, __last, _Integral());
00322 #  else
00323     _M_impl.insert(ite_cast_traits::to_storage_type_ite(__pos), __first, __last);
00324 #  endif
00325   }
00326 
00327 #else /* _STLP_MEMBER_TEMPLATES */
00328   void insert(iterator __pos,
00329               const_pointer __first, const_pointer __last) {
00330     _M_impl.insert(ite_cast_traits::to_storage_type_ite(__pos),
00331                    cast_traits::to_storage_type_cptr(__first),
00332                    cast_traits::to_storage_type_cptr(__last));
00333   }
00334   void insert(iterator __pos,
00335               const_iterator __first, const_iterator __last) {
00336     _M_impl.insert(ite_cast_traits::to_storage_type_ite(__pos),
00337                    ite_cast_traits::to_storage_type_cite(__first),
00338                    ite_cast_traits::to_storage_type_cite(__last));
00339   }
00340 
00341 #endif /* _STLP_MEMBER_TEMPLATES */
00342 
00343 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
00344   void resize(size_type __new_size, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
00345 #else
00346   void resize(size_type __new_size, const value_type& __x)
00347 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
00348   { _M_impl.resize(__new_size, cast_traits::to_storage_type_cref(__x)); }
00349 
00350 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
00351   void resize(size_type __new_size) { _M_impl.resize(__new_size); }
00352 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
00353 
00354   iterator erase(iterator __pos)
00355   { return ite_cast_traits::to_value_type_ite(_M_impl.erase(ite_cast_traits::to_storage_type_ite(__pos))); }
00356 
00357   iterator erase(iterator __first, iterator __last)
00358   { return ite_cast_traits::to_value_type_ite(_M_impl.erase(ite_cast_traits::to_storage_type_ite(__first),
00359                                                             ite_cast_traits::to_storage_type_ite(__last))); }
00360   void clear() { _M_impl.clear(); }
00361 
00362 private:
00363   _Base _M_impl;
00364 };
00365 
00366 #if defined (deque)
00367 #  undef deque
00368 _STLP_MOVE_TO_STD_NAMESPACE
00369 #endif
00370 
00371 #undef DEQUE_IMPL
00372 
00373 _STLP_END_NAMESPACE
00374 
00375 #endif /* _STLP_SPECIALIZED_DEQUE_H */
00376 
00377 // Local Variables:
00378 // mode:C++
00379 // End:



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