00001
00023 #ifndef DEF_GRAPH__HPP
00024 #define DEF_GRAPH__HPP
00025
00026
00027 #define DEBUG 1
00030 #include <string>
00031 #include <map>
00032
00033
00034 #ifdef __GNUC__
00035 #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
00036
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
00052
00053
00055 typedef boost::adjacency_list <
00056 boost::listS,
00057 boost::listS,
00058 boost::bidirectionalS,
00059
00060
00061 boost::no_property,
00062 boost::no_property,
00063 boost::no_property,
00064 boost::listS
00065 > Graph_t;
00066
00067
00068
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
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
00146
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* >
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
00179
00180
00181
00182
00183
00184 }
00185
00187
00188 #endif