diff --git a/include/boost/graph/leda_graph.hpp b/include/boost/graph/leda_graph.hpp index 24a47b8d..5d1050d3 100644 --- a/include/boost/graph/leda_graph.hpp +++ b/include/boost/graph/leda_graph.hpp @@ -25,10 +25,14 @@ #ifndef BOOST_GRAPH_LEDA_HPP #define BOOST_GRAPH_LEDA_HPP -#include - #include #include +#include +#include + +#include +#include +#include // The functions and classes in this file allows the user to // treat a LEDA GRAPH object as a boost graph "as is". No @@ -355,9 +359,189 @@ namespace boost { { g.del_edge(e); } - // property maps... + + //=========================================================================== + // property maps + class leda_graph_id_map + : public put_get_helper + { + public: + typedef readable_property_map_tag category; + typedef int value_type; + typedef int reference; + typedef node key_type; + leda_graph_id_map() { } + template + long operator[](T x) const { return x->id(); } + }; + template + inline leda_graph_id_map + get(vertex_index_t, const GRAPH& g) { + return leda_graph_id_map(); + } + template + inline leda_graph_id_map + get(edge_index_t, const GRAPH& g) { + return leda_graph_id_map(); + } + + template + struct leda_property_map { }; + + template <> + struct leda_property_map { + template + struct bind { + typedef leda_graph_id_map type; + typedef leda_graph_id_map const_type; + }; + }; + template <> + struct leda_property_map { + template + struct bind { + typedef leda_graph_id_map type; + typedef leda_graph_id_map const_type; + }; + }; + + + template + class leda_graph_data_map + : public put_get_helper > + { + public: + typedef Data value_type; + typedef DataRef reference; + typedef void key_type; + typedef lvalue_property_map_tag category; + leda_graph_data_map(GraphPtr g) : m_g(g) { } + template + DataRef operator[](NodeOrEdge x) const { return (*m_g)[x]; } + protected: + GraphPtr m_g; + }; + + template <> + struct leda_property_map { + template + struct bind { + typedef leda_graph_data_map*> type; + typedef leda_graph_data_map*> const_type; + }; + }; + template + inline typename property_map< GRAPH, vertex_all_t>::type + get(vertex_all_t, GRAPH& g) { + typedef typename property_map< GRAPH, vertex_all_t>::type + pmap_type; + return pmap_type(&g); + } + template + inline typename property_map< GRAPH, vertex_all_t>::const_type + get(vertex_all_t, const GRAPH& g) { + typedef typename property_map< GRAPH, + vertex_all_t>::const_type pmap_type; + return pmap_type(&g); + } + + template <> + struct leda_property_map { + template + struct bind { + typedef leda_graph_data_map*> type; + typedef leda_graph_data_map*> const_type; + }; + }; + template + inline typename property_map< GRAPH, edge_all_t>::type + get(edge_all_t, GRAPH& g) { + typedef typename property_map< GRAPH, edge_all_t>::type + pmap_type; + return pmap_type(&g); + } + template + inline typename property_map< GRAPH, edge_all_t>::const_type + get(edge_all_t, const GRAPH& g) { + typedef typename property_map< GRAPH, + edge_all_t>::const_type pmap_type; + return pmap_type(&g); + } + + // property map interface to the LEDA node_array class + + template + class leda_node_property_map + : public put_get_helper > + { + public: + leda_node_property_map(NodeMapPtr a) : m_array(a) { } + ERef operator[](node n) const { return (*m_array)[n]; } + protected: + NodeMapPtr m_array; + }; + template + leda_node_property_map*> + make_leda_node_property_map(const node_array& a) + { + typedef leda_node_property_map*> pmap_type; + return pmap_type(&a); + } + template + leda_node_property_map*> + make_leda_node_property_map(node_array& a) + { + typedef leda_node_property_map*> pmap_type; + return pmap_type(&a); + } + + template + leda_node_property_map*> + make_leda_node_property_map(const node_map& a) + { + typedef leda_node_property_map*> pmap_type; + return pmap_type(&a); + } + template + leda_node_property_map*> + make_leda_node_property_map(node_map& a) + { + typedef leda_node_property_map*> pmap_type; + return pmap_type(&a); + } + + // g++ 'enumeral_type' in template unification not implemented workaround + template + struct property_map, Tag> { + typedef typename + leda_property_map::template bind map_gen; + typedef typename map_gen::type type; + typedef typename map_gen::const_type const_type; + }; + + template + inline + typename boost::property_traits< + typename boost::property_map,PropertyTag>::const_type + >::value_type + get(PropertyTag p, const GRAPH& g, const Key& key) { + return get(get(p, g), key); + } + template + inline void + put(PropertyTag p, GRAPH& g, + const Key& key, const Value& value) + { + typedef typename property_map, PropertyTag>::type Map; + Map pmap = get(p, g); + put(pmap, key, value); + } + } // namespace boost