• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2003
3  * Francois Dumont
4  *
5  * This material is provided "as is", with absolutely no warranty expressed
6  * or implied. Any use is at your own risk.
7  *
8  * Permission to use or copy this software for any purpose is hereby granted
9  * without fee, provided the above notices are retained on all copies.
10  * Permission to modify the code and to distribute modified code is granted,
11  * provided the above notices are retained, and a notice that the code was
12  * modified is included with the above copyright notice.
13  *
14  */
15 
16 /* NOTE: This is an internal header file, included by other STL headers.
17  *   You should not attempt to use it directly.
18  */
19 
20 #ifndef _STLP_SPECIALIZED_VECTOR_H
21 #define _STLP_SPECIALIZED_VECTOR_H
22 
23 #ifndef _STLP_POINTERS_SPEC_TOOLS_H
24 #  include <stl/pointers/_tools.h>
25 #endif
26 
27 _STLP_BEGIN_NAMESPACE
28 
29 #define VECTOR_IMPL _STLP_PTR_IMPL_NAME(vector)
30 
31 #if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
32 _STLP_EXPORT_TEMPLATE_CLASS _STLP_PRIV _Vector_base<void*,allocator<void*> >;
33 _STLP_EXPORT_TEMPLATE_CLASS _STLP_PRIV VECTOR_IMPL<void*, allocator<void*> >;
34 #endif
35 
36 #if defined (_STLP_DEBUG)
37 #  define vector _STLP_NON_DBG_NAME(vector)
38 _STLP_MOVE_TO_PRIV_NAMESPACE
39 #endif
40 
41 template <class _Tp, _STLP_DFL_TMPL_PARAM(_Alloc, allocator<_Tp>) >
42 class vector
43 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (vector)
44              : public __stlport_class<vector<_Tp, _Alloc> >
45 #endif
46 {
47   /* In the vector implementation iterators are pointer which give a number
48    * of opportunities for optimization. To not break those optimizations
49    * iterators passed to template should not be wrapped for casting purpose.
50    * So vector implementation will always use a qualified void pointer type and
51    * won't use iterator wrapping.
52    */
53   typedef _STLP_TYPENAME _STLP_PRIV _StorageType<_Tp>::_QualifiedType _StorageType;
54   typedef typename _Alloc_traits<_StorageType, _Alloc>::allocator_type _StorageTypeAlloc;
55   typedef _STLP_PRIV VECTOR_IMPL<_StorageType, _StorageTypeAlloc> _Base;
56   typedef vector<_Tp, _Alloc> _Self;
57 
58   typedef _STLP_PRIV _CastTraits<_StorageType, _Tp> cast_traits;
59 
60 public:
61   typedef _Tp value_type;
62   typedef value_type* pointer;
63   typedef const value_type* const_pointer;
64   typedef value_type* iterator;
65   typedef const value_type* const_iterator;
66   typedef value_type& reference;
67   typedef const value_type& const_reference;
68   typedef size_t size_type;
69   typedef ptrdiff_t difference_type;
70   typedef random_access_iterator_tag _Iterator_category;
71 
72   _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
73   _STLP_FORCE_ALLOCATORS(value_type, _Alloc)
74   typedef typename _Alloc_traits<value_type, _Alloc>::allocator_type allocator_type;
75 
get_allocator()76   allocator_type get_allocator() const
77   { return _STLP_CONVERT_ALLOCATOR(_M_impl.get_allocator(), value_type); }
78 
begin()79   iterator begin()             { return cast_traits::to_value_type_ptr(_M_impl.begin()); }
begin()80   const_iterator begin() const { return cast_traits::to_value_type_cptr(_M_impl.begin()); }
end()81   iterator end()               { return cast_traits::to_value_type_ptr(_M_impl.end()); }
end()82   const_iterator end() const   { return cast_traits::to_value_type_cptr(_M_impl.end()); }
83 
rbegin()84   reverse_iterator rbegin()              { return reverse_iterator(end()); }
rbegin()85   const_reverse_iterator rbegin() const  { return const_reverse_iterator(end()); }
rend()86   reverse_iterator rend()                { return reverse_iterator(begin()); }
rend()87   const_reverse_iterator rend() const    { return const_reverse_iterator(begin()); }
88 
size()89   size_type size() const        { return _M_impl.size(); }
max_size()90   size_type max_size() const    { return _M_impl.max_size(); }
91 
capacity()92   size_type capacity() const    { return _M_impl.capacity(); }
empty()93   bool empty() const            { return _M_impl.empty(); }
94 
95   reference operator[](size_type __n) { return cast_traits::to_value_type_ref(_M_impl[__n]); }
96   const_reference operator[](size_type __n) const { return cast_traits::to_value_type_cref(_M_impl[__n]); }
97 
front()98   reference front()             { return cast_traits::to_value_type_ref(_M_impl.front()); }
front()99   const_reference front() const { return cast_traits::to_value_type_cref(_M_impl.front()); }
back()100   reference back()              { return cast_traits::to_value_type_ref(_M_impl.back()); }
back()101   const_reference back() const  { return cast_traits::to_value_type_cref(_M_impl.back()); }
102 
at(size_type __n)103   reference at(size_type __n) { return cast_traits::to_value_type_ref(_M_impl.at(__n)); }
at(size_type __n)104   const_reference at(size_type __n) const { return cast_traits::to_value_type_cref(_M_impl.at(__n)); }
105 
106   explicit vector(const allocator_type& __a = allocator_type())
_M_impl(_STLP_CONVERT_ALLOCATOR (__a,_StorageType))107     : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
108 
109 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
110   explicit vector(size_type __n, const value_type& __val = _STLP_DEFAULT_CONSTRUCTED(value_type),
111 #else
112   vector(size_type __n, const value_type& __val,
113 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
114          const allocator_type& __a = allocator_type())
_M_impl(__n,cast_traits::to_storage_type_cref (__val),_STLP_CONVERT_ALLOCATOR (__a,_StorageType))115     : _M_impl(__n, cast_traits::to_storage_type_cref(__val),
116       _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
117 
118 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
vector(size_type __n)119   explicit vector(size_type __n)
120     : _M_impl(__n, allocator_type() ) {}
121 #endif
122 
vector(const _Self & __x)123   vector(const _Self& __x)
124     : _M_impl(__x._M_impl) {}
125 
126 #if !defined (_STLP_NO_MOVE_SEMANTIC)
vector(__move_source<_Self> src)127   explicit vector(__move_source<_Self> src)
128     : _M_impl(__move_source<_Base>(src.get()._M_impl)) {}
129 #endif
130 
131 #if defined (_STLP_MEMBER_TEMPLATES)
132   template <class _InputIterator>
vector(_InputIterator __first,_InputIterator __last,const allocator_type & __a _STLP_ALLOCATOR_TYPE_DFL)133   vector(_InputIterator __first, _InputIterator __last,
134          const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL )
135   : _M_impl(__first, __last,
136             _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
137 
138 #  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
139   template <class _InputIterator>
vector(_InputIterator __first,_InputIterator __last)140   vector(_InputIterator __first, _InputIterator __last)
141     : _M_impl(__first, __last) {}
142 #  endif
143 
144 #else
145   vector(const_iterator __first, const_iterator __last,
146          const allocator_type& __a = allocator_type())
_M_impl(cast_traits::to_storage_type_cptr (__first),cast_traits::to_storage_type_cptr (__last),_STLP_CONVERT_ALLOCATOR (__a,_StorageType))147     : _M_impl(cast_traits::to_storage_type_cptr(__first), cast_traits::to_storage_type_cptr(__last),
148               _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
149 #endif /* _STLP_MEMBER_TEMPLATES */
150 
151   _Self& operator=(const _Self& __x) { _M_impl = __x._M_impl; return *this; }
152 
reserve(size_type __n)153   void reserve(size_type __n) {_M_impl.reserve(__n);}
assign(size_type __n,const value_type & __val)154   void assign(size_type __n, const value_type& __val)
155   { _M_impl.assign(__n, cast_traits::to_storage_type_cref(__val)); }
156 
157 #if defined (_STLP_MEMBER_TEMPLATES)
158   template <class _InputIterator>
assign(_InputIterator __first,_InputIterator __last)159   void assign(_InputIterator __first, _InputIterator __last)
160   { _M_impl.assign(__first, __last); }
161 #else
assign(const_iterator __first,const_iterator __last)162   void assign(const_iterator __first, const_iterator __last) {
163     _M_impl.assign(cast_traits::to_storage_type_cptr(__first),
164                    cast_traits::to_storage_type_cptr(__last));
165   }
166 #endif /* _STLP_MEMBER_TEMPLATES */
167 
168 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
169   void push_back(const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
170 #else
171   void push_back(const value_type& __x)
172 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
173   { _M_impl.push_back(cast_traits::to_storage_type_cref(__x)); }
174 
175 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
176   iterator insert(iterator __pos, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
177 #else
178   iterator insert(iterator __pos, const value_type& __x)
179 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
180   { return cast_traits::to_value_type_ptr(_M_impl.insert(cast_traits::to_storage_type_ptr(__pos),
181                                                          cast_traits::to_storage_type_cref(__x))); }
182 
183 #if defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
push_back()184   void push_back() { _M_impl.push_back(); }
insert(iterator __pos)185   iterator insert(iterator __pos)
186   { return _M_impl.insert(cast_traits::to_storage_type_ptr(__pos)); }
187 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
188 
swap(_Self & __x)189   void swap(_Self& __x) { _M_impl.swap(__x._M_impl); }
190 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
_M_swap_workaround(_Self & __x)191   void _M_swap_workaround(_Self& __x) { swap(__x); }
192 #endif
193 
194 #if defined (_STLP_MEMBER_TEMPLATES)
195   template <class _InputIterator>
insert(iterator __pos,_InputIterator __first,_InputIterator __last)196   void insert(iterator __pos, _InputIterator __first, _InputIterator __last)
197   { _M_impl.insert(cast_traits::to_storage_type_ptr(__pos), __first, __last); }
198 #else
insert(iterator __pos,const_iterator __first,const_iterator __last)199   void insert(iterator __pos, const_iterator __first, const_iterator __last) {
200     _M_impl.insert(cast_traits::to_storage_type_ptr(__pos), cast_traits::to_storage_type_cptr(__first),
201                                                             cast_traits::to_storage_type_cptr(__last));
202   }
203 #endif
204 
insert(iterator __pos,size_type __n,const value_type & __x)205   void insert (iterator __pos, size_type __n, const value_type& __x) {
206     _M_impl.insert(cast_traits::to_storage_type_ptr(__pos), __n, cast_traits::to_storage_type_cref(__x));
207   }
208 
pop_back()209   void pop_back() {_M_impl.pop_back();}
erase(iterator __pos)210   iterator erase(iterator __pos)
211   {return cast_traits::to_value_type_ptr(_M_impl.erase(cast_traits::to_storage_type_ptr(__pos)));}
erase(iterator __first,iterator __last)212   iterator erase(iterator __first, iterator __last) {
213     return cast_traits::to_value_type_ptr(_M_impl.erase(cast_traits::to_storage_type_ptr(__first),
214                                                         cast_traits::to_storage_type_ptr(__last)));
215   }
216 
217 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
218   void resize(size_type __new_size, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
219 #else
220   void resize(size_type __new_size, const value_type& __x)
221 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
222   { _M_impl.resize(__new_size, cast_traits::to_storage_type_cref(__x)); }
223 
224 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
resize(size_type __new_size)225   void resize(size_type __new_size) { _M_impl.resize(__new_size); }
226 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
227 
clear()228   void clear() { _M_impl.clear(); }
229 
230 private:
231   _Base _M_impl;
232 };
233 
234 #if defined (vector)
235 #  undef vector
236 _STLP_MOVE_TO_STD_NAMESPACE
237 #endif
238 
239 #undef VECTOR_IMPL
240 
241 _STLP_END_NAMESPACE
242 
243 #endif /* _STLP_SPECIALIZED_VECTOR_H */
244