WinDom: list.h Source File

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

# list.h

Go to the documentation of this file.

    00001 /*
    00002  * WinDom: a high level GEM library
    00003  * Copyright (c) 1997-2006 windom authors (see AUTHORS file)
    00004  *
    00005  * This library is free software; you can redistribute it and/or
    00006  * modify it under the terms of the GNU Lesser General Public
    00007  * License as published by the Free Software Foundation; either
    00008  * version 2.1 of the License, or (at your option) any later version.
    00009  *
    00010  * This library is distributed in the hope that it will be useful,
    00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013  * Lesser General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Lesser General Public
    00016  * License along with this library; if not, write to the Free Software
    00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    00018  *
    00019  * $Source: /cvsroot/windom/windom/include/windom/list.h,v $
    00020  *
    00021  * CVS info:
    00022  *   $Author: opichals $
    00023  *   $Date: 2006/01/03 15:13:00 $
    00024  *   $Revision: 1.7 $
    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 /* __WINDOM_LIST__ */