3 * libEtPan! -- a mail stuff library
5 * clist - Implements simple generic double-linked pointer lists
7 * Copyright (c) 1999-2000, Gaƫl Roualland <gael.roualland@iname.com>
8 * interface changes - 2002 - DINH Viet Hoa
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the libEtPan! project nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 typedef struct clistcell_s
{
49 struct clistcell_s
* previous
;
50 struct clistcell_s
* next
;
59 typedef struct clist_s clist
;
60 typedef clistcell clistiter
;
62 /* Allocate a new pointer list */
65 /* Destroys a list. Data pointed by data pointers is NOT freed. */
66 void clist_free(clist
*);
68 /* Some of the following routines can be implemented as macros to
69 be faster. If you don't want it, define NO_MACROS */
72 /* Returns TRUE if list is empty */
73 int clist_isempty(clist
*);
75 /* Returns the number of elements in the list */
76 int clist_count(clist
*);
78 /* Returns an iterator to the first element of the list */
79 clistiter
* clist_begin(clist
*);
81 /* Returns an iterator to the last element of the list */
82 clistiter
* clist_end(clist
*);
84 /* Returns an iterator to the next element of the list */
85 clistiter
* clist_next(clistiter
*);
87 /* Returns an iterator to the previous element of the list */
88 clistiter
* clist_previous(clistiter
*);
90 /* Returns the data pointer of this element of the list */
91 void* clist_content(clistiter
*);
93 /* Inserts this data pointer at the beginning of the list */
94 int clist_prepend(clist
*, void *);
96 /* Inserts this data pointer at the end of the list */
97 int clist_append(clist
*, void *);
99 #define clist_isempty(lst) ((lst->first==lst->last) && (lst->last==NULL))
100 #define clist_count(lst) (lst->count)
101 #define clist_begin(lst) (lst->first)
102 #define clist_end(lst) (lst->last)
103 #define clist_next(iter) (iter ? iter->next : NULL)
104 #define clist_previous(iter) (iter ? iter->previous : NULL)
105 #define clist_content(iter) (iter ? iter->data : NULL)
106 #define clist_prepend(lst, data) (clist_insert_before(lst, lst->first, data))
107 #define clist_append(lst, data) (clist_insert_after(lst, lst->last, data))
110 /* Inserts this data pointer before the element pointed by the iterator */
111 int clist_insert_before(clist
*, clistiter
*, void *);
113 /* Inserts this data pointer after the element pointed by the iterator */
114 int clist_insert_after(clist
*, clistiter
*, void *);
116 /* Deletes the element pointed by the iterator.
117 Returns an iterator to the next element. */
118 clistiter
* clist_delete(clist
*, clistiter
*);
120 typedef void (* clist_func
)(void *, void *);
122 void clist_foreach(clist
* lst
, clist_func func
, void * data
);
124 void clist_concat(clist
* dest
, clist
* src
);
126 void * clist_nth_data(clist
* lst
, int index
);
128 clistiter
* clist_nth(clist
* lst
, int index
);