00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __WINDOM_LIST__
00028 #define __WINDOM_LIST__
00029
00030 __BEGIN_DECLS
00031
00041 typedef struct Linkable {
00042 struct Linkable *next;
00043 struct Linkable *prev;
00044 } LINKABLE;
00045
00046
00054 typedef struct {
00055 LINKABLE head;
00056 LINKABLE tail;
00057 } LIST;
00058
00059
00065 #define listEmptyListInitializer() {{NULL,NULL},{NULL,NULL}}
00066
00074 static inline void listInit( LIST *list ) {
00075 list->head.next = &list->tail;
00076 list->head.prev = (LINKABLE*)0L;
00077 list->tail.next = (LINKABLE*)0L;
00078 list->tail.prev = &list->head;
00079 }
00080
00087 static inline void listInsert( LINKABLE *iter, LINKABLE *entry ) {
00088 entry->next = iter;
00089 entry->prev = iter->prev;
00090 iter->prev->next = entry;
00091 iter->prev = entry;
00092 }
00093
00100 static inline void listAppend( LINKABLE *iter, LINKABLE *entry ) {
00101 entry->next = iter->next;
00102 entry->prev = iter;
00103 iter->next->prev = entry;
00104 iter->next = entry;
00105 }
00106
00112 static inline LINKABLE *listRemove( LINKABLE *iter ) {
00113 iter->prev->next = iter->next;
00114 iter->next->prev = iter->prev;
00115 return iter;
00116 }
00117
00118 LIST *createList( void );
00119 LIST *listSplice( LIST *list, LINKABLE *first, LINKABLE *pastLast );
00120
00158 #define listForEach( type, i, list ) \
00159 if ( list ) for( i=(type)(list)->head.next; \
00160 ((LINKABLE*)i) != &(list)->tail; \
00161 i=(type)((LINKABLE*)i)->next )
00162
00164 #define listRewind( list ) &((list)->head)
00165
00167 #define listEnd( list ) &((list)->tail)
00168
00171 #define listNext( iter ) ((!((LINKABLE*)iter)->next->next) ? NULL : (((LINKABLE*)iter)->next))
00172
00175 #define listPrev( iter ) ((!((LINKABLE*)iter)->prev->prev) ? NULL : (((LINKABLE*)iter)->prev))
00176
00178 #define listIsEmpty(list) ( ((list)->head.next) == (&(list)->tail))
00179
00182 #define listFirst(list) ( ((list)->head.next) == (&(list)->tail) ? NULL : ((list)->head.next))
00183 #define listLast(list) ( ((list)->tail.prev) == (&(list)->head) ? NULL : ((list)->tail.prev))
00184
00185 typedef struct LinkablePtr {
00186 LINKABLE iter;
00187 void *value;
00188 } LINKABLEPTR;
00189
00190
00193 __END_DECLS
00194
00195 #endif