From 929df2bcdd4722f0797db511828419971dddf734 Mon Sep 17 00:00:00 2001 From: Jeremy Siek Date: Sun, 4 Feb 2001 03:12:40 +0000 Subject: [PATCH] got some property stuff working, and added children() [SVN r8894] --- include/boost/graph/subgraph.hpp | 118 ++++++++++++++++++++++++------- 1 file changed, 91 insertions(+), 27 deletions(-) diff --git a/include/boost/graph/subgraph.hpp b/include/boost/graph/subgraph.hpp index c07b7fea..e72c849d 100644 --- a/include/boost/graph/subgraph.hpp +++ b/include/boost/graph/subgraph.hpp @@ -35,6 +35,7 @@ #include #include #include +#include namespace boost { @@ -125,11 +126,11 @@ namespace boost { } edge_descriptor local_to_global(edge_descriptor e_local) { - return m_global_edge[get(edge_index, g, u_local)]; + return m_global_edge[get(edge_index, m_graph, e_local)]; } edge_descriptor global_to_local(edge_descriptor e_global) { - return m_local_edge[get(edge_index, this->root(), u_global)]; + return m_local_edge[get(edge_index, root().m_graph, e_global)]; } // Is vertex u (of the root graph) contained in this subgraph? @@ -140,6 +141,7 @@ namespace boost { // Return the parent graph. subgraph& parent() { return *m_parent; } + const subgraph& parent() const { return *m_parent; } // Return the root graph of the subgraph tree. subgraph& root() { @@ -148,6 +150,28 @@ namespace boost { else return m_parent->root(); } + const subgraph& root() const { + if (m_parent == 0) + return *this; + else + return m_parent->root(); + } + + // Return the children subgraphs of this graph/subgraph. + typedef subgraph* inner_iter; + typedef typename std::list::const_iterator outer_iter; + typedef typename boost::indirect_iterator, + boost::iterator > + >::type children_iterator; + + std::pair + children() const + { + return std::make_pair(children_iterator(m_children.begin()), + children_iterator(m_children.end())); + } // private: void add_child(subgraph* child) { m_children.push_back(child); } @@ -162,8 +186,8 @@ namespace boost { typedef typename property_map::type EdgeIndexMap; typedef typename property_traits::value_type edge_index_type; - std::vector m_global_edge; // local -> global - std::map m_local_edge; // global -> local + std::vector m_global_edge; // local -> global + std::map m_local_edge; // global -> local edge_index_type m_edge_counter; // for generating unique edge indices edge_descriptor @@ -174,9 +198,8 @@ namespace boost { bool inserted; tie(e_local, inserted) = add_edge(u_local, v_local, m_graph); put(edge_index, m_graph, e_local, m_edge_counter++); - m_global_edge.push_back(get(edge_index, m_graph, e_global)); - m_local_edge[get(edge_index, this->root(), e_global)] - = get(edge_index, m_graph, e_local); + m_global_edge.push_back(e_global); + m_local_edge[get(edge_index, this->root(), e_global)] = e_local; return e_local; } @@ -531,38 +554,66 @@ namespace boost { //=========================================================================== // Functions required by the PropertyGraph concept - template + namespace detail { + + template + struct property_map_ref { + template + struct bind { + typedef ValueType type; + typedef ValueType const_type; + }; + }; + template <> + struct property_map_ref { + template + struct bind { + typedef ValueType& type; + typedef const ValueType& const_type; + }; + }; + + } // namespace detail + + template class subgraph_property_map : public put_get_at_helper< typename property_traits< - typename property_map::type + typename property_map::type >::value_type, - subgraph_property_map > + subgraph_property_map > { - typedef typename property_map::type PropertyMap; + typedef typename property_map::type PropertyMap; public: + typedef typename PropertyMap::category category; typedef typename property_traits::value_type value_type; typedef Key key_type; + typedef typename detail::property_map_ref:: + template bind Ref; + typedef typename Ref::type ref_type; + typedef typename Ref::const_type const_ref_type; + subgraph_property_map() { } - subgraph_property_map(subgraph& g) - : m_g(&g), m_pmap(get(Property, g.root())) { } + subgraph_property_map(const subgraph& g) + : m_g(&const_cast&>(g)), + m_pmap(get(PropertyTag(), g.root().m_graph)) { } - inline value_type& operator[](key_type e_local) { + inline ref_type operator[](key_type e_local) { if (m_g->m_parent == 0) return m_pmap[e_local]; else return m_pmap[m_g->local_to_global(e_local)]; } - inline const value_type& operator[](key_type e_local) const { + inline const_ref_type operator[](key_type e_local) const { if (m_g->m_parent == 0) return m_pmap[e_local]; else return m_pmap[m_g->local_to_global(e_local)]; } subgraph* m_g; - ProperyMap m_pmap; + PropertyMap m_pmap; }; namespace detail { @@ -570,7 +621,7 @@ namespace boost { struct subgraph_vertex_property_selector { template struct bind { - typedef subgraph_property_map type; typedef type const_type; }; @@ -579,7 +630,7 @@ namespace boost { struct subgraph_edge_property_selector { template struct bind { - typedef subgraph_property_map type; typedef type const_type; }; @@ -598,28 +649,28 @@ namespace boost { }; template - typename property_map::type + typename property_map< subgraph, Property>::type get(Property, subgraph& g) { - typedef typename property_map::type PMap; + typedef typename property_map< subgraph, Property>::type PMap; return PMap(g); } - template - typename property_map::const_type + template + typename property_map< subgraph, Property>::const_type get(Property, const subgraph& g) { - typedef typename property_map::const_type PMap; + typedef typename property_map< subgraph, Property>::const_type PMap; return PMap(g); } template typename property_traits< - typename property_map::const_type + typename property_map< subgraph, Property>::const_type >::value_type get(Property, const subgraph& g, const Key& k) { - typedef typename property_map::const_type PMap; + typedef typename property_map< subgraph, Property>::const_type PMap; PMap pmap(g); return pmap[k]; } @@ -628,12 +679,25 @@ namespace boost { void put(Property, const subgraph& g, const Key& k, const Value& val) { - typedef typename property_map::const_type PMap; + typedef typename property_map< subgraph, Property>::const_type PMap; PMap pmap(g); pmap[k] = val; } - + template + inline + typename graph_property::type& + get_property(subgraph& g, Tag tag) { + return get_property(g.m_graph, tag); + } + + template + inline + const typename graph_property::type& + get_property(const subgraph& g, Tag tag) { + return get_property(g.m_graph, tag); + } + } // namespace boost #endif // BOOST_SUBGRAPH_HPP