libkcal

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