• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright (c) 2009, 2013 IBM Corp.
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * and Eclipse Distribution License v1.0 which accompany this distribution.
7  *
8  * The Eclipse Public License is available at
9  *    http://www.eclipse.org/legal/epl-v10.html
10  * and the Eclipse Distribution License is available at
11  *   http://www.eclipse.org/org/documents/edl-v10.php.
12  *
13  * Contributors:
14  *    Ian Craggs - initial API and implementation and/or initial documentation
15  *    Ian Craggs - updates for the async client
16  *    Ian Craggs - change size types from int to size_t
17  *******************************************************************************/
18 
19 #if !defined(LINKEDLIST_H)
20 #define LINKEDLIST_H
21 
22 #include <stdlib.h> /* for size_t definition */
23 
24 /*BE
25 defm defList(T)
26 
27 def T concat Item
28 {
29 	at 4
30 	n32 ptr T concat Item suppress "next"
31 	at 0
32 	n32 ptr T concat Item suppress "prev"
33 	at 8
34 	n32 ptr T id2str(T)
35 }
36 
37 def T concat List
38 {
39 	n32 ptr T concat Item suppress "first"
40 	n32 ptr T concat Item suppress "last"
41 	n32 ptr T concat Item suppress "current"
42 	n32 dec "count"
43 	n32 suppress "size"
44 }
45 endm
46 
47 defList(INT)
48 defList(STRING)
49 defList(TMP)
50 
51 BE*/
52 
53 /**
54  * Structure to hold all data for one list element
55  */
56 typedef struct ListElementStruct
57 {
58 	struct ListElementStruct *prev, /**< pointer to previous list element */
59 							*next;	/**< pointer to next list element */
60 	void* content;					/**< pointer to element content */
61 } ListElement;
62 
63 
64 /**
65  * Structure to hold all data for one list
66  */
67 typedef struct
68 {
69 	ListElement *first,	/**< first element in the list */
70 				*last,	/**< last element in the list */
71 				*current;	/**< current element in the list, for iteration */
72 	int count;  /**< no of items */
73 	size_t size;  /**< heap storage used */
74 } List;
75 
76 void ListZero(List*);
77 List* ListInitialize(void);
78 
79 void ListAppend(List* aList, void* content, size_t size);
80 void ListAppendNoMalloc(List* aList, void* content, ListElement* newel, size_t size);
81 void ListInsert(List* aList, void* content, size_t size, ListElement* index);
82 
83 int ListRemove(List* aList, void* content);
84 int ListRemoveItem(List* aList, void* content, int(*callback)(void*, void*));
85 void* ListDetachHead(List* aList);
86 int ListRemoveHead(List* aList);
87 void* ListPopTail(List* aList);
88 
89 int ListDetach(List* aList, void* content);
90 int ListDetachItem(List* aList, void* content, int(*callback)(void*, void*));
91 
92 void ListFree(List* aList);
93 void ListEmpty(List* aList);
94 void ListFreeNoContent(List* aList);
95 
96 ListElement* ListNextElement(List* aList, ListElement** pos);
97 ListElement* ListPrevElement(List* aList, ListElement** pos);
98 
99 ListElement* ListFind(List* aList, void* content);
100 ListElement* ListFindItem(List* aList, void* content, int(*callback)(void*, void*));
101 
102 int intcompare(void* a, void* b);
103 int stringcompare(void* a, void* b);
104 
105 #endif
106