Back to index

lightning-sunbird  0.9+nobinonly
pvl.h
Go to the documentation of this file.
00001 /*======================================================================
00002  FILE: pvl.h
00003  CREATOR: eric November, 1995
00004 
00005 
00006  (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
00007 ======================================================================*/
00008 
00009 
00010 #ifndef __PVL_H__
00011 #define __PVL_H__
00012 
00013 typedef struct pvl_list_t* pvl_list;
00014 typedef struct pvl_elem_t* pvl_elem;
00015 
00022 typedef struct pvl_elem_t
00023 {
00024        int MAGIC;                  
00025        void *d;                    
00026        struct pvl_elem_t *next;    
00027        struct pvl_elem_t *prior;   
00028 } pvl_elem_t;
00029 
00030 
00031 
00037 extern int  pvl_elem_count;
00038 extern int  pvl_list_count;
00039 
00040 /* Create new lists or elements */
00041 pvl_elem pvl_new_element(void* d, pvl_elem next,pvl_elem prior);
00042 pvl_list pvl_newlist(void);
00043 void pvl_free(pvl_list);
00044 
00045 /* Add, remove, or get the head of the list */
00046 void pvl_unshift(pvl_list l,void *d);
00047 void* pvl_shift(pvl_list l);
00048 pvl_elem pvl_head(pvl_list);
00049 
00050 /* Add, remove or get the tail of the list */
00051 void pvl_push(pvl_list l,void *d);
00052 void* pvl_pop(pvl_list l);
00053 pvl_elem pvl_tail(pvl_list);
00054 
00055 /* Insert elements in random places */
00056 typedef int (*pvl_comparef)(void* a, void* b); /* a, b are of the data type*/
00057 void pvl_insert_ordered(pvl_list l,pvl_comparef f,void *d);
00058 void pvl_insert_after(pvl_list l,pvl_elem e,void *d);
00059 void pvl_insert_before(pvl_list l,pvl_elem e,void *d);
00060 
00061 /* Remove an element, or clear the entire list */
00062 void* pvl_remove(pvl_list,pvl_elem); /* Remove element, return data */
00063 void pvl_clear(pvl_list); /* Remove all elements, de-allocate all data */
00064 
00065 int pvl_count(pvl_list);
00066 
00067 /* Navagate the list */
00068 pvl_elem pvl_next(pvl_elem e);
00069 pvl_elem pvl_prior(pvl_elem e);
00070 
00071 /* get the data in the list */
00072 #ifndef PVL_USE_MACROS
00073 void* pvl_data(pvl_elem);
00074 #else
00075 #define pvl_data(x) x==0 ? 0 : ((struct pvl_elem_t *)x)->d;
00076 #endif
00077 
00078 
00079 /* Find an element for which a function returns true */
00080 typedef int (*pvl_findf)(void* a, void* b); /*a is list elem, b is other data*/
00081 pvl_elem pvl_find(pvl_list l,pvl_findf f,void* v);
00082 pvl_elem pvl_find_next(pvl_list l,pvl_findf f,void* v);
00083 
00088 typedef void (*pvl_applyf)(void* a, void* b); 
00089 void pvl_apply(pvl_list l,pvl_applyf f, void *v);
00090 
00091 
00092 #endif /* __PVL_H__ */
00093 
00094 
00095 
00096 
00097