Main Page   Compound List   File List   Compound Members   File Members  

list.h

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 
00024 /*
00025  * Structures
00026  */
00027  
00028 struct element {
00029    struct element *next, *previous;
00030    void *data;
00031 };
00032 typedef struct element Element;
00033 
00034 struct list {
00035    Element *header;
00036    Element *tail;
00037    Element **fix;               /* fixes the list_del header problem */
00038    Element **current;           /* for(each_element) */
00039    int n;                       /* number of elements */
00040    int level;                   /* level of nested fors */
00041 };
00042 typedef struct list List;
00043 
00044 /*
00045  * Functions
00046  */
00047 
00048 void    list_init               ( List *l );
00049 int     list_app                ( List *l, void *data );
00050 int     list_ins                ( List *l, void *data_after, void *data);
00051 Element*list_element_from_data  ( List *l, void *data );
00052 int     list_del                ( List *l, void *data );
00053 void    list_free               ( List *l );
00054 int     list_higher_level       ( List *l );
00055 void    list_lower_level        ( List *l );
00056 void *  list_next               ( List *l, void *data );
00057 void *  list_prev               ( List *l, void *data );
00058 void    list_sort               ( List *l, int (*compare)(const void *, const void *) );
00059 
00060 #define list_empty(l)                   ((l)->header == NULL ? 1 : 0)
00061 #define list_get_header(l)              ((l)->header->data)
00062 #define list_get_tail(l)                ((l)->tail->data)
00063 #define list_get_current(l)             ((l)->current[(l)->level]->data)
00064 #define list_get_cur_prev(l)            ((l)->current[(l)->level]->previous == NULL ? \
00065                         NULL : (l)->current[(l)->level]->previous->data )
00066 #define list_get_cur_next(l)            ((l)->current[(l)->level]->next == NULL ? \
00067                         NULL : (l)->current[(l)->level]->next->data )
00068 #define list_total(l)                   ((l)->n)
00069 
00070 #define for_each_data(l)                \
00071  if (list_higher_level(l) == 0) { \
00072    for ( ; (l)->current[(l)->level]; (l)->current[(l)->level] = \
00073         (l)->current[(l)->level]->next ) { \
00074      if ( (l)->fix[(l)->level] ) { /* fix level */\
00075        int i; \
00076        for ( i = (l)->level - 1; i >= 0; i-- ) {  \
00077        /* check if some other copy of (l)->fix[(l)->level] exists */ \
00078         \
00079          if ( (l)->fix[i] == (l)->fix[(l)->level] ) break; \
00080        } \
00081        if ( i < 0 ) { /* no, it doesn't. Free it */ \
00082          free((l)->fix[(l)->level]); \
00083        } \
00084        (l)->fix[(l)->level] = NULL; \
00085      }
00086 
00087 #define end_for_each(l)                 \
00088    } \
00089  list_lower_level(l); \
00090  }
00091 
00092 #endif

Generated at Thu Mar 1 10:05:32 2001 for GOCR API by doxygen1.2.2 written by Dimitri van Heesch, © 1997-2000