/home/ntakagi/work/STLport-5.1.5/stlport/stl/pointers/_vector.hGo to the documentation of this file.00001 /* 00002 * Copyright (c) 2003 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_VECTOR_H 00021 #define _STLP_SPECIALIZED_VECTOR_H 00022 00023 #ifndef _STLP_POINTERS_SPEC_TOOLS_H 00024 # include <stl/pointers/_tools.h> 00025 #endif 00026 00027 _STLP_BEGIN_NAMESPACE 00028 00029 #define VECTOR_IMPL _STLP_PTR_IMPL_NAME(vector) 00030 00031 #if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00032 _STLP_EXPORT_TEMPLATE_CLASS _STLP_PRIV _Vector_base<void*,allocator<void*> >; 00033 _STLP_EXPORT_TEMPLATE_CLASS _STLP_PRIV VECTOR_IMPL<void*, allocator<void*> >; 00034 #endif 00035 00036 #if defined (_STLP_DEBUG) 00037 # define vector _STLP_NON_DBG_NAME(vector) 00038 _STLP_MOVE_TO_PRIV_NAMESPACE 00039 #endif 00040 00041 template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) > 00042 class vector 00043 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (vector) 00044 : public __stlport_class<vector<_Tp, _Alloc> > 00045 #endif 00046 { 00047 /* In the vector implementation iterators are pointer which give a number 00048 * of opportunities for optimization. To not break those optimizations 00049 * iterators passed to template should not be wrapped for casting purpose. 00050 * So vector implementation will always use a qualified void pointer type and 00051 * won't use iterator wrapping. 00052 */ 00053 typedef typename _STLP_PRIV _StorageType<_Tp>::_QualifiedType _StorageType; 00054 typedef typename _Alloc_traits<_StorageType, _Alloc>::allocator_type _StorageTypeAlloc; 00055 typedef _STLP_PRIV VECTOR_IMPL<_StorageType, _StorageTypeAlloc> _Base; 00056 typedef vector<_Tp, _Alloc> _Self; 00057 00058 typedef _STLP_PRIV _CastTraits<_StorageType, _Tp> cast_traits; 00059 00060 public: 00061 typedef _Tp value_type; 00062 typedef value_type* pointer; 00063 typedef const value_type* const_pointer; 00064 typedef value_type* iterator; 00065 typedef const value_type* const_iterator; 00066 typedef value_type& reference; 00067 typedef const value_type& const_reference; 00068 typedef size_t size_type; 00069 typedef ptrdiff_t difference_type; 00070 typedef random_access_iterator_tag _Iterator_category; 00071 00072 _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS; 00073 _STLP_FORCE_ALLOCATORS(value_type, _Alloc) 00074 typedef typename _Alloc_traits<value_type, _Alloc>::allocator_type allocator_type; 00075 00076 allocator_type get_allocator() const 00077 { return _STLP_CONVERT_ALLOCATOR(_M_impl.get_allocator(), value_type); } 00078 00079 iterator begin() { return cast_traits::to_value_type_ptr(_M_impl.begin()); } 00080 const_iterator begin() const { return cast_traits::to_value_type_cptr(_M_impl.begin()); } 00081 iterator end() { return cast_traits::to_value_type_ptr(_M_impl.end()); } 00082 const_iterator end() const { return cast_traits::to_value_type_cptr(_M_impl.end()); } 00083 00084 reverse_iterator rbegin() { return reverse_iterator(end()); } 00085 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } 00086 reverse_iterator rend() { return reverse_iterator(begin()); } 00087 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } 00088 00089 size_type size() const { return _M_impl.size(); } 00090 size_type max_size() const { return _M_impl.max_size(); } 00091 00092 size_type capacity() const { return _M_impl.capacity(); } 00093 bool empty() const { return _M_impl.empty(); } 00094 00095 reference operator[](size_type __n) { return cast_traits::to_value_type_ref(_M_impl[__n]); } 00096 const_reference operator[](size_type __n) const { return cast_traits::to_value_type_cref(_M_impl[__n]); } 00097 00098 reference front() { return cast_traits::to_value_type_ref(_M_impl.front()); } 00099 const_reference front() const { return cast_traits::to_value_type_cref(_M_impl.front()); } 00100 reference back() { return cast_traits::to_value_type_ref(_M_impl.back()); } 00101 const_reference back() const { return cast_traits::to_value_type_cref(_M_impl.back()); } 00102 00103 reference at(size_type __n) { return cast_traits::to_value_type_ref(_M_impl.at(__n)); } 00104 const_reference at(size_type __n) const { return cast_traits::to_value_type_cref(_M_impl.at(__n)); } 00105 00106 explicit vector(const allocator_type& __a = allocator_type()) 00107 : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {} 00108 00109 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) 00110 explicit vector(size_type __n, const value_type& __val = _STLP_DEFAULT_CONSTRUCTED(value_type), 00111 #else 00112 vector(size_type __n, const value_type& __val, 00113 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 00114 const allocator_type& __a = allocator_type()) 00115 : _M_impl(__n, cast_traits::to_storage_type_cref(__val), 00116 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {} 00117 00118 #if defined(_STLP_DONT_SUP_DFLT_PARAM) 00119 explicit vector(size_type __n) 00120 : _M_impl(__n, allocator_type() ) {} 00121 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 00122 00123 vector(const _Self& __x) 00124 : _M_impl(__x._M_impl) {} 00125 00126 explicit vector(__move_source<_Self> src) 00127 : _M_impl(__move_source<_Base>(src.get()._M_impl)) {} 00128 00129 #if defined (_STLP_MEMBER_TEMPLATES) 00130 template <class _InputIterator> 00131 vector(_InputIterator __first, _InputIterator __last, 00132 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL ) 00133 : _M_impl(__first, __last, 00134 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {} 00135 00136 # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS) 00137 template <class _InputIterator> 00138 vector(_InputIterator __first, _InputIterator __last) 00139 : _M_impl(__first, __last) {} 00140 # endif 00141 00142 #else 00143 vector(const_iterator __first, const_iterator __last, 00144 const allocator_type& __a = allocator_type()) 00145 : _M_impl(cast_traits::to_storage_type_cptr(__first), cast_traits::to_storage_type_cptr(__last), 00146 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {} 00147 #endif /* _STLP_MEMBER_TEMPLATES */ 00148 00149 _Self& operator=(const _Self& __x) { _M_impl = __x._M_impl; return *this; } 00150 00151 void reserve(size_type __n) {_M_impl.reserve(__n);} 00152 void assign(size_type __n, const value_type& __val) 00153 { _M_impl.assign(__n, cast_traits::to_storage_type_cref(__val)); } 00154 00155 #if defined (_STLP_MEMBER_TEMPLATES) 00156 template <class _InputIterator> 00157 void assign(_InputIterator __first, _InputIterator __last) 00158 { _M_impl.assign(__first, __last); } 00159 #else 00160 void assign(const_iterator __first, const_iterator __last) { 00161 _M_impl.assign(cast_traits::to_storage_type_cptr(__first), 00162 cast_traits::to_storage_type_cptr(__last)); 00163 } 00164 #endif /* _STLP_MEMBER_TEMPLATES */ 00165 00166 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS) 00167 void push_back(const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type)) 00168 #else 00169 void push_back(const value_type& __x) 00170 #endif 00171 { _M_impl.push_back(cast_traits::to_storage_type_cref(__x)); } 00172 00173 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS) 00174 iterator insert(iterator __pos, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type)) 00175 #else 00176 iterator insert(iterator __pos, const value_type& __x) 00177 #endif 00178 { return cast_traits::to_value_type_ptr(_M_impl.insert(cast_traits::to_storage_type_ptr(__pos), 00179 cast_traits::to_storage_type_cref(__x))); } 00180 00181 #if defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS) 00182 void push_back() { _M_impl.push_back(); } 00183 iterator insert(iterator __pos) 00184 { return _M_impl.insert(cast_traits::to_storage_type_ptr(__pos)); } 00185 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/ 00186 00187 void swap(_Self& __x) { _M_impl.swap(__x._M_impl); } 00188 00189 #if defined (_STLP_MEMBER_TEMPLATES) 00190 template <class _InputIterator> 00191 void insert(iterator __pos, _InputIterator __first, _InputIterator __last) 00192 { _M_impl.insert(cast_traits::to_storage_type_ptr(__pos), __first, __last); } 00193 #else 00194 void insert(iterator __pos, const_iterator __first, const_iterator __last) { 00195 _M_impl.insert(cast_traits::to_storage_type_ptr(__pos), cast_traits::to_storage_type_cptr(__first), 00196 cast_traits::to_storage_type_cptr(__last)); 00197 } 00198 #endif 00199 00200 void insert (iterator __pos, size_type __n, const value_type& __x) { 00201 _M_impl.insert(cast_traits::to_storage_type_ptr(__pos), __n, cast_traits::to_storage_type_cref(__x)); 00202 } 00203 00204 void pop_back() {_M_impl.pop_back();} 00205 iterator erase(iterator __pos) 00206 {return cast_traits::to_value_type_ptr(_M_impl.erase(cast_traits::to_storage_type_ptr(__pos)));} 00207 iterator erase(iterator __first, iterator __last) { 00208 return cast_traits::to_value_type_ptr(_M_impl.erase(cast_traits::to_storage_type_ptr(__first), 00209 cast_traits::to_storage_type_ptr(__last))); 00210 } 00211 00212 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) 00213 void resize(size_type __new_size, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type)) 00214 #else 00215 void resize(size_type __new_size, const value_type& __x) 00216 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 00217 { _M_impl.resize(__new_size, cast_traits::to_storage_type_cref(__x)); } 00218 00219 #if defined(_STLP_DONT_SUP_DFLT_PARAM) 00220 void resize(size_type __new_size) { _M_impl.resize(__new_size); } 00221 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/ 00222 00223 void clear() { _M_impl.clear(); } 00224 00225 private: 00226 _Base _M_impl; 00227 }; 00228 00229 #if defined (vector) 00230 # undef vector 00231 _STLP_MOVE_TO_STD_NAMESPACE 00232 #endif 00233 00234 #undef VECTOR_IMPL 00235 00236 _STLP_END_NAMESPACE 00237 00238 #endif /* _STLP_SPECIALIZED_VECTOR_H */
Generated on Mon Mar 10 15:32:46 2008 by ![]() |