191 * Common type for all list implementations. |
191 * Common type for all list implementations. |
192 */ |
192 */ |
193 typedef struct cx_list_s CxList; |
193 typedef struct cx_list_s CxList; |
194 |
194 |
195 /** |
195 /** |
|
196 * Convenience function to configure the memory management for this a list. |
|
197 * @param list the list to configure |
|
198 * @param list_destructor an alternative list destructor to use (if \c NULL, the current destructor remains unchanged) |
|
199 * @param content_destructor the content destructor to use (if \c NULL, no content destructor is used) |
|
200 * @param list_autofree a flag indicating, if the list allocator shall free the list, if the destructor did not do that |
|
201 * @param content_autofree a flag indicating, if the list allocator shall free an element, |
|
202 * if the content destructor did not do that or no content destructor exists |
|
203 */ |
|
204 static inline void cxListMemoryMgmt( |
|
205 CxList *list, |
|
206 cx_destructor_func list_destructor, |
|
207 cx_destructor_func content_destructor, |
|
208 bool list_autofree, |
|
209 bool content_autofree |
|
210 ) { |
|
211 if (list_destructor != NULL) list->list_destructor = list_destructor; |
|
212 list->content_destructor = content_destructor; |
|
213 list->autofree = list_autofree; |
|
214 list->autofree_contents = content_autofree; |
|
215 } |
|
216 |
|
217 /** |
196 * Adds an item to the end of the list. |
218 * Adds an item to the end of the list. |
197 * |
219 * |
198 * @param list the list |
220 * @param list the list |
199 * @param elem a pointer to the element to add |
221 * @param elem a pointer to the element to add |
200 * @return zero on success, non-zero on memory allocation failure |
222 * @return zero on success, non-zero on memory allocation failure |