list.h 3.97 KB
Newer Older
jehan's avatar
jehan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
    bctoolbox
    Copyright (C) 2016  Belledonne Communications SARL

    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.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

jehan's avatar
jehan committed
19 20
#ifndef BCTBX_LIST_H_
#define BCTBX_LIST_H_
jehan's avatar
jehan committed
21 22 23 24 25 26 27

#include "bctoolbox/port.h"

#ifdef __cplusplus
extern "C"{
#endif

jehan's avatar
jehan committed
28 29 30 31 32
typedef struct _bctbx_list {
	struct _bctbx_list *next;
	struct _bctbx_list *prev;
	void *data;
} bctbx_list_t;
jehan's avatar
jehan committed
33

Ghislain MARY's avatar
Ghislain MARY committed
34 35 36 37 38
typedef int (*bctbx_compare_func)(const void *, const void*);
typedef void (*bctbx_list_iterate_func)(void *);
typedef void (*bctbx_list_iterate2_func)(void *, void *);
typedef void (*bctbx_list_free_func)(void *);
typedef void* (*bctbx_list_copy_func)(void *);
39

40
BCTBX_PUBLIC bctbx_list_t * bctbx_list_new(void *data);
jehan's avatar
jehan committed
41
BCTBX_PUBLIC bctbx_list_t * bctbx_list_append(bctbx_list_t * elem, void * data);
42
BCTBX_PUBLIC bctbx_list_t * bctbx_list_append_link(bctbx_list_t * elem, bctbx_list_t *new_elem);
jehan's avatar
jehan committed
43
BCTBX_PUBLIC bctbx_list_t * bctbx_list_prepend(bctbx_list_t * elem, void * data);
44
BCTBX_PUBLIC bctbx_list_t * bctbx_list_prepend_link(bctbx_list_t* elem, bctbx_list_t *new_elem);
jehan's avatar
jehan committed
45 46 47 48 49
BCTBX_PUBLIC bctbx_list_t * bctbx_list_last_elem(const bctbx_list_t *l);
BCTBX_PUBLIC bctbx_list_t * bctbx_list_first_elem(const bctbx_list_t *l);
BCTBX_PUBLIC bctbx_list_t * bctbx_list_free(bctbx_list_t * elem);
BCTBX_PUBLIC bctbx_list_t * bctbx_list_concat(bctbx_list_t * first, bctbx_list_t * second);
BCTBX_PUBLIC bctbx_list_t * bctbx_list_remove(bctbx_list_t * first, void *data);
50
BCTBX_PUBLIC bctbx_list_t * bctbx_list_remove_custom(bctbx_list_t *first, bctbx_compare_func compare_func, const void *user_data);
jehan's avatar
jehan committed
51
BCTBX_PUBLIC bctbx_list_t * bctbx_list_pop_front(bctbx_list_t *list, void **front_data);
52
BCTBX_PUBLIC size_t bctbx_list_size(const bctbx_list_t * first);
Ghislain MARY's avatar
Ghislain MARY committed
53 54
BCTBX_PUBLIC void bctbx_list_for_each(const bctbx_list_t * list, bctbx_list_iterate_func func);
BCTBX_PUBLIC void bctbx_list_for_each2(const bctbx_list_t * list, bctbx_list_iterate2_func func, void *user_data);
jehan's avatar
jehan committed
55 56 57 58
BCTBX_PUBLIC bctbx_list_t * bctbx_list_remove_link(bctbx_list_t * list, bctbx_list_t * elem);
BCTBX_PUBLIC bctbx_list_t * bctbx_list_delete_link(bctbx_list_t * list, bctbx_list_t * elem);
BCTBX_PUBLIC bctbx_list_t * bctbx_list_find(bctbx_list_t * list, void *data);
BCTBX_PUBLIC bctbx_list_t * bctbx_list_free(bctbx_list_t *list);
jehan's avatar
jehan committed
59
/*frees list elements and associated data, using the supplied function pointer*/
Ghislain MARY's avatar
Ghislain MARY committed
60
BCTBX_PUBLIC bctbx_list_t * bctbx_list_free_with_data(bctbx_list_t *list, bctbx_list_free_func freefunc);
jehan's avatar
jehan committed
61

jehan's avatar
jehan committed
62 63 64 65 66 67 68
BCTBX_PUBLIC bctbx_list_t * bctbx_list_find_custom(const bctbx_list_t * list, bctbx_compare_func cmp, const void *user_data);
BCTBX_PUBLIC void * bctbx_list_nth_data(const bctbx_list_t * list, int index);
BCTBX_PUBLIC int bctbx_list_position(const bctbx_list_t * list, bctbx_list_t * elem);
BCTBX_PUBLIC int bctbx_list_index(const bctbx_list_t * list, void *data);
BCTBX_PUBLIC bctbx_list_t * bctbx_list_insert_sorted(bctbx_list_t * list, void *data, bctbx_compare_func cmp);
BCTBX_PUBLIC bctbx_list_t * bctbx_list_insert(bctbx_list_t * list, bctbx_list_t * before, void *data);
BCTBX_PUBLIC bctbx_list_t * bctbx_list_copy(const bctbx_list_t * list);
jehan's avatar
jehan committed
69
/*copy list elements and associated data, using the supplied function pointer*/
Ghislain MARY's avatar
Ghislain MARY committed
70
BCTBX_PUBLIC bctbx_list_t* bctbx_list_copy_with_data(const bctbx_list_t* list, bctbx_list_copy_func copyfunc);
jehan's avatar
jehan committed
71

jehan's avatar
jehan committed
72 73
BCTBX_PUBLIC bctbx_list_t* bctbx_list_next(const bctbx_list_t *elem);
BCTBX_PUBLIC void* bctbx_list_get_data(const bctbx_list_t *elem);
jehan's avatar
jehan committed
74 75 76 77 78
	
#ifdef __cplusplus
}
#endif

jehan's avatar
jehan committed
79
#endif /* BCTLBX_LIST_H_ */