Merge pull request #5 from diogogithub/cfulist_set_free_function
Added cfulist_set_free_fn()
This commit is contained in:
commit
f3f439998d
@ -490,7 +490,12 @@ cfulist_map(). The return value is used to build a new list.
|
|||||||
|
|
||||||
@deftypefun {cfulist_t *} cfulist_new ();
|
@deftypefun {cfulist_t *} cfulist_new ();
|
||||||
|
|
||||||
Returns a new list.
|
Creates a new list.
|
||||||
|
@end deftypefun
|
||||||
|
|
||||||
|
@deftypefun {cfulist_t *} cfulist_new_with_free_fn (cfulist_free_fn_t @var{ff})
|
||||||
|
|
||||||
|
Same as cfulist_new() except automatically calls cfulist_set_free_fn().
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
@deftypefun {size_t} cfulist_num_entries (cfulist_t *@var{list})
|
@deftypefun {size_t} cfulist_num_entries (cfulist_t *@var{list})
|
||||||
@ -517,7 +522,8 @@ cfulist_map(). The return value is used to build a new list.
|
|||||||
@deftypefun {void} cfulist_delete_data_with_free_fn (cfulist_t * @var{list}, void * @var{data}, cfulist_free_fn_t @var{ff})
|
@deftypefun {void} cfulist_delete_data_with_free_fn (cfulist_t * @var{list}, void * @var{data}, cfulist_free_fn_t @var{ff})
|
||||||
|
|
||||||
Deletes the entry in the list associated with value. If ff is not NULL, it
|
Deletes the entry in the list associated with value. If ff is not NULL, it
|
||||||
is called for value of the entry passed as its only argument.
|
is called for value of the entry passed as its only argument. If ff is not NULL,
|
||||||
|
it overrides any function set previously with cfulist_set_free_function().
|
||||||
|
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
@ -588,10 +594,12 @@ position in the new list.
|
|||||||
Free all resources used by the list.
|
Free all resources used by the list.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
@deftypefun {void} cfulist_destroy (cfulist_t * @var{list}, cfulist_free_fn_t @var{free_fn})
|
@deftypefun {void} cfulist_destroy_with_free_fn (cfulist_t * @var{list}, cfulist_free_fn_t @var{free_fn})
|
||||||
|
|
||||||
Free all resources used by the list. If free_fn is not NULL, call it
|
Free all resources used by the list. If free_fn is not NULL, is called
|
||||||
for each element of the list, passing the data to it as a void *.
|
for each element of the list, passing the data to it as a void *.
|
||||||
|
If free_fn is not NULL, it overrides any function set previously
|
||||||
|
with cfulist_set_free_function().
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,10 +84,16 @@ cfulist_new(void) {
|
|||||||
cfulist_t *
|
cfulist_t *
|
||||||
cfulist_new_with_free_fn(cfulist_free_fn_t free_fn) {
|
cfulist_new_with_free_fn(cfulist_free_fn_t free_fn) {
|
||||||
cfulist_t *list = cfulist_new();
|
cfulist_t *list = cfulist_new();
|
||||||
list->free_fn = free_fn;
|
cfulist_set_free_function (list, free_fn);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cfulist_set_free_function(cfulist_t *list, cfulist_free_fn_t ff) {
|
||||||
|
if (ff) list->free_fn = ff;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
cfulist_num_entries(cfulist_t *list) {
|
cfulist_num_entries(cfulist_t *list) {
|
||||||
return list->num_entries;
|
return list->num_entries;
|
||||||
|
@ -65,9 +65,7 @@ typedef void (*cfulist_free_fn_t)(void *data);
|
|||||||
/* Returns a new list. */
|
/* Returns a new list. */
|
||||||
cfulist_t * cfulist_new(void);
|
cfulist_t * cfulist_new(void);
|
||||||
|
|
||||||
/* Same as cfulist_new(), but set a function to be called on each
|
/* Same as cfulist_new() except automatically calls cfulist_set_free_fn(). */
|
||||||
* element when the list is destroyed.
|
|
||||||
*/
|
|
||||||
cfulist_t * cfulist_new_with_free_fn(cfulist_free_fn_t free_fn);
|
cfulist_t * cfulist_new_with_free_fn(cfulist_free_fn_t free_fn);
|
||||||
|
|
||||||
/* Returns the number of entries in the list. */
|
/* Returns the number of entries in the list. */
|
||||||
|
Reference in New Issue
Block a user