166 typedef cx_list_s *CxList; |
175 typedef cx_list_s *CxList; |
167 |
176 |
168 /** |
177 /** |
169 * Adds an item to the end of the list. |
178 * Adds an item to the end of the list. |
170 * |
179 * |
171 * \remark It is implementation defined whether |
|
172 * the contents of the element are copied or the |
|
173 * pointer is added to the list. In the latter case |
|
174 * the \c itemsize of the list SHALL be \c sizeof(void*). |
|
175 * |
|
176 * @param list the list |
180 * @param list the list |
177 * @param elem a pointer to the element to add |
181 * @param elem a pointer to the element to add |
178 * @return zero on success, non-zero on memory allocation failure |
182 * @return zero on success, non-zero on memory allocation failure |
179 */ |
183 */ |
180 static inline int cxListAdd( |
184 static inline int cxListAdd( |
186 |
190 |
187 /** |
191 /** |
188 * Inserts an item at the specified index. |
192 * Inserts an item at the specified index. |
189 * |
193 * |
190 * If \p index equals the list \c size, this is effectively cxListAdd(). |
194 * If \p index equals the list \c size, this is effectively cxListAdd(). |
191 * |
|
192 * \remark It is implementation defined whether |
|
193 * the contents of the element are copied or the |
|
194 * pointer is added to the list. In the latter case |
|
195 * the \c itemsize of the list SHALL be \c sizeof(void*). |
|
196 * |
195 * |
197 * @param list the list |
196 * @param list the list |
198 * @param index the index the element shall have |
197 * @param index the index the element shall have |
199 * @param elem a pointer to the element to add |
198 * @param elem a pointer to the element to add |
200 * @return zero on success, non-zero on memory allocation failure |
199 * @return zero on success, non-zero on memory allocation failure |
201 * or when the index is out of bounds |
200 * or when the index is out of bounds |
|
201 * @see cxListInsertAfter() |
|
202 * @see cxListInsertBefore() |
202 */ |
203 */ |
203 static inline int cxListInsert( |
204 static inline int cxListInsert( |
204 CxList list, |
205 CxList list, |
205 size_t index, |
206 size_t index, |
206 void const *elem |
207 void const *elem |
207 ) { |
208 ) { |
208 return list->cl->insert(list, index, elem); |
209 return list->cl->insert(list, index, elem); |
|
210 } |
|
211 |
|
212 /** |
|
213 * Inserts an element after the current location of the specified iterator. |
|
214 * |
|
215 * The used iterator remains operational, but all other active iterators should |
|
216 * be considered invalidated. |
|
217 * |
|
218 * If \p iter is not a list iterator, the behavior is undefined. |
|
219 * If \p iter is a past-the-end iterator, the new element gets appended to the list. |
|
220 * |
|
221 * @param iter an iterator |
|
222 * @param elem the element to insert |
|
223 * @return zero on success, non-zero on memory allocation failure |
|
224 * @see cxListInsert() |
|
225 * @see cxListInsertBefore() |
|
226 */ |
|
227 static inline int cxListInsertAfter( |
|
228 CxIterator *iter, |
|
229 void const *elem |
|
230 ) { |
|
231 return ((cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 0); |
|
232 } |
|
233 |
|
234 /** |
|
235 * Inserts an element before the current location of the specified iterator. |
|
236 * |
|
237 * The used iterator remains operational, but all other active iterators should |
|
238 * be considered invalidated. |
|
239 * |
|
240 * If \p iter is not a list iterator, the behavior is undefined. |
|
241 * If \p iter is a past-the-end iterator, the new element gets appended to the list. |
|
242 * |
|
243 * @param iter an iterator |
|
244 * @param elem the element to insert |
|
245 * @return zero on success, non-zero on memory allocation failure |
|
246 * @see cxListInsert() |
|
247 * @see cxListInsertAfter() |
|
248 */ |
|
249 static inline int cxListInsertBefore( |
|
250 CxIterator *iter, |
|
251 void const *elem |
|
252 ) { |
|
253 return ((cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 1); |
209 } |
254 } |
210 |
255 |
211 /** |
256 /** |
212 * Removes the element at the specified index. |
257 * Removes the element at the specified index. |
213 * @param list the list |
258 * @param list the list |