115 * the current array \p size. If the new index plus the number of elements added |
115 * the current array \p size. If the new index plus the number of elements added |
116 * would extend the array's size, and \p capacity is not \c NULL, the remaining |
116 * would extend the array's size, and \p capacity is not \c NULL, the remaining |
117 * capacity is used. |
117 * capacity is used. |
118 * |
118 * |
119 * If the capacity is insufficient to hold the new data, a reallocation |
119 * If the capacity is insufficient to hold the new data, a reallocation |
120 * attempt is made, unless the allocator is set to \c NULL, in which case |
120 * attempt is made, unless the \p reallocator is set to \c NULL, in which case |
121 * this function ultimately returns a failure. |
121 * this function ultimately returns a failure. |
122 * |
122 * |
123 * @param target the target array |
123 * @param target the target array |
124 * @param size a pointer to the size of the target array |
124 * @param size a pointer to the size of the target array |
125 * @param capacity a pointer to the target array's capacity - |
125 * @param capacity a pointer to the target array's capacity - |
141 size_t elem_size, |
141 size_t elem_size, |
142 size_t elem_count, |
142 size_t elem_count, |
143 struct cx_array_reallocator_s *reallocator |
143 struct cx_array_reallocator_s *reallocator |
144 ) __attribute__((__nonnull__(1, 2, 5))); |
144 ) __attribute__((__nonnull__(1, 2, 5))); |
145 |
145 |
|
146 /** |
|
147 * Adds an element to an array with the possibility of allocating more space. |
|
148 * |
|
149 * The element \p elem is added to the end of the \p target array which containing |
|
150 * \p size elements, already. The \p capacity must not be \c NULL and point a |
|
151 * variable holding the current maximum number of elements the array can hold. |
|
152 * |
|
153 * If the capacity is insufficient to hold the new element, and the optional |
|
154 * \p reallocator is not \c NULL, an attempt increase the \p capacity is made |
|
155 * and the new capacity is written back. |
|
156 * |
|
157 * @param target the target array |
|
158 * @param size a pointer to the size of the target array |
|
159 * @param capacity a pointer to the target array's capacity - must not be \c NULL |
|
160 * @param elem_size the size of one element |
|
161 * @param elem the element to add |
|
162 * @param reallocator the array re-allocator to use, or \c NULL |
|
163 * if re-allocation shall not happen |
|
164 * @return zero on success, non-zero error code on failure |
|
165 */ |
|
166 #define cx_array_add(target, size, capacity, elem_size, elem, reallocator) \ |
|
167 cx_array_copy((void**)(target), size, capacity, *(size), elem, elem_size, 1, reallocator) |
146 |
168 |
147 /** |
169 /** |
148 * Swaps two array elements. |
170 * Swaps two array elements. |
149 * |
171 * |
150 * @param arr the array |
172 * @param arr the array |