src/cx/list.h

changeset 503
a89857072ace
parent 500
eb9e7bd40a8e
child 504
aaf89ce0cbf6
equal deleted inserted replaced
502:33e7b6ebf403 503:a89857072ace
69 /** 69 /**
70 * The allocator to use. 70 * The allocator to use.
71 */ 71 */
72 CxAllocator *allocator; 72 CxAllocator *allocator;
73 /** 73 /**
74 * A mandatory destructor for the list structure.
75 */
76 cx_destructor_func list_destructor;
77 /**
78 * An optional destructor for the list contents.
79 */
80 cx_destructor_func content_destructor;
81 /**
74 * The comparator function for the elements. 82 * The comparator function for the elements.
75 */ 83 */
76 CxListComparator cmpfunc; 84 CxListComparator cmpfunc;
77 /** 85 /**
78 * The size of each element (payload only). 86 * The size of each element (payload only).
84 size_t size; 92 size_t size;
85 /** 93 /**
86 * The capacity of the list (maximum number of elements). 94 * The capacity of the list (maximum number of elements).
87 */ 95 */
88 size_t capacity; 96 size_t capacity;
97 /**
98 * Flag indicating whether cxListDestroy() shall free the list structure,
99 * even if cx_list_s.list_destructor did not do that.
100 */
101 bool autofree;
102 /**
103 * Flag indicating whether cxListDestroy() shall free each list element,
104 * even if cx_list_s.content_destructor did not do that.
105 */
106 bool autofree_contents;
89 }; 107 };
90 108
91 /** 109 /**
92 * The class definition for arbitrary lists. 110 * The class definition for arbitrary lists.
93 */ 111 */
362 CxList *other 380 CxList *other
363 ) { 381 ) {
364 return list->cl->compare(list, other); 382 return list->cl->compare(list, other);
365 } 383 }
366 384
385 /**
386 * Calls the list's destructor function for every element.
387 * If CxList.autofree_content is \c true, the elements are automatically free'd
388 * unless the content destructor function did not already do that.
389 * Similarly, if CxList.autofree is \c true, the list structure is free'd, unless
390 * the list destructor function did not already do that.
391 *
392 * This function itself is a destructor function for the CxList.
393 *
394 * @param list the list which contents shall be destroyed
395 * @return \p list if the list structure has been free'd during the process
396 */
397 __attribute__((__nonnull__))
398 CxList *cxListDestroy(CxList *list);
399
367 #ifdef __cplusplus 400 #ifdef __cplusplus
368 } /* extern "C" */ 401 } /* extern "C" */
369 #endif 402 #endif
370 403
371 #endif /* UCX_LIST_H */ 404 #endif /* UCX_LIST_H */

mercurial