chiark / gitweb /
Imported Debian patch 1.0.0-6
[e16] / src / e16-ecore_list.h
1 /*
2  * Copyright (C) 2000-2007 Carsten Haitzler and various contributors (see AUTHORS)
3  *
4  * Copyright (C) Nathan Ingersoll (author)
5  * Copyright (C) Ibukun Olumuyiwa (ewd -> ecore)
6  * Copyright (C) Dan Sinclair     (various cleanups)
7  * Copyright (C) Kim Woelders     (e16 port/additions)
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to
11  * deal in the Software without restriction, including without limitation the
12  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
13  * sell copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies of the Software, its documentation and marketing & publicity
18  * materials, and acknowledgment shall be given in the documentation, materials
19  * and software packages that this Software was used.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
25  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  */
28 /*
29  * Most of this was snatched from e17/libs/ecore/src/lib/ecore/ecore_list.c
30  * revision 1.21, and associated header files.
31  * The pertinent AUTHORS list is e17/libs/ecore/AUTHORS.
32  */
33 #ifndef _E16_ECORE_LIST_H_
34 #define _E16_ECORE_LIST_H_
35
36 #if USE_ECORE
37
38 #include <Ecore_Data.h>
39
40 #else
41
42 #undef EAPI
43 #define EAPI
44
45 typedef struct _ecore_list Ecore_List;
46 typedef struct _ecore_list_node Ecore_List_Node;
47
48 typedef int         (*Ecore_Compare_Cb) (const void *data, const void *match);
49 typedef void        (*Ecore_For_Each) (void *value, void *user_data);
50 typedef void        (*Ecore_Free_Cb) (void *data);
51
52 /* Creating and initializing new list structures */
53 EAPI Ecore_List    *ecore_list_new(void);
54 EAPI int            ecore_list_init(Ecore_List * list);
55
56 /* Adding items to the list */
57 EAPI int            ecore_list_append(Ecore_List * list, void *_data);
58 EAPI int            ecore_list_prepend(Ecore_List * list, void *_data);
59 EAPI int            ecore_list_insert(Ecore_List * list, void *_data);
60
61 /* Removing items from the list */
62 EAPI int            ecore_list_remove_destroy(Ecore_List * list);
63 EAPI void          *ecore_list_remove(Ecore_List * list);
64 EAPI void          *ecore_list_first_remove(Ecore_List * list);
65 EAPI void          *ecore_list_last_remove(Ecore_List * list);
66
67 /* Retrieve the current position in the list */
68 EAPI void          *ecore_list_current(Ecore_List * list);
69 EAPI int            ecore_list_index(Ecore_List * list);
70 EAPI int            ecore_list_count(Ecore_List * list);
71
72 /* Traversing the list */
73 EAPI int            ecore_list_for_each(Ecore_List * list,
74                                         Ecore_For_Each function,
75                                         void *user_data);
76 EAPI void          *ecore_list_first_goto(Ecore_List * list);
77 EAPI void          *ecore_list_last_goto(Ecore_List * list);
78 EAPI void          *ecore_list_index_goto(Ecore_List * list, int index);
79 EAPI void          *ecore_list_goto(Ecore_List * list, const void *_data);
80
81 /* Traversing the list and returning data */
82 EAPI void          *ecore_list_next(Ecore_List * list);
83 EAPI void          *ecore_list_find(Ecore_List * list,
84                                     Ecore_Compare_Cb function,
85                                     const void *match);
86
87 /* Check to see if there is any data in the list */
88 EAPI int            ecore_list_empty_is(Ecore_List * list);
89
90 /* Remove every node in the list without freeing the list itself */
91 EAPI int            ecore_list_clear(Ecore_List * list);
92
93 /* Free the list and it's contents */
94 EAPI void           ecore_list_destroy(Ecore_List * list);
95
96 /* Creating and initializing list nodes */
97 EAPI Ecore_List_Node *ecore_list_node_new(void);
98 EAPI int            ecore_list_node_init(Ecore_List_Node * newNode);
99
100 /* Destroying nodes */
101 EAPI int            ecore_list_node_destroy(Ecore_List_Node * _e_node,
102                                             Ecore_Free_Cb free_func);
103
104 EAPI int            ecore_list_free_cb_set(Ecore_List * list,
105                                            Ecore_Free_Cb free_func);
106
107 #endif /* USE_ECORE */
108
109 /* e16 additions */
110 #if __cplusplus
111 #define ECORE_LIST_FOR_EACH(list, p) \
112    for (ecore_list_first_goto(list); (p = (typeof(p))ecore_list_next(list)) != NULL;)
113 #else
114 #define ECORE_LIST_FOR_EACH(list, p) \
115    for (ecore_list_first_goto(list); (p = ecore_list_next(list)) != NULL;)
116 #endif
117
118 EAPI void          *ecore_list_node_remove(Ecore_List * list, void *_data);
119 EAPI void         **ecore_list_items_get(Ecore_List * list, int *pnum);
120
121 #endif /* _E16_ECORE_LIST_H_ */