Imported Upstream version 0.48
[platform/upstream/libical.git] / src / libical / pvl.h
1 /*======================================================================
2  FILE: pvl.h
3  CREATOR: eric November, 1995
4
5
6  (C) COPYRIGHT 2000, Eric Busboom <eric@softwarestudio.org>
7      http://www.softwarestudio.org
8
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of either:
11
12     The LGPL as published by the Free Software Foundation, version
13     2.1, available at: http://www.fsf.org/copyleft/lesser.html
14
15   Or:
16
17     The Mozilla Public License Version 1.0. You may obtain a copy of
18     the License at http://www.mozilla.org/MPL/
19
20 ======================================================================*/
21
22
23 #ifndef __PVL_H__
24 #define __PVL_H__
25
26 typedef struct pvl_list_t* pvl_list;
27 typedef struct pvl_elem_t* pvl_elem;
28
29 /**
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
32  * blocks work
33  */
34
35 typedef struct pvl_elem_t
36 {
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 */
41 } pvl_elem_t;
42
43
44
45 /**
46  * This global is incremented for each call to pvl_new_element(); it gives each
47  * list a unique identifer
48  */
49
50 extern int  pvl_elem_count;
51 extern int  pvl_list_count;
52
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);
57
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);
62
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);
67
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);
73
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 */
77
78 int pvl_count(pvl_list);
79
80 /* Navagate the list */
81 pvl_elem pvl_next(pvl_elem e);
82 pvl_elem pvl_prior(pvl_elem e);
83
84 /* get the data in the list */
85 #ifndef PVL_USE_MACROS
86 void* pvl_data(pvl_elem);
87 #else
88 #define pvl_data(x) x==0 ? 0 : ((struct pvl_elem_t *)x)->d;
89 #endif
90
91
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);
96
97 /**
98  * Pass each element in the list to a function
99  * a is list elem, b is other data
100  */
101 typedef void (*pvl_applyf)(void* a, void* b); 
102 void pvl_apply(pvl_list l,pvl_applyf f, void *v);
103
104
105 #endif /* __PVL_H__ */
106
107
108
109
110