ReactOS 0.4.15-dev-7842-g558ab78
_vector.c
Go to the documentation of this file.
1/*
2 *
3 *
4 * Copyright (c) 1994
5 * Hewlett-Packard Company
6 *
7 * Copyright (c) 1996,1997
8 * Silicon Graphics Computer Systems, Inc.
9 *
10 * Copyright (c) 1997
11 * Moscow Center for SPARC Technology
12 *
13 * Copyright (c) 1999
14 * Boris Fomitchev
15 *
16 * This material is provided "as is", with absolutely no warranty expressed
17 * or implied. Any use is at your own risk.
18 *
19 * Permission to use or copy this software for any purpose is hereby granted
20 * without fee, provided the above notices are retained on all copies.
21 * Permission to modify the code and to distribute modified code is granted,
22 * provided the above notices are retained, and a notice that the code was
23 * modified is included with the above copyright notice.
24 *
25 */
26#ifndef _STLP_VECTOR_C
27#define _STLP_VECTOR_C
28
29#if !defined (_STLP_INTERNAL_VECTOR_H)
30# include <stl/_vector.h>
31#endif
32
33#include <stl/_range_errors.h>
34
36
38
39template <class _Tp, class _Alloc>
41{ __stl_throw_length_error("vector"); }
42
43template <class _Tp, class _Alloc>
45{ __stl_throw_out_of_range("vector"); }
46
47#if defined (_STLP_USE_PTR_SPECIALIZATIONS)
48# define vector _STLP_PTR_IMPL_NAME(vector)
49#elif defined (_STLP_DEBUG)
50# define vector _STLP_NON_DBG_NAME(vector)
51#else
53#endif
54
55#if defined (_STLP_NESTED_TYPE_PARAM_BUG)
56# define __iterator__ _Tp*
57#else
58# define __iterator__ _STLP_TYPENAME_ON_RETURN_TYPE vector<_Tp, _Alloc>::iterator
59#endif
60
61template <class _Tp, class _Alloc>
63 if (capacity() < __n) {
64 if (max_size() < __n) {
65 this->_M_throw_length_error();
66 }
67
68 const size_type __old_size = size();
69 pointer __tmp;
70 if (this->_M_start) {
71 __tmp = _M_allocate_and_copy(__n, this->_M_start, this->_M_finish);
72 _M_clear();
73 } else {
74 __tmp = this->_M_end_of_storage.allocate(__n, __n);
75 }
76 _M_set(__tmp, __tmp + __old_size, __tmp + __n);
77 }
78}
79
80template <class _Tp, class _Alloc>
81void vector<_Tp, _Alloc>::_M_insert_overflow_aux(pointer __pos, const _Tp& __x, const __false_type& /*DO NOT USE!!*/,
82 size_type __fill_len, bool __atend ) {
84#if !defined (_STLP_NO_MOVE_SEMANTIC)
85 typedef typename __move_traits<_Tp>::implemented _Movable;
86#endif
87 size_type __len = _M_compute_next_size(__fill_len);
88 pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
89 pointer __new_finish = __new_start;
90 _STLP_TRY {
91 __new_finish = _STLP_PRIV __uninitialized_move(this->_M_start, __pos, __new_start, _TrivialUCopy(), _Movable());
92 // handle insertion
93 if (__fill_len == 1) {
94 _Copy_Construct(__new_finish, __x);
95 ++__new_finish;
96 } else
97 __new_finish = _STLP_PRIV __uninitialized_fill_n(__new_finish, __fill_len, __x);
98 if (!__atend)
99 __new_finish = _STLP_PRIV __uninitialized_move(__pos, this->_M_finish, __new_finish, _TrivialUCopy(), _Movable()); // copy remainder
100 }
101 _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
102 this->_M_end_of_storage.deallocate(__new_start,__len)))
103 _M_clear_after_move();
104 _M_set(__new_start, __new_finish, __new_start + __len);
105}
106
107template <class _Tp, class _Alloc>
108void vector<_Tp, _Alloc>::_M_insert_overflow(pointer __pos, const _Tp& __x, const __true_type& /*_TrivialCopy*/,
109 size_type __fill_len, bool __atend ) {
110 size_type __len = _M_compute_next_size(__fill_len);
111 pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
112 pointer __new_finish = __STATIC_CAST(pointer, _STLP_PRIV __copy_trivial(this->_M_start, __pos, __new_start));
113 // handle insertion
114 __new_finish = _STLP_PRIV __fill_n(__new_finish, __fill_len, __x);
115 if (!__atend)
116 __new_finish = __STATIC_CAST(pointer, _STLP_PRIV __copy_trivial(__pos, this->_M_finish, __new_finish)); // copy remainder
117 _M_clear();
118 _M_set(__new_start, __new_finish, __new_start + __len);
119}
120
121template <class _Tp, class _Alloc>
123 const _Tp& __x, const __true_type& /*_Movable*/) {
124 if (_M_is_inside(__x)) {
125 _Tp __x_copy = __x;
126 _M_fill_insert_aux(__pos, __n, __x_copy, __true_type());
127 return;
128 }
129 iterator __src = this->_M_finish - 1;
130 iterator __dst = __src + __n;
131 for (; __src >= __pos; --__dst, --__src) {
132 _STLP_STD::_Move_Construct(__dst, *__src);
133 _STLP_STD::_Destroy_Moved(__src);
134 }
136 this->_M_finish += __n;
137}
138
139template <class _Tp, class _Alloc>
141 const _Tp& __x, const __false_type& /*_Movable*/) {
144 //Here self referencing needs to be checked even for non movable types.
145 if (_M_is_inside(__x)) {
146 _Tp __x_copy = __x;
147 _M_fill_insert_aux(__pos, __n, __x_copy, __false_type());
148 return;
149 }
150 const size_type __elems_after = this->_M_finish - __pos;
151 pointer __old_finish = this->_M_finish;
152 if (__elems_after > __n) {
153 _STLP_PRIV __ucopy_ptrs(this->_M_finish - __n, this->_M_finish, this->_M_finish, _TrivialUCopy());
154 this->_M_finish += __n;
155 _STLP_PRIV __copy_backward_ptrs(__pos, __old_finish - __n, __old_finish, _TrivialCopy());
156 _STLP_STD::fill(__pos, __pos + __n, __x);
157 } else {
158 this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_finish, __n - __elems_after, __x);
159 _STLP_PRIV __ucopy_ptrs(__pos, __old_finish, this->_M_finish, _TrivialUCopy());
160 this->_M_finish += __elems_after;
161 _STLP_STD::fill(__pos, __old_finish, __x);
162 }
163}
165template <class _Tp, class _Alloc>
167 size_type __n, const _Tp& __x) {
168#if !defined (_STLP_NO_MOVE_SEMANTIC)
169 typedef typename __move_traits<_Tp>::implemented _Movable;
170#endif
171 if (__n != 0) {
172 if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n) {
173 _M_fill_insert_aux(__pos, __n, __x, _Movable());
174 } else {
176 _M_insert_overflow(__pos, __x, _TrivialCopy(), __n);
177 }
178 }
179}
180
181template <class _Tp, class _Alloc>
185 if (&__x != this) {
186 const size_type __xlen = __x.size();
187 if (__xlen > capacity()) {
188 size_type __len = __xlen;
189 pointer __tmp = _M_allocate_and_copy(__len, __CONST_CAST(const_pointer, __x._M_start) + 0,
190 __CONST_CAST(const_pointer, __x._M_finish) + 0);
191 _M_clear();
192 this->_M_start = __tmp;
193 this->_M_end_of_storage._M_data = this->_M_start + __len;
194 } else if (size() >= __xlen) {
196 __CONST_CAST(const_pointer, __x._M_finish) + 0, this->_M_start, _TrivialCopy());
197 _STLP_STD::_Destroy_Range(__i, this->_M_finish);
198 } else {
200 __CONST_CAST(const_pointer, __x._M_start) + size(), this->_M_start, _TrivialCopy());
202 __CONST_CAST(const_pointer, __x._M_finish) + 0, this->_M_finish, _TrivialUCopy());
203 }
204 this->_M_finish = this->_M_start + __xlen;
205 }
206 return *this;
207}
208
209template <class _Tp, class _Alloc>
211 if (__n > capacity()) {
212 vector<_Tp, _Alloc> __tmp(__n, __val, get_allocator());
213 __tmp.swap(*this);
214 } else if (__n > size()) {
215 fill(begin(), end(), __val);
216 this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_finish, __n - size(), __val);
217 } else
218 erase(_STLP_PRIV __fill_n(begin(), __n, __val), end());
219}
220
221template <class _Tp, class _Alloc>
223vector<_Tp, _Alloc>::insert(iterator __pos, const _Tp& __x) {
224 size_type __n = __pos - begin();
225 _M_fill_insert(__pos, 1, __x);
226 return begin() + __n;
227}
228
229#undef __iterator__
230
231#if defined (vector)
232# undef vector
234#endif
235
237
238#endif /* _STLP_VECTOR_C */
239
240// Local Variables:
241// mode:C++
242// End:
return __n
Definition: _algo.h:75
_STLP_MOVE_TO_STD_NAMESPACE void fill(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algobase.h:449
_STLP_MOVE_TO_PRIV_NAMESPACE _OutputIter __copy_backward_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type &)
Definition: _algobase.h:299
void * __copy_trivial(const void *__first, const void *__last, void *__result)
Definition: _algobase.h:222
_OutputIter __copy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type &)
Definition: _algobase.h:260
_STLP_INLINE_LOOP _InputIter const _Tp & __val
Definition: _algobase.h:656
_STLP_MOVE_TO_PRIV_NAMESPACE _STLP_INLINE_LOOP _OutputIter __fill_n(_OutputIter __first, _Size __n, const _Tp &__val)
Definition: _algobase.h:478
void _Copy_Construct(_Tp *__p, const _Tp &__val)
Definition: _construct.h:130
#define _STLP_PRIV
Definition: _dm.h:70
_STLP_THROW_FUNCT_SPEC _STLP_CALL __stl_throw_out_of_range(const char *__msg)
Definition: _range_errors.c:69
_STLP_THROW_FUNCT_SPEC _STLP_CALL __stl_throw_length_error(const char *__msg)
Definition: _range_errors.c:72
_OutputIter __ucopy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type &)
_ForwardIter __uninitialized_move(_InputIter __first, _InputIter __last, _ForwardIter __result, _TrivialUCpy __trivial_ucpy, const __false_type &)
_ForwardIter __uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp &__x)
#define __iterator__
Definition: _vector.c:58
static INT max_size
Definition: history.c:51
void _STLP_FUNCTION_THROWS _M_throw_length_error() const
Definition: _vector.c:40
void _STLP_FUNCTION_THROWS _M_throw_out_of_range() const
Definition: _vector.c:44
#define _STLP_UNWIND(action)
Definition: features.h:824
#define _STLP_MOVE_TO_STD_NAMESPACE
Definition: features.h:525
#define __STATIC_CAST(__x, __y)
Definition: features.h:585
#define _STLP_TRY
Definition: features.h:817
#define __CONST_CAST(__x, __y)
Definition: features.h:584
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
#define _STLP_END_NAMESPACE
Definition: features.h:503
#define _STLP_MOVE_TO_PRIV_NAMESPACE
Definition: features.h:524
GLuint GLuint end
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
GLsizei const GLvoid * pointer
Definition: glext.h:5848
void _M_fill_insert(iterator __pos, size_type __n, const _Tp &__x)
Definition: _vector.c:166
void _M_insert_overflow_aux(pointer __pos, const _Tp &__x, const __false_type &, size_type __fill_len, bool __atend)
Definition: _vector.c:81
void reserve(size_type __n)
Definition: _vector.c:62
const value_type * const_pointer
Definition: _vector.h:123
void _M_insert_overflow(pointer __pos, const _Tp &__x, const __false_type &, size_type __fill_len, bool __atend=false)
Definition: _vector.h:157
value_type * pointer
Definition: _vector.h:122
_Self & operator=(const _Self &__x)
Definition: _vector.c:182
iterator insert(iterator __pos, const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.c:223
void swap(_Self &__x)
Definition: _vector.h:404
size_type size() const
Definition: _vector.h:192
void _M_fill_insert_aux(iterator __pos, size_type __n, const _Tp &__x, const __true_type &)
Definition: _vector.c:122
size_t size_type
Definition: _vector.h:129
void _M_fill_assign(size_type __n, const _Tp &__val)
Definition: _vector.c:210
value_type * iterator
Definition: _vector.h:124
static clock_t begin
Definition: xmllint.c:458