| 300 * @par Example |
300 * @par Example |
| 301 * |
301 * |
| 302 * @code |
302 * @code |
| 303 * CxList *myCustomListCreate( |
303 * CxList *myCustomListCreate( |
| 304 * const CxAllocator *allocator, |
304 * const CxAllocator *allocator, |
| 305 * cx_compare_func comparator, |
|
| 306 * size_t elem_size |
305 * size_t elem_size |
| 307 * ) { |
306 * ) { |
| 308 * if (allocator == NULL) { |
307 * if (allocator == NULL) { |
| 309 * allocator = cxDefaultAllocator; |
308 * allocator = cxDefaultAllocator; |
| 310 * } |
309 * } |
| 312 * MyCustomList *list = cxCalloc(allocator, 1, sizeof(MyCustomList)); |
311 * MyCustomList *list = cxCalloc(allocator, 1, sizeof(MyCustomList)); |
| 313 * if (list == NULL) return NULL; |
312 * if (list == NULL) return NULL; |
| 314 * |
313 * |
| 315 * // initialize |
314 * // initialize |
| 316 * cx_list_init((CxList*)list, &my_custom_list_class, |
315 * cx_list_init((CxList*)list, &my_custom_list_class, |
| 317 * allocator, comparator, elem_size); |
316 * allocator, elem_size); |
| 318 * |
317 * |
| 319 * // ... some more custom stuff ... |
318 * // ... some more custom stuff ... |
| 320 * |
319 * |
| 321 * return (CxList *) list; |
320 * return (CxList *) list; |
| 322 * } |
321 * } |
| 323 * @endcode |
322 * @endcode |
| 324 * |
323 * |
| 325 * @param list the list to initialize |
324 * @param list the list to initialize |
| 326 * @param cl the list class |
325 * @param cl the list class |
| 327 * @param allocator the allocator for the elements |
326 * @param allocator the allocator for the elements |
| 328 * @param comparator a compare function for the elements |
|
| 329 * @param elem_size the size of one element |
327 * @param elem_size the size of one element |
| 330 */ |
328 */ |
| 331 cx_attr_nonnull_arg(1, 2, 3) |
329 cx_attr_nonnull_arg(1, 2, 3) |
| 332 CX_EXPORT void cx_list_init(struct cx_list_s *list, |
330 CX_EXPORT void cx_list_init(struct cx_list_s *list, |
| 333 struct cx_list_class_s *cl, const struct cx_allocator_s *allocator, |
331 struct cx_list_class_s *cl, const struct cx_allocator_s *allocator, |
| 334 cx_compare_func comparator, size_t elem_size); |
332 size_t elem_size); |
| 335 |
333 |
| 336 /** |
334 /** |
| 337 * Returns the number of elements currently stored in the list. |
335 * Returns the number of elements currently stored in the list. |
| 338 * |
336 * |
| 339 * @param list the list |
337 * @param list the list |