Main Page | Class List | Directories | File List | Class Members | File Members

list.h

Go to the documentation of this file.
00001 /*
00002 GOCR Copyright (C) 2000  Joerg Schulenburg Joerg.Schulenburg@physik.uni-magdeburg.de 
00003 GOCR API Copyright (C) 2001 Bruno Barberi Gnecco <brunobg@sourceforge.net>
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program 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
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019 */
00020 
00021 #ifndef _GOCR_LIST_H
00022 #define _GOCR_LIST_H
00023 
00035 struct node {
00036         struct node             *next;          
00037         struct node             *previous;      
00038         void                    *data;          
00039 };
00040 typedef struct node Node;
00041 
00045 struct list {
00046         Node                    *header;        
00047         Node                    *tail;          
00048         Node                    **fix;          
00049         Node                    **current;      
00050         int                     n;              
00051         int                     level;          
00052 };
00053 typedef struct list List;
00054 
00055 /*
00056  * Functions
00057  */
00058 void    list_init               ( List *l );
00059 int     list_app                ( List *l, void *data );
00060 int     list_ins                ( List *l, void *data_after, void *data);
00061 int     list_ins_order          ( List *l, void *data,
00062                                         int (*say_when) (const void *, const void *) );
00063 Node*   list_node_from_data     ( List *l, void *data );
00064 int     list_del                ( List *l, void *data );
00065 void    list_free               ( List *l );
00066 int     list_higher_level       ( List *l );
00067 void    list_lower_level        ( List *l );
00068 void *  list_next               ( List *l, void *data );
00069 void *  list_prev               ( List *l, void *data );
00070 void    list_sort               ( List *l, int (*compare)(const void *, const void *) );
00071 
00077 #define list_empty(l)                   ((l)->header == NULL ? 1 : 0)
00078 
00083 #define list_get_header(l)              ((l)->header->data)
00084 
00089 #define list_get_tail(l)                ((l)->tail->data)
00090 
00096 #define list_get_current(l)             ((l)->current[(l)->level]->data)
00097 
00098 
00099 #define list_get_cur_prev(l)            ((l)->current[(l)->level]->previous == NULL ? \
00100                         NULL : (l)->current[(l)->level]->previous->data )
00101 #define list_get_cur_next(l)            ((l)->current[(l)->level]->next == NULL ? \
00102                         NULL : (l)->current[(l)->level]->next->data )
00103 
00108 #define list_total(l)                   ((l)->n)
00109 
00110 #define for_each_data(l)                \
00111  if (list_higher_level(l) == 0) { \
00112    for ( ; (l)->current[(l)->level]; (l)->current[(l)->level] = \
00113         (l)->current[(l)->level]->next ) { \
00114      if ( (l)->fix[(l)->level] ) { /* fix level */\
00115        int i; \
00116        for ( i = (l)->level - 1; i >= 0; i-- ) {  \
00117        /* check if some other copy of (l)->fix[(l)->level] exists */ \
00118         \
00119          if ( (l)->fix[i] == (l)->fix[(l)->level] ) break; \
00120        } \
00121        if ( i < 0 ) { /* no, it doesn't. Free it */ \
00122          free((l)->fix[(l)->level]); \
00123        } \
00124        (l)->fix[(l)->level] = NULL; \
00125      }
00126 
00127 #define end_for_each(l)                 \
00128    } \
00129  list_lower_level(l); \
00130  }
00131 
00133 #endif

Generated on Tue Oct 25 04:13:04 2005 for GOCR API by  doxygen 1.4.4