1 /*======================================================================
3 CREATOR: eric November, 1995
6 (C) COPYRIGHT 2000, Eric Busboom <eric@softwarestudio.org>
7 http://www.softwarestudio.org
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of either:
12 The LGPL as published by the Free Software Foundation, version
13 2.1, available at: http://www.fsf.org/copyleft/lesser.html
17 The Mozilla Public License Version 1.0. You may obtain a copy of
18 the License at http://www.mozilla.org/MPL/
20 ======================================================================*/
26 typedef struct pvl_list_t* pvl_list;
27 typedef struct pvl_elem_t* pvl_elem;
30 * This type is private. Always use pvl_elem instead. The struct would
31 * not even appear in this header except to make code in the USE_MACROS
35 typedef struct pvl_elem_t
37 int MAGIC; /**< Magic Identifier */
38 void *d; /**< Pointer to data user is storing */
39 struct pvl_elem_t *next; /**< Next element */
40 struct pvl_elem_t *prior; /**< Prior element */
46 * This global is incremented for each call to pvl_new_element(); it gives each
47 * list a unique identifer
50 extern int pvl_elem_count;
51 extern int pvl_list_count;
53 /* Create new lists or elements */
54 pvl_elem pvl_new_element(void* d, pvl_elem next,pvl_elem prior);
55 pvl_list pvl_newlist(void);
56 void pvl_free(pvl_list);
58 /* Add, remove, or get the head of the list */
59 void pvl_unshift(pvl_list l,void *d);
60 void* pvl_shift(pvl_list l);
61 pvl_elem pvl_head(pvl_list);
63 /* Add, remove or get the tail of the list */
64 void pvl_push(pvl_list l,void *d);
65 void* pvl_pop(pvl_list l);
66 pvl_elem pvl_tail(pvl_list);
68 /* Insert elements in random places */
69 typedef int (*pvl_comparef)(void* a, void* b); /* a, b are of the data type*/
70 void pvl_insert_ordered(pvl_list l,pvl_comparef f,void *d);
71 void pvl_insert_after(pvl_list l,pvl_elem e,void *d);
72 void pvl_insert_before(pvl_list l,pvl_elem e,void *d);
74 /* Remove an element, or clear the entire list */
75 void* pvl_remove(pvl_list,pvl_elem); /* Remove element, return data */
76 void pvl_clear(pvl_list); /* Remove all elements, de-allocate all data */
78 int pvl_count(pvl_list);
80 /* Navagate the list */
81 pvl_elem pvl_next(pvl_elem e);
82 pvl_elem pvl_prior(pvl_elem e);
84 /* get the data in the list */
85 #ifndef PVL_USE_MACROS
86 void* pvl_data(pvl_elem);
88 #define pvl_data(x) x==0 ? 0 : ((struct pvl_elem_t *)x)->d;
92 /* Find an element for which a function returns true */
93 typedef int (*pvl_findf)(void* a, void* b); /*a is list elem, b is other data*/
94 pvl_elem pvl_find(pvl_list l,pvl_findf f,void* v);
95 pvl_elem pvl_find_next(pvl_list l,pvl_findf f,void* v);
98 * Pass each element in the list to a function
99 * a is list elem, b is other data
101 typedef void (*pvl_applyf)(void* a, void* b);
102 void pvl_apply(pvl_list l,pvl_applyf f, void *v);
105 #endif /* __PVL_H__ */