Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygen_vector.c
Go to the documentation of this file.
00001 /* 00002 * 00003 * 00004 * Copyright (c) 1994 00005 * Hewlett-Packard Company 00006 * 00007 * Copyright (c) 1996,1997 00008 * Silicon Graphics Computer Systems, Inc. 00009 * 00010 * Copyright (c) 1997 00011 * Moscow Center for SPARC Technology 00012 * 00013 * Copyright (c) 1999 00014 * Boris Fomitchev 00015 * 00016 * This material is provided "as is", with absolutely no warranty expressed 00017 * or implied. Any use is at your own risk. 00018 * 00019 * Permission to use or copy this software for any purpose is hereby granted 00020 * without fee, provided the above notices are retained on all copies. 00021 * Permission to modify the code and to distribute modified code is granted, 00022 * provided the above notices are retained, and a notice that the code was 00023 * modified is included with the above copyright notice. 00024 * 00025 */ 00026 #ifndef _STLP_VECTOR_C 00027 #define _STLP_VECTOR_C 00028 00029 #if !defined (_STLP_INTERNAL_VECTOR_H) 00030 # include <stl/_vector.h> 00031 #endif 00032 00033 #include <stl/_range_errors.h> 00034 00035 _STLP_BEGIN_NAMESPACE 00036 00037 _STLP_MOVE_TO_PRIV_NAMESPACE 00038 00039 template <class _Tp, class _Alloc> 00040 void _Vector_base<_Tp,_Alloc>::_M_throw_length_error() const 00041 { __stl_throw_length_error("vector"); } 00042 00043 template <class _Tp, class _Alloc> 00044 void _Vector_base<_Tp, _Alloc>::_M_throw_out_of_range() const 00045 { __stl_throw_out_of_range("vector"); } 00046 00047 #if defined (_STLP_USE_PTR_SPECIALIZATIONS) 00048 # define vector _STLP_PTR_IMPL_NAME(vector) 00049 #elif defined (_STLP_DEBUG) 00050 # define vector _STLP_NON_DBG_NAME(vector) 00051 #else 00052 _STLP_MOVE_TO_STD_NAMESPACE 00053 #endif 00054 00055 #if defined (_STLP_NESTED_TYPE_PARAM_BUG) 00056 # define __iterator__ _Tp* 00057 #else 00058 # define __iterator__ _STLP_TYPENAME_ON_RETURN_TYPE vector<_Tp, _Alloc>::iterator 00059 #endif 00060 00061 template <class _Tp, class _Alloc> 00062 void vector<_Tp, _Alloc>::reserve(size_type __n) { 00063 if (capacity() < __n) { 00064 if (max_size() < __n) { 00065 this->_M_throw_length_error(); 00066 } 00067 00068 const size_type __old_size = size(); 00069 pointer __tmp; 00070 if (this->_M_start) { 00071 __tmp = _M_allocate_and_copy(__n, this->_M_start, this->_M_finish); 00072 _M_clear(); 00073 } else { 00074 __tmp = this->_M_end_of_storage.allocate(__n, __n); 00075 } 00076 _M_set(__tmp, __tmp + __old_size, __tmp + __n); 00077 } 00078 } 00079 00080 template <class _Tp, class _Alloc> 00081 void vector<_Tp, _Alloc>::_M_insert_overflow_aux(pointer __pos, const _Tp& __x, const __false_type& /*DO NOT USE!!*/, 00082 size_type __fill_len, bool __atend ) { 00083 typedef typename __type_traits<_Tp>::has_trivial_copy_constructor _TrivialUCopy; 00084 #if !defined (_STLP_NO_MOVE_SEMANTIC) 00085 typedef typename __move_traits<_Tp>::implemented _Movable; 00086 #endif 00087 size_type __len = _M_compute_next_size(__fill_len); 00088 pointer __new_start = this->_M_end_of_storage.allocate(__len, __len); 00089 pointer __new_finish = __new_start; 00090 _STLP_TRY { 00091 __new_finish = _STLP_PRIV __uninitialized_move(this->_M_start, __pos, __new_start, _TrivialUCopy(), _Movable()); 00092 // handle insertion 00093 if (__fill_len == 1) { 00094 _Copy_Construct(__new_finish, __x); 00095 ++__new_finish; 00096 } else 00097 __new_finish = _STLP_PRIV __uninitialized_fill_n(__new_finish, __fill_len, __x); 00098 if (!__atend) 00099 __new_finish = _STLP_PRIV __uninitialized_move(__pos, this->_M_finish, __new_finish, _TrivialUCopy(), _Movable()); // copy remainder 00100 } 00101 _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish), 00102 this->_M_end_of_storage.deallocate(__new_start,__len))) 00103 _M_clear_after_move(); 00104 _M_set(__new_start, __new_finish, __new_start + __len); 00105 } 00106 00107 template <class _Tp, class _Alloc> 00108 void vector<_Tp, _Alloc>::_M_insert_overflow(pointer __pos, const _Tp& __x, const __true_type& /*_TrivialCopy*/, 00109 size_type __fill_len, bool __atend ) { 00110 size_type __len = _M_compute_next_size(__fill_len); 00111 pointer __new_start = this->_M_end_of_storage.allocate(__len, __len); 00112 pointer __new_finish = __STATIC_CAST(pointer, _STLP_PRIV __copy_trivial(this->_M_start, __pos, __new_start)); 00113 // handle insertion 00114 __new_finish = _STLP_PRIV __fill_n(__new_finish, __fill_len, __x); 00115 if (!__atend) 00116 __new_finish = __STATIC_CAST(pointer, _STLP_PRIV __copy_trivial(__pos, this->_M_finish, __new_finish)); // copy remainder 00117 _M_clear(); 00118 _M_set(__new_start, __new_finish, __new_start + __len); 00119 } 00120 00121 template <class _Tp, class _Alloc> 00122 void vector<_Tp, _Alloc>::_M_fill_insert_aux(iterator __pos, size_type __n, 00123 const _Tp& __x, const __true_type& /*_Movable*/) { 00124 if (_M_is_inside(__x)) { 00125 _Tp __x_copy = __x; 00126 _M_fill_insert_aux(__pos, __n, __x_copy, __true_type()); 00127 return; 00128 } 00129 iterator __src = this->_M_finish - 1; 00130 iterator __dst = __src + __n; 00131 for (; __src >= __pos; --__dst, --__src) { 00132 _STLP_STD::_Move_Construct(__dst, *__src); 00133 _STLP_STD::_Destroy_Moved(__src); 00134 } 00135 _STLP_PRIV __uninitialized_fill_n(__pos, __n, __x); 00136 this->_M_finish += __n; 00137 } 00138 00139 template <class _Tp, class _Alloc> 00140 void vector<_Tp, _Alloc>::_M_fill_insert_aux (iterator __pos, size_type __n, 00141 const _Tp& __x, const __false_type& /*_Movable*/) { 00142 typedef typename __type_traits<_Tp>::has_trivial_copy_constructor _TrivialUCopy; 00143 typedef typename __type_traits<_Tp>::has_trivial_assignment_operator _TrivialCopy; 00144 //Here self referencing needs to be checked even for non movable types. 00145 if (_M_is_inside(__x)) { 00146 _Tp __x_copy = __x; 00147 _M_fill_insert_aux(__pos, __n, __x_copy, __false_type()); 00148 return; 00149 } 00150 const size_type __elems_after = this->_M_finish - __pos; 00151 pointer __old_finish = this->_M_finish; 00152 if (__elems_after > __n) { 00153 _STLP_PRIV __ucopy_ptrs(this->_M_finish - __n, this->_M_finish, this->_M_finish, _TrivialUCopy()); 00154 this->_M_finish += __n; 00155 _STLP_PRIV __copy_backward_ptrs(__pos, __old_finish - __n, __old_finish, _TrivialCopy()); 00156 _STLP_STD::fill(__pos, __pos + __n, __x); 00157 } else { 00158 this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_finish, __n - __elems_after, __x); 00159 _STLP_PRIV __ucopy_ptrs(__pos, __old_finish, this->_M_finish, _TrivialUCopy()); 00160 this->_M_finish += __elems_after; 00161 _STLP_STD::fill(__pos, __old_finish, __x); 00162 } 00163 } 00164 00165 template <class _Tp, class _Alloc> 00166 void vector<_Tp, _Alloc>::_M_fill_insert(iterator __pos, 00167 size_type __n, const _Tp& __x) { 00168 #if !defined (_STLP_NO_MOVE_SEMANTIC) 00169 typedef typename __move_traits<_Tp>::implemented _Movable; 00170 #endif 00171 if (__n != 0) { 00172 if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n) { 00173 _M_fill_insert_aux(__pos, __n, __x, _Movable()); 00174 } else { 00175 typedef typename __type_traits<_Tp>::has_trivial_assignment_operator _TrivialCopy; 00176 _M_insert_overflow(__pos, __x, _TrivialCopy(), __n); 00177 } 00178 } 00179 } 00180 00181 template <class _Tp, class _Alloc> 00182 vector<_Tp, _Alloc>& vector<_Tp, _Alloc>::operator = (const vector<_Tp, _Alloc>& __x) { 00183 typedef typename __type_traits<_Tp>::has_trivial_assignment_operator _TrivialCopy; 00184 typedef typename __type_traits<_Tp>::has_trivial_copy_constructor _TrivialUCopy; 00185 if (&__x != this) { 00186 const size_type __xlen = __x.size(); 00187 if (__xlen > capacity()) { 00188 size_type __len = __xlen; 00189 pointer __tmp = _M_allocate_and_copy(__len, __CONST_CAST(const_pointer, __x._M_start) + 0, 00190 __CONST_CAST(const_pointer, __x._M_finish) + 0); 00191 _M_clear(); 00192 this->_M_start = __tmp; 00193 this->_M_end_of_storage._M_data = this->_M_start + __len; 00194 } else if (size() >= __xlen) { 00195 pointer __i = _STLP_PRIV __copy_ptrs(__CONST_CAST(const_pointer, __x._M_start) + 0, 00196 __CONST_CAST(const_pointer, __x._M_finish) + 0, this->_M_start, _TrivialCopy()); 00197 _STLP_STD::_Destroy_Range(__i, this->_M_finish); 00198 } else { 00199 _STLP_PRIV __copy_ptrs(__CONST_CAST(const_pointer, __x._M_start), 00200 __CONST_CAST(const_pointer, __x._M_start) + size(), this->_M_start, _TrivialCopy()); 00201 _STLP_PRIV __ucopy_ptrs(__CONST_CAST(const_pointer, __x._M_start) + size(), 00202 __CONST_CAST(const_pointer, __x._M_finish) + 0, this->_M_finish, _TrivialUCopy()); 00203 } 00204 this->_M_finish = this->_M_start + __xlen; 00205 } 00206 return *this; 00207 } 00208 00209 template <class _Tp, class _Alloc> 00210 void vector<_Tp, _Alloc>::_M_fill_assign(size_t __n, const _Tp& __val) { 00211 if (__n > capacity()) { 00212 vector<_Tp, _Alloc> __tmp(__n, __val, get_allocator()); 00213 __tmp.swap(*this); 00214 } else if (__n > size()) { 00215 fill(begin(), end(), __val); 00216 this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_finish, __n - size(), __val); 00217 } else 00218 erase(_STLP_PRIV __fill_n(begin(), __n, __val), end()); 00219 } 00220 00221 template <class _Tp, class _Alloc> 00222 __iterator__ 00223 vector<_Tp, _Alloc>::insert(iterator __pos, const _Tp& __x) { 00224 size_type __n = __pos - begin(); 00225 _M_fill_insert(__pos, 1, __x); 00226 return begin() + __n; 00227 } 00228 00229 #undef __iterator__ 00230 00231 #if defined (vector) 00232 # undef vector 00233 _STLP_MOVE_TO_STD_NAMESPACE 00234 #endif 00235 00236 _STLP_END_NAMESPACE 00237 00238 #endif /* _STLP_VECTOR_C */ 00239 00240 // Local Variables: 00241 // mode:C++ 00242 // End: Generated on Sun May 27 2012 04:29:44 for ReactOS by
1.7.6.1
|