graph.c

Go to the documentation of this file.
00001 /***************************************************************************/
00007 #include "graph.h"
00008 #include <stdlib.h>
00009 #include <string.h>
00010 #include <assert.h>
00011 
00012 /* *************************************************************** structures */
00013 
00014 struct s_graph
00015 {
00016     unsigned long color;
00017     char* name;
00018     list* con;
00019 };
00020 
00021 /* ******************************************************* exported functions */
00022 
00023 graph* newGraph(const char* name)
00024 {
00025     graph* res = (graph*) malloc(sizeof(graph));
00026     
00027     res->color = 0;
00028     res->name = strdup(name);
00029     res->con = newList();
00030     
00031     return res;
00032 }
00033 
00034 void deleteGraph(graph* src)
00035 {
00036     assert(src);
00037     
00038     deleteList(src->con);
00039     free(src->name);
00040     free(src);
00041 }
00042 
00043 void graphConnect(graph* src, const graph* dest)
00044 {
00045     assert(src && dest);
00046     
00047     
00048     /* check for double connections - could surely be optimized a bit */
00049     listStart(src->con);
00050     while (listNext(src->con))
00051     {
00052         if (listGet(src->con) == dest)
00053             return;
00054     }
00055     /* check passed, so add that new connection */
00056     listAdd(src->con, dest);
00057 }
00058 
00059 void graphColorNode(graph* src, unsigned long color)
00060 {
00061     assert(src);
00062     src->color = color;
00063 }
00064 
00065 unsigned long graphGetColorNode(graph* src)
00066 {
00067     assert(src);
00068     return src->color;
00069 }
00070 
00071 const char* graphGetNameNode(graph* src)
00072 {
00073     assert(src);
00074     return src->name;
00075 }
00076 
00077 list* graphGetConnections(graph* src)
00078 {
00079     assert(src);
00080     return src->con;
00081 }

Generated on Fri Jun 5 15:31:57 2009 for DeadStrip Utility by  doxygen 1.5.8