[go: up one dir, main page]

Menu

[r888]: / trunk / src / common / dllist.h  Maximize  Restore  History

Download this file

227 lines (175 with data), 5.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
///////////////////////////////////////////////////////////////////////////////
// dllist.h
//
// Copyright (C) 2000-2008 Ake Hedman, eurosource, <akhe@eurosource.se>
//
// This software is placed into
// the public domain and may be used for any purpose. However, this
// notice must not be changed or removed and no warranty is either
// expressed or implied by its publication or distribution.
//
// $RCSfile: dllist.h,v $
// $Date: 2006/03/14 21:32:47 $
// $Author: akhe $
// $Revision: 1.6 $
///////////////////////////////////////////////////////////////////////////////
#ifndef H_DLLIST_H
#define H_DLLIST_H
#ifndef BOOL
#define BOOL int
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __int8_t_defined
# define __int8_t_defined
//typedef long long int64_t;
typedef long int32_t;
typedef short int16_t;
typedef char int8_t;
//typedef unsigned long long uint64_t;
typedef unsigned long uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
#endif
/*!
A base class to derive from for object storage
*/
struct dllnode
{
/*!
String key used for alphanumeric sort
*/
char *pstrKey;
/*!
Numeric key used for numeric sort
*/
unsigned long *pKey;
/*!
Sort key (can be used if no other key is abailabe ). pKey should
be pointing to this key if used.
*/
unsigned long Key;
/*!
A pointer to the embedded node object
*/
void *pObject;
/*!
A long that can be used in any way a user likes.
*/
unsigned long obid;
/*!
Pointer to the next node
*/
struct dllnode *pNext;
/*!
Pointer to the previous node
*/
struct dllnode *pPrev;
};
/*!
Methods to handle a node for the double linked list
*/
/*!
Sorttypes for the list
*/
//enum _sorttype { SORT_NONE = 0, SORT_STRING, SORT_NUMERIC };
#define SORT_NONE 0
#define SORT_STRING 1
#define SORT_NUMERIC 2
struct DoubleLinkedList
{
/*!
Sort order
==========
0 - not sorted.
1 - sort on string key.
2 - sort on numeric key.
Note that items can be retrived in accending/decending order by
retriving them from the head or from the tail of the list.
*/
unsigned char nSortOrder;
/*!
Pointer to the head of the linked list
*/
struct dllnode *pHead;
/*!
Pointer to the tail of the linked list
*/
struct dllnode *pTail;
/*!
Number of elements in list
*/
unsigned long nCount;
};
/*!
Initialize the double linked list
*/
void dll_init( struct DoubleLinkedList *, unsigned char );
/*!
Add a node to the front of the linked list.
*/
BOOL dll_addNodeHead( struct DoubleLinkedList *, struct dllnode * );
/*!
Add a node to the end of the linked list.
*/
BOOL dll_addNodeTail( struct DoubleLinkedList *, struct dllnode * );
/*!
Add a node before another node
*/
BOOL dll_addNodeBefore( struct DoubleLinkedList *pdll,
struct dllnode *pNode,
struct dllnode *pInsertNode );
/*!
Add a node after another node.
*/
BOOL dll_addNodeAfter( struct DoubleLinkedList *pdll,
struct dllnode *pNode,
struct dllnode *pInsertNode );
/*!
Add a node sorted by the current sort order
*/
BOOL dll_addNode( struct DoubleLinkedList *, struct dllnode * );
/*!
Remove all nodes form the linked list.
*/
BOOL dll_removeAllNodes( struct DoubleLinkedList * );
/*!
Get node from its numerical key
@param Numerical key for node.
@return Found Object
@return NULL if no match found.
*/
struct dllnode * dll_findNodeFromID( struct DoubleLinkedList *, unsigned long );
/*!
Get node from its string key
@param String key for node.
@return Found Object
@return NULL if no match found.
*/
struct dllnode * dll_findNodeFromString( struct DoubleLinkedList *, char * );
/*!
Insert a node and an object between two other nodes
*/
BOOL dll_insertNode( struct DoubleLinkedList *pdll,
struct dllnode *pNode1,
struct dllnode *pNode2 );
/*!
Remove a node from the double linked list
*/
BOOL dll_removeNode( struct DoubleLinkedList *pdll,
struct dllnode *pNode );
/*!
Get the node count for the list
*/
unsigned long dll_getNodeCount( struct DoubleLinkedList *pdll );
#ifdef __cplusplus
}
#endif
#endif // H_DDLIST_H