69 /** |
69 /** |
70 * The allocator to use. |
70 * The allocator to use. |
71 */ |
71 */ |
72 CxAllocator const *allocator; |
72 CxAllocator const *allocator; |
73 /** |
73 /** |
74 * An optional destructor for the list contents. |
|
75 * |
|
76 * @attention Read the documentation of the particular list implementation |
|
77 * whether this destructor shall only destroy the contents or also free the memory. |
|
78 */ |
|
79 cx_destructor_func content_destructor; |
|
80 /** |
|
81 * The comparator function for the elements. |
74 * The comparator function for the elements. |
82 */ |
75 */ |
83 CxListComparator cmpfunc; |
76 CxListComparator cmpfunc; |
84 /** |
77 /** |
85 * The size of each element (payload only). |
78 * The size of each element (payload only). |
91 size_t size; |
84 size_t size; |
92 /** |
85 /** |
93 * The capacity of the list (maximum number of elements). |
86 * The capacity of the list (maximum number of elements). |
94 */ |
87 */ |
95 size_t capacity; |
88 size_t capacity; |
|
89 union { |
|
90 /** |
|
91 * An optional simple destructor for the list contents that admits the free() interface. |
|
92 * |
|
93 * @remark Set content_destructor_type to #CX_DESTRUCTOR_SIMPLE. |
|
94 * |
|
95 * @attention Read the documentation of the particular list implementation |
|
96 * whether this destructor shall only destroy the contents or also free the memory. |
|
97 */ |
|
98 cx_destructor_func simple_destructor; |
|
99 /** |
|
100 * An optional advanced destructor for the list contents providing additional data. |
|
101 * |
|
102 * @remark Set content_destructor_type to #CX_DESTRUCTOR_ADVANCED. |
|
103 * |
|
104 * @attention Read the documentation of the particular list implementation |
|
105 * whether this destructor shall only destroy the contents or also free the memory. |
|
106 */ |
|
107 cx_advanced_destructor advanced_destructor; |
|
108 }; |
|
109 /** |
|
110 * The type of destructor to use. |
|
111 */ |
|
112 enum cx_destructor_type content_destructor_type; |
96 }; |
113 }; |
97 |
114 |
98 /** |
115 /** |
99 * The class definition for arbitrary lists. |
116 * The class definition for arbitrary lists. |
100 */ |
117 */ |
387 ) { |
404 ) { |
388 return list->cl->compare(list, other); |
405 return list->cl->compare(list, other); |
389 } |
406 } |
390 |
407 |
391 /** |
408 /** |
392 * Calls the list's destructor function for every element. |
409 * Deallocates the memory of the specified list structure. |
393 * If CxList.autofree_content is \c true, the elements are automatically free'd |
410 * |
394 * unless the content destructor function did not already do that. |
411 * Also calls content a destructor function, depending on the configuration |
395 * Similarly, if CxList.autofree is \c true, the list structure is free'd, unless |
412 * in CxList.content_destructor_type. |
396 * the list destructor function did not already do that. |
|
397 * |
413 * |
398 * This function itself is a destructor function for the CxList. |
414 * This function itself is a destructor function for the CxList. |
399 * |
415 * |
400 * @param list the list which contents shall be destroyed |
416 * @param list the list which shall be destroyed |
401 * @return \p list if the list structure has not been free'd during the process |
417 */ |
402 */ |
418 __attribute__((__nonnull__)) |
403 __attribute__((__nonnull__)) |
419 void cxListDestroy(CxList *list); |
404 CxList *cxListDestroy(CxList *list); |
|
405 |
420 |
406 #ifdef __cplusplus |
421 #ifdef __cplusplus |
407 } /* extern "C" */ |
422 } /* extern "C" */ |
408 #endif |
423 #endif |
409 |
424 |