dsi_storage.c

Go to the documentation of this file.
00001 
00007 /* $Id: dsi_storage.c,v 1.4 2007/07/24 19:24:32 yarkhan Exp $ */
00008 /* $UTK_Copyright: $ */
00009 
00010 #ifdef HAVE_CONFIG_H
00011 #include "config.h"
00012 #endif /* HAVE_CONFIG_H */
00013 
00014 #include "dsi.h"
00015 #include "problem.h"
00016 
00017 /* global for keeping track of DSI objects */
00018 
00019 icl_list_t *dsi_objects = NULL;
00020 
00030 int 
00031 gs_comp_dsi_object(void *key, void *d)
00032 {
00033   return (key != d);
00034 }
00035 
00042 void 
00043 gs_free_dsi_object(void *d)
00044 {
00045   free(d);
00046 }
00047 
00056 int 
00057 gs_insert_dsi_object(DSI_OBJECT *dsi_obj)
00058 {
00059   if(!dsi_objects) {
00060     dsi_objects = icl_list_new();
00061     if(!dsi_objects)
00062       return -1;
00063   }
00064 
00065   if(icl_list_append(dsi_objects, dsi_obj) == NULL)
00066     return -1;
00067 
00068   return 0;
00069 }
00070 
00079 int 
00080 gs_remove_dsi_object(DSI_OBJECT *dsi_obj)
00081 {
00082   icl_list_t *tmp;
00083 
00084   if(!dsi_objects)
00085     return 0;
00086 
00087   tmp = icl_list_search(dsi_objects, dsi_obj, gs_comp_dsi_object);
00088 
00089   if(!tmp)
00090     return -1;
00091 
00092   if(icl_list_delete(dsi_objects, tmp, gs_free_dsi_object) < 0)
00093     return -1;
00094 
00095   return 0;
00096 }
00097 
00107 int 
00108 gs_is_dsi_object(void *obj)
00109 {
00110   icl_list_t *tmp;
00111 
00112   if(!dsi_objects)
00113     return 0;
00114 
00115   tmp = icl_list_search(dsi_objects, obj, gs_comp_dsi_object);
00116 
00117   return (tmp != NULL);
00118 }