Main Page | Class Hierarchy | Data Structures | File List | Data Fields | Globals

def_graph.hpp

Go to the documentation of this file.
00001 // vim:sw=2:ts=8
00023 #ifndef DEF_GRAPH__HPP
00024 #define DEF_GRAPH__HPP
00025 
00026 
00027 #define DEBUG 1 
00030 #include <string>
00031 #include <map>
00032 
00033 // hash_map compiler specifics here
00034 #ifdef __GNUC__
00035 #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
00036   // GCC 3.1 and later
00037   #include <ext/hash_map>
00038   namespace std { using namespace __gnu_cxx; }
00039   namespace __gnu_cxx { using namespace std; }
00040   #define HASH_NAMESPACE __gnu_cxx
00041 #endif
00042 #endif
00043 
00044 #include "boost/graph/adjacency_list.hpp"
00045 
00046 #include "Property.hpp"
00047 
00048 
00049 namespace gns {
00050 
00051   //typedef std::map<std::string, AbstractProperty*> NodeMap;
00052   //typedef std::map<std::string, AbstractProperty*> EdgeMap;
00053 
00055   typedef boost::adjacency_list <
00056     boost::listS,          // OutEdge List (per vertex)
00057     boost::listS,          // Vertex list (vecS would give us automatically indices but remove_vertex needs O(V+E))
00058     boost::bidirectionalS, // Directed graph, storing both in and out edges
00059     //boost::property<boost::vertex_index_t, std::string>, // Vertex properties
00060     //boost::property<boost::edge_index_t, std::string>,   // Edge properties
00061         boost::no_property,    // Vertex properties
00062         boost::no_property,    // Edge properties
00063     boost::no_property,    // Graph properties
00064     boost::listS           // Edge list
00065   > Graph_t;
00066 
00067   //typedef boost::property_traits<boost::property_map<Graph_t, boost::vertex_index_t>::type>::value_type NodeID;
00068   //typedef boost::property_traits<boost::property_map<Graph_t, boost::edge_index_t>::type>::value_type EdgeID;
00069   typedef std::string NodeID;  
00070   typedef std::string EdgeID;  
00072   typedef boost::graph_traits<Graph_t>::vertex_descriptor Node;         
00073   typedef boost::graph_traits<Graph_t>::edge_descriptor Edge;           
00074   typedef boost::graph_traits<Graph_t>::vertex_iterator NodeIter;       
00075   typedef boost::graph_traits<Graph_t>::edge_iterator EdgeIter;         
00076   typedef boost::graph_traits<Graph_t>::out_edge_iterator OutEdgeIter;  
00077   typedef boost::graph_traits<Graph_t>::in_edge_iterator InEdgeIter;    
00079 //  typedef std::string PropertyName;
00080 
00081 
00110 #define foreach_node(G, n) for(gns::NodeIter __next = (G)->first_node(), (n) = __next++; (n) != (G)->last_node(); (n) = __next, ++__next)
00111 
00117 #define foreach_edge(G, e) for(gns::EdgeIter __next = (G)->first_edge(), (e) = __next++; (e) != (G)->last_edge(); (e) = __next, ++__next)
00118 
00127 #define foreach_in_edge(G, n, e) for(gns::InEdgeIter __next = (G)->first_in_edge(n), (e) = __next++; (e) != (G)->last_in_edge(n); (e) = __next, ++__next)
00128 
00137 #define foreach_out_edge(G, n, e) for(gns::OutEdgeIter __next = (G)->first_out_edge(n), (e) = __next++; (e) != (G)->last_out_edge(n); (e) = __next, ++__next)
00138 
00139 
00140 }
00141 
00142 
00144 
00145 //#include <iostream>
00146 // For the hash_map in gnu c++
00147 namespace HASH_NAMESPACE
00148 {
00150   template<>
00151     struct hash< std::string >
00152     {
00154       std::size_t
00155         operator()(const std::string &s) const { return hash<const char *>()( s.c_str() ); }
00156     };
00157         
00158 
00160   template <>
00161     struct hash< void* > // Need this when vertex_descriptor=void*
00162     {
00164       std::size_t
00165         operator()(const void* v) const { return (std::size_t)v; }
00166     };
00167 
00168 
00170   template < typename D, typename V >
00171     struct hash< boost::detail::edge_desc_impl<D,V> >
00172     {
00174       std::size_t
00175         operator()(const boost::detail::edge_desc_impl<D,V> __x) const { return (std::size_t)__x.get_property(); }
00176     };
00177 
00178 /*  template<> struct hash<void*> {
00179     size_t operator()(void* __x) const { return (long)__x; }
00180   };
00181   template<> struct hash<gns::Edge> {
00182     size_t operator()(gns::Edge __x) const { std::cout << "H" << &__x << std::endl; return (long)&__x; }
00183   };*/
00184 }
00185 
00187 
00188 #endif

Generated on Sun Nov 5 12:05:19 2006 for Graph by  doxygen 1.4.1