source: branches/branch-1-0/include/helpers/linklist.h

Last change on this file was 174, checked in by umoeller, 23 years ago

Misc updates.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 KB
Line 
1
2/*
3 *@@sourcefile linklist.h:
4 * header file for linklist.c. See remarks there.
5 *
6 * Note: Version numbering in this file relates to XWorkplace version
7 * numbering.
8 *
9 *@@include #include "helpers\linklist.h"
10 */
11
12/* Copyright (C) 1997-2001 Ulrich M”ller.
13 * This file is part of the "XWorkplace helpers" source package.
14 * This is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published
16 * by the Free Software Foundation, in version 2 as it comes in the
17 * "COPYING" file of the XWorkplace main distribution.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 */
23
24#if __cplusplus
25extern "C" {
26#endif
27
28#ifndef LINKLIST_HEADER_INCLUDED
29 #define LINKLIST_HEADER_INCLUDED
30
31 #ifndef XWPENTRY
32 #error You must define XWPENTRY to contain the standard linkage for the XWPHelpers.
33 #endif
34
35 #include "helpers\simples.h"
36 // V0.9.19 (2002-06-13) [umoeller]
37
38 /* LISTITEM was used before V0.9.0 */
39 /* typedef struct _LISTITEM {
40 struct LIST_STRUCT *pNext, *pPrevious;
41 unsigned long ulSize;
42 } LISTITEM, *PLISTITEM; */
43
44 /*
45 *@@ LISTNODE:
46 * this defines one item in a LINKLIST.
47 *
48 * pItemData points to the actual data,
49 * whatever format this is in...
50 *
51 * See linklist.c for more on how
52 * to use these.
53 *
54 *@@added V0.9.0
55 */
56
57 typedef struct _LISTNODE
58 {
59 void *pItemData;
60 struct _LISTNODE *pNext,
61 *pPrevious;
62 } LISTNODE, *PLISTNODE;
63
64 /*
65 *@@ LINKLIST:
66 * the "root" of a linked list.
67 *
68 * See linklist.c for more on how
69 * to use these.
70 *
71 *@@added V0.9.0
72 */
73
74 typedef struct _LINKLIST
75 {
76 unsigned long ulMagic; // integrity check
77 unsigned long ulCount; // no. of items on list
78 PLISTNODE pFirst, // first node
79 pLast; // last node
80 BOOL fItemsFreeable; // as in lstCreate()
81 } LINKLIST, *PLINKLIST;
82
83 #define LINKLISTMAGIC 0xf124 // could be anything
84
85 typedef signed short XWPENTRY FNSORTLIST(void*, void*, void*);
86 // changed V0.9.0 (99-10-22) [umoeller]
87 typedef FNSORTLIST *PFNSORTLIST;
88
89 /*
90 *@@ FOR_ALL_NODES:
91 * helper macro to iterator over all nodes in
92 * a list.
93 *
94 * Usage:
95 +
96 + PLINKLIST pll = ...;
97 + PLISTNODE pNode;
98 +
99 + FOR_ALL_NODES(pll, pNode)
100 + {
101 + PVOID pData = (PVOID)pNode->pItemData;
102 + }
103 +
104 * This really is a "for" loop, so you can "break"
105 * out of the loop.
106 *
107 *@@added V0.9.9 (2001-04-01) [umoeller]
108 */
109
110 #define FOR_ALL_NODES(pll, pNode) for (pNode = lstQueryFirstNode(pll); (pNode); pNode = pNode->pNext)
111
112 /* ******************************************************************
113 *
114 * List base functions
115 *
116 ********************************************************************/
117
118 void* XWPENTRY lstMalloc(size_t size);
119 typedef void* XWPENTRY LSTMALLOC(size_t size);
120 typedef LSTMALLOC *PLSTMALLOC;
121
122 void* XWPENTRY lstStrDup(const char *pcsz);
123 typedef void* XWPENTRY LSTSTRDUP(const char *pcsz);
124 typedef LSTSTRDUP *PLSTSTRDUP;
125
126 void XWPENTRY lstInit(PLINKLIST pList, BOOL fItemsFreeable);
127 typedef void XWPENTRY LSTINIT(PLINKLIST pList, BOOL fItemsFreeable);
128 typedef LSTINIT *PLSTINIT;
129
130 #if (defined(__DEBUG_MALLOC_ENABLED__) && !defined(DONT_REPLACE_LIST_MALLOC)) // setup.h, helpers\memdebug.c
131 PLINKLIST XWPENTRY lstCreateDebug(BOOL fItemsFreeable,
132 const char *file,
133 unsigned long line,
134 const char *function);
135 typedef PLINKLIST XWPENTRY LSTCREATEDEBUG(BOOL fItemsFreeable,
136 const char *file,
137 unsigned long line,
138 const char *function);
139 typedef LSTCREATEDEBUG *PLSTCREATEDEBUG;
140
141 #define lstCreate(b) lstCreateDebug((b), __FILE__, __LINE__, __FUNCTION__)
142 #else
143 PLINKLIST XWPENTRY lstCreate(BOOL fItemsFreeable);
144 typedef PLINKLIST XWPENTRY LSTCREATE(BOOL fItemsFreeable);
145 typedef LSTCREATE *PLSTCREATE;
146 #endif
147
148 BOOL XWPENTRY lstFree(PLINKLIST *ppList);
149 typedef BOOL XWPENTRY LSTFREE(PLINKLIST *ppList);
150 typedef LSTFREE *PLSTFREE;
151
152 BOOL XWPENTRY lstClear(PLINKLIST pList);
153 typedef BOOL XWPENTRY LSTCLEAR(PLINKLIST pList);
154 typedef LSTCLEAR *PLSTCLEAR;
155
156 long XWPENTRY lstCountItems(const LINKLIST *pList);
157 typedef long XWPENTRY LSTCOUNTITEMS(const LINKLIST *pList);
158 typedef LSTCOUNTITEMS *PLSTCOUNTITEMS;
159
160 PLISTNODE XWPENTRY lstQueryFirstNode(const LINKLIST *pList);
161 typedef PLISTNODE XWPENTRY LSTQUERYFIRSTNODE(PLINKLIST pList);
162 typedef LSTQUERYFIRSTNODE *PLSTQUERYFIRSTNODE;
163
164 PLISTNODE XWPENTRY lstQueryLastNode(const LINKLIST *pList);
165 typedef PLISTNODE XWPENTRY LSTQUERYLASTNODE(PLINKLIST pList);
166 typedef LSTQUERYLASTNODE *PLSTQUERYLASTNODE;
167
168 PLISTNODE XWPENTRY lstNodeFromIndex(PLINKLIST pList, unsigned long ulIndex);
169 typedef PLISTNODE XWPENTRY LSTNODEFROMINDEX(PLINKLIST pList, unsigned long ulIndex);
170 typedef LSTNODEFROMINDEX *PLSTNODEFROMINDEX;
171
172 PLISTNODE XWPENTRY lstNodeFromItem(PLINKLIST pList, void* pItemData);
173 typedef PLISTNODE XWPENTRY LSTNODEFROMITEM(PLINKLIST pList, void* pItemData);
174 typedef LSTNODEFROMITEM *PLSTNODEFROMITEM;
175
176 void* XWPENTRY lstItemFromIndex(PLINKLIST pList, unsigned long ulIndex);
177 typedef void* XWPENTRY LSTITEMFROMINDEX(PLINKLIST pList, unsigned long ulIndex);
178 typedef LSTITEMFROMINDEX *PLSTITEMFROMINDEX;
179
180 unsigned long lstIndexFromItem(PLINKLIST pList, void *pItemData);
181 typedef unsigned long LSTINDEXFROMITEM(PLINKLIST pList, void *pItemData);
182 typedef LSTINDEXFROMITEM *PLSTINDEXFROMITEM;
183
184 #if (defined(__DEBUG_MALLOC_ENABLED__) && !defined(DONT_REPLACE_LIST_MALLOC)) // setup.h, helpers\memdebug.c
185 PLISTNODE XWPENTRY lstAppendItemDebug(PLINKLIST pList,
186 void* pNewItemData,
187 const char *file,
188 unsigned long line,
189 const char *function);
190 #define lstAppendItem(pl, pd) lstAppendItemDebug((pl), (pd), __FILE__, __LINE__, __FUNCTION__)
191 #else
192 PLISTNODE XWPENTRY lstAppendItem(PLINKLIST pList, void* pNewItemData);
193 typedef PLISTNODE XWPENTRY LSTAPPENDITEM(PLINKLIST pList, void* pNewItemData);
194 typedef LSTAPPENDITEM *PLSTAPPENDITEM;
195 #endif
196
197 PLISTNODE XWPENTRY lstInsertItemBefore(PLINKLIST pList,
198 void* pNewItemData,
199 unsigned long ulIndex);
200 typedef PLISTNODE XWPENTRY LSTINSERTITEMBEFORE(PLINKLIST pList,
201 void* pNewItemData,
202 unsigned long ulIndex);
203 typedef LSTINSERTITEMBEFORE *PLSTINSERTITEMBEFORE;
204
205 BOOL XWPENTRY lstRemoveNode(PLINKLIST pList, PLISTNODE pRemoveNode);
206 typedef BOOL XWPENTRY LSTREMOVENODE(PLINKLIST pList, PLISTNODE pRemoveNode);
207 typedef LSTREMOVENODE *PLSTREMOVENODE;
208
209 BOOL XWPENTRY lstRemoveItem(PLINKLIST pList, void* pRemoveItem);
210 typedef BOOL XWPENTRY LSTREMOVEITEM(PLINKLIST pList, void* pRemoveItem);
211 typedef LSTREMOVEITEM *PLSTREMOVEITEM;
212
213 BOOL XWPENTRY lstSwapNodes(PLISTNODE pNode1, PLISTNODE pNode2);
214 typedef BOOL XWPENTRY LSTSWAPNODES(PLISTNODE pNode1, PLISTNODE pNode2);
215 typedef LSTSWAPNODES *PLSTSWAPNODES;
216
217 /* ******************************************************************
218 *
219 * List sorting
220 *
221 ********************************************************************/
222
223 BOOL XWPENTRY lstQuickSort(PLINKLIST pList,
224 PFNSORTLIST pfnSort,
225 void* pStorage);
226
227 BOOL XWPENTRY lstBubbleSort(PLINKLIST pList,
228 PFNSORTLIST pfnSort,
229 void* pStorage);
230
231 /* ******************************************************************
232 *
233 * List pseudo-stacks
234 *
235 ********************************************************************/
236
237 PLISTNODE lstPush(PLINKLIST pList,
238 void* pNewItemData);
239
240 PLISTNODE lstPop(PLINKLIST pList);
241
242#endif
243
244#if __cplusplus
245}
246#endif
247
Note: See TracBrowser for help on using the repository browser.