Debian Codegraph @

src/common/list.h

raw symbols SCIP
1 /*
2 * Copyright (C) 1999,2000 Ross Combs ([email protected])
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 #ifndef INCLUDED_LIST_TYPES
19 #define INCLUDED_LIST_TYPES
20
21 namespace pvpgn
22 {
23
24 typedef struct elem
25 #ifdef LIST_INTERNAL_ACCESS
26 {
27 void * data;
28 struct elem * prev;
29 struct elem * next;
30 }
31 #endif
32 t_elem;
33
34 typedef struct list
35 #ifdef LIST_INTERNAL_ACCESS
36 {
37 unsigned int len;
38 t_elem * head;
39 t_elem * tail;
40 }
41 #endif
42 t_list;
43
44 }
45
46 #endif
47
48
49 /*****/
50 #ifndef JUST_NEED_TYPES
51 #ifndef INCLUDED_LIST_PROTOS
52 #define INCLUDED_LIST_PROTOS
53
54 namespace pvpgn
55 {
56
57 extern t_list * list_create(void);
58 extern int list_destroy(t_list * list);
59 extern unsigned int list_get_length(t_list const * list);
60 extern int list_prepend_data(t_list * list, void * data);
61 extern int list_append_data(t_list * list, void * data);
62 extern t_elem * list_get_elem_by_data(t_list const * list, void const * data);
63 extern t_elem const * list_get_elem_by_data_const(t_list const * list, void const * data);
64
65 /* note changed API for those commands:
66 due to direct removal of elements from list, you need to take special care during list traversal.
67 a pointer to the traversal variable needs to be passed to the list_remove functions, so they
68 can properly modify it to point to the "previous" element (the one before the element to be deleted)
69 so the next elem_get_next call will address the "next" element (the one after the element to be deleted) */
70
71 extern int list_remove_data(t_list * list, void const * data, t_elem ** elem); /* delete matching item */
72 extern int list_remove_elem(t_list * list, t_elem ** elem);
73
74 extern void * list_get_data_by_pos(t_list const * list, unsigned int pos);
75 #ifdef LIST_DEBUG
76 extern t_elem * list_get_first_real(t_list const * list, char const * fn, unsigned int ln);
77 # define list_get_first(L) list_get_first_real(L,__FILE__,__LINE__)
78 #else
79 extern t_elem * list_get_first(t_list const * list);
80 #endif
81 #ifdef LIST_DEBUG
82 extern t_elem const * list_get_first_const_real(t_list const * list, char const * fn, unsigned int ln);
83 # define list_get_first_const(L) list_get_first_const_real(L,__FILE__,__LINE__)
84 #else
85 extern t_elem const * list_get_first_const(t_list const * list);
86 #endif
87
88 extern void * elem_get_data(t_elem const * elem);
89 extern int elem_set_data(t_elem * elem, void * data);
90 #define elem_get_next(list,elem) elem_get_next_real(list,elem,__FILE__,__LINE__)
91 extern t_elem * elem_get_next_real(t_list const * list, t_elem const * elem, char const * fn, unsigned int ln);
92 extern t_elem const * elem_get_next_const(t_list const * list, t_elem const * elem);
93
94 #define LIST_TRAVERSE(list,curr) for (curr=(list)?list_get_first(list):(NULL); curr; curr=elem_get_next(list,curr))
95 #define LIST_TRAVERSE_CONST(list,curr) for (curr=(list)?list_get_first_const(list):(NULL); curr; curr=elem_get_next_const(list,curr))
96
97 }
98
99 #endif
100 #endif