rtl_433/include/list.h

45 lines
1.5 KiB
C
Raw Permalink Normal View History

/** @file
Generic list.
2019-02-15 17:04:27 +01:00
Copyright (C) 2018 Christian Zuckschwerdt
2019-02-15 17:04:27 +01:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
*/
2019-04-06 17:10:52 +02:00
#ifndef INCLUDE_LIST_H_
#define INCLUDE_LIST_H_
#include <stddef.h>
/// Dynamically growing list, elems is always NULL terminated, call list_ensure_size() to alloc elems.
typedef struct list {
void **elems;
size_t size;
size_t len;
} list_t;
2018-12-20 10:24:27 +01:00
typedef void (*list_elem_free_fn)(void *);
/// Alloc elems if needed and ensure the list has room for at least min_size elements.
void list_ensure_size(list_t *list, size_t min_size);
/// Add to the end of elems, allocs or grows the list if needed and ensures the list has a terminating NULL.
void list_push(list_t *list, void *p);
2018-12-20 11:30:07 +01:00
/// Adds all elements of a NULL terminated list to the end of elems, allocs or grows the list if needed and ensures the list has a terminating NULL.
void list_push_all(list_t *list, void **p);
2019-01-18 09:36:19 +00:00
/// Remove element from the list, frees element with fn.
void list_remove(list_t *list, size_t idx, list_elem_free_fn elem_free);
2018-12-20 10:24:27 +01:00
/// Clear the list, frees each element with fn, does not free backing or list itself.
void list_clear(list_t *list, list_elem_free_fn elem_free);
/// Clear the list, free backing, does not free list itself.
void list_free_elems(list_t *list, list_elem_free_fn elem_free);
2019-04-06 17:10:52 +02:00
#endif /* INCLUDE_LIST_H_ */