Re: [Boost-bugs] [Boost C++ Libraries] #3259: write_graphviz requires more concepts than the documentation states

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #3259: write_graphviz requires more concepts than the documentation states
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-07-16 10:01:26


#3259: write_graphviz requires more concepts than the documentation states
--------------------------+-------------------------------------------------
 Reporter: anonymous | Owner: asutton
     Type: Bugs | Status: new
Milestone: Boost 1.40.0 | Component: graph
  Version: Boost 1.39.0 | Severity: Cosmetic
 Keywords: |
--------------------------+-------------------------------------------------

Comment(by richi@…):

 Here's the code that I had in mind :

 template <typename EdgeListGraph, typename VertexPropertiesWriter,
         typename EdgePropertiesWriter, typename GraphPropertiesWriter,
         typename VertexID>
 static inline void write_graphviz_dispatch(std::ostream& out, const
 EdgeListGraph& g,
         VertexPropertiesWriter vpw,
         EdgePropertiesWriter epw,
         GraphPropertiesWriter gpw,
         VertexID vertex_id,
         edge_list_graph_tag)
 {
         typedef typename graph_traits<EdgeListGraph>::directed_category
 cat_type;
         typedef graphviz_io_traits<cat_type> Traits;
         std::string name = "G";
         out << Traits::name() << " " << name << " {" << std::endl;

         gpw(out); //print graph properties

         typename graph_traits<EdgeListGraph>::vertex_iterator i, end;

         for(tie(i,end) = vertices(g); i != end; ++i) {
                 out << get(vertex_id, *i);
                 vpw(out, *i); //print vertex attributes
                 out << ";" << std::endl;
         }
         typename graph_traits<EdgeListGraph>::edge_iterator ei, edge_end;
         for(tie(ei, edge_end) = edges(g); ei != edge_end; ++ei) {
                 out << get(vertex_id, source(*ei, g)) <<
 Traits::delimiter() << get(vertex_id, target(*ei, g)) << " ";
                 epw(out, *ei); //print edge attributes
                 out << ";" << std::endl;
         }
         out << "}" << std::endl;
 }


 template <typename VertexListGraph, typename VertexPropertiesWriter,
         typename EdgePropertiesWriter, typename GraphPropertiesWriter,
         typename VertexID>
 inline void write_graphviz_dispatch(std::ostream& out, const
 VertexListGraph& g,
         VertexPropertiesWriter vpw,
         EdgePropertiesWriter epw,
         GraphPropertiesWriter gpw,
         VertexID vertex_id,
         vertex_list_graph_tag)
 {
         typedef typename graph_traits<VertexListGraph>::directed_category
 cat_type;
         typedef graphviz_io_traits<cat_type> Traits;
         std::string name = "G";
         out << Traits::name() << " " << name << " {" << std::endl;

         gpw(out); //print graph properties

         typename graph_traits<VertexListGraph>::vertex_iterator i, end;

         for(tie(i,end) = vertices(g); i != end; ++i) {
                 out << get(vertex_id, *i);
                 vpw(out, *i); //print vertex attributes
                 out << ";" << std::endl;
         }

         for(tie(i,end) = vertices(g); i != end; ++i)
         {
                 typename graph_traits<VertexListGraph>::out_edge_iterator
 ei, edge_end;
                 for(tie(ei, edge_end) = out_edges(*i, g); ei != edge_end;
 ++ei) {
                         out << get(vertex_id, source(*ei, g)) <<
 Traits::delimiter() << get(vertex_id, target(*ei, g)) << " ";
                         epw(out, *ei); //print edge attributes
                         out << ";" << std::endl;
                 }
         }
         out << "}" << std::endl;
 }

 // dispatcher
 template <typename Graph, typename VertexPropertiesWriter,
         typename EdgePropertiesWriter, typename GraphPropertiesWriter,
         typename VertexID>
 inline void write_graphviz(std::ostream& out, const Graph& g,
         VertexPropertiesWriter vpw,
         EdgePropertiesWriter epw,
         GraphPropertiesWriter gpw,
         VertexID vertex_id)
 {
         typedef typename graph_traits<Graph>::traversal_category cat_type;
         function_requires<IncidenceGraphConcept<Graph> >();

         write_graphviz_dispatch(out, g, vpw, epw, gpw, vertex_id,
 cat_type());
 }


 works for me, but it's not extensively tested...

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/3259#comment:1>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:00 UTC