lemon/graph_writer.h
changeset 2292 38d985e82205
parent 2083 f50c8c191cbd
child 2386 81b47fc5c444
equal deleted inserted replaced
11:32418a05fddc 12:f8e46a97c40c
    34   /// \addtogroup lemon_io
    34   /// \addtogroup lemon_io
    35   /// @{
    35   /// @{
    36 
    36 
    37   /// \brief The graph writer class.
    37   /// \brief The graph writer class.
    38   ///
    38   ///
    39   /// The \c GraphWriter class provides the graph output. 
    39   /// The \c GraphWriter class provides the graph output.  Before you
    40   /// Before you read this documentation it might be useful to read the general
    40   /// read this documentation it might be useful to read the general
    41   /// description of  \ref graph-io-page "Graph Input-Output".
    41   /// description of \ref graph-io-page "Graph Input-Output".
    42   ///
    42   ///
    43   /// To write a graph
    43   /// To write a graph you should first give writing commands to the
    44   /// you should first give writing commands to the writer. You can declare
    44   /// writer. You can declare write commands as \c NodeMap or \c
    45   /// write commands as \c NodeMap or \c EdgeMap writing and labeled Node and
    45   /// EdgeMap writing and labeled Node and Edge writing.
    46   /// Edge writing.
       
    47   ///
    46   ///
    48   ///\code
    47   ///\code
    49   /// GraphWriter<ListGraph> writer(std::cout, graph);
    48   /// GraphWriter<ListGraph> writer(std::cout, graph);
    50   ///\endcode
    49   ///\endcode
    51   ///
    50   ///
    52   /// The \c writeNodeMap() function declares a \c NodeMap writing 
    51   /// The \c writeNodeMap() function declares a \c NodeMap writing
    53   /// command in the \c GraphWriter. You should give as parameter 
    52   /// command in the \c GraphWriter. You should give as parameter the
    54   /// the name of the map and the map object. The NodeMap writing 
    53   /// name of the map and the map object. The NodeMap writing command
    55   /// command with name "label" should write a unique map because it 
    54   /// with name "label" should write a unique map because it is
    56   /// is regarded as label map (such a map is essential if the graph has edges).
    55   /// regarded as label map (such a map is essential if the graph has
       
    56   /// edges).
    57   ///
    57   ///
    58   ///\code
    58   ///\code
    59   /// IdMap<ListGraph, Node> nodeLabelMap;
    59   /// IdMap<ListGraph, Node> nodeLabelMap;
    60   /// writer.writeNodeMap("label", nodeLabelMap);
    60   /// writer.writeNodeMap("label", nodeLabelMap);
    61   ///
    61   ///
   279     EdgeWriter<Graph> edge_writer;
   279     EdgeWriter<Graph> edge_writer;
   280     
   280     
   281     AttributeWriter<WriterTraits> attribute_writer;
   281     AttributeWriter<WriterTraits> attribute_writer;
   282   };
   282   };
   283 
   283 
   284 
       
   285 
       
   286   /// \brief Write a graph to the output.
       
   287   ///
       
   288   /// It is a helper function to write a graph to the given output
       
   289   /// stream. It gives back a GraphWriter object and this object
       
   290   /// can write more maps, labeled nodes and edges and attributes.
       
   291   /// \warning Do not forget to call the \c run() function.
       
   292   ///
       
   293   /// \param os The output stream.
       
   294   /// \param g The graph.
       
   295   template <typename Graph>
       
   296   GraphWriter<Graph> graphWriter(std::ostream& os, const Graph &g) {
       
   297     return GraphWriter<Graph>(os, g);
       
   298   }
       
   299 
       
   300   /// \brief Write a graph to the output.
       
   301   ///
       
   302   /// It is a helper function to write a graph to the given output
       
   303   /// file. It gives back a GraphWriter object and this object
       
   304   /// can write more maps, labeled nodes and edges and attributes.
       
   305   /// \warning Do not forget to call the \c run() function.
       
   306   ///
       
   307   /// \param fn The filename.
       
   308   /// \param g The graph.
       
   309   template <typename Graph>
       
   310   GraphWriter<Graph> graphWriter(const std::string& fn, const Graph &g) {
       
   311     return GraphWriter<Graph>(fn, g);
       
   312   }
       
   313 
   284 
   314   /// \brief The undirected graph writer class.
   285   /// \brief The undirected graph writer class.
   315   ///
   286   ///
   316   /// The \c UGraphWriter class provides the ugraph output. To write 
   287   /// The \c UGraphWriter class provides the ugraph output. To write 
   317   /// a graph you should first give writing commands to the writer. You can 
   288   /// a graph you should first give writing commands to the writer. You can 
   436 	delete writer;
   407 	delete writer;
   437     }
   408     }
   438 
   409 
   439     /// \brief Issue a new node map writing command to the writer.
   410     /// \brief Issue a new node map writing command to the writer.
   440     ///
   411     ///
   441    /// This function issues a new <i> node map writing command</i> to the writer.
   412     /// This function issues a new <i> node map writing command</i> to
       
   413     /// the writer.
   442     template <typename Map>
   414     template <typename Map>
   443     UGraphWriter& writeNodeMap(std::string name, const Map& map) {
   415     UGraphWriter& writeNodeMap(std::string name, const Map& map) {
   444       nodeset_writer.writeNodeMap(name, map);
   416       nodeset_writer.writeNodeMap(name, map);
   445       return *this;
   417       return *this;
   446     }
   418     }
   447 
   419 
   448     /// \brief Issue a new node map writing command to the writer.
   420     /// \brief Issue a new node map writing command to the writer.
   449     ///
   421     ///
   450    /// This function issues a new <i> node map writing command</i> to the writer.
   422     /// This function issues a new <i> node map writing command</i> to
       
   423     /// the writer.
   451     template <typename Writer, typename Map>
   424     template <typename Writer, typename Map>
   452     UGraphWriter& writeNodeMap(std::string name, const Map& map, 
   425     UGraphWriter& writeNodeMap(std::string name, const Map& map, 
   453 			      const Writer& writer = Writer()) {
   426 			      const Writer& writer = Writer()) {
   454       nodeset_writer.writeNodeMap(name, map, writer);
   427       nodeset_writer.writeNodeMap(name, map, writer);
   455       return *this;
   428       return *this;
   456     }
   429     }
   457 
   430 
   458     /// \brief Issue a new edge map writing command to the writer.
   431     /// \brief Issue a new edge map writing command to the writer.
   459     ///
   432     ///
   460    /// This function issues a new <i> edge map writing command</i> to the writer.
   433     /// This function issues a new <i> edge map writing command</i> to
       
   434     /// the writer.
   461     template <typename Map>
   435     template <typename Map>
   462     UGraphWriter& writeEdgeMap(std::string name, const Map& map) { 
   436     UGraphWriter& writeEdgeMap(std::string name, const Map& map) { 
   463       u_edgeset_writer.writeEdgeMap(name, map);
   437       u_edgeset_writer.writeEdgeMap(name, map);
   464       return *this;
   438       return *this;
   465     }
   439     }
   466 
   440 
   467     /// \brief Issue a new edge map writing command to the writer.
   441     /// \brief Issue a new edge map writing command to the writer.
   468     ///
   442     ///
   469    /// This function issues a new <i> edge map writing command</i> to the writer.
   443     /// This function issues a new <i> edge map writing command</i> to
       
   444     /// the writer.
   470     template <typename Writer, typename Map>
   445     template <typename Writer, typename Map>
   471     UGraphWriter& writeEdgeMap(std::string name, const Map& map,
   446     UGraphWriter& writeEdgeMap(std::string name, const Map& map,
   472 				   const Writer& writer = Writer()) {
   447 				   const Writer& writer = Writer()) {
   473       u_edgeset_writer.writeEdgeMap(name, map, writer);
   448       u_edgeset_writer.writeEdgeMap(name, map, writer);
   474       return *this;
   449       return *this;
   575       u_edgeset_writer.writeLabel(os, item);
   550       u_edgeset_writer.writeLabel(os, item);
   576     } 
   551     } 
   577 
   552 
   578     /// \brief Write the label of the given undirected edge.
   553     /// \brief Write the label of the given undirected edge.
   579     ///
   554     ///
   580     /// It writes the label of the given undirected edge. If there was written 
   555     /// It writes the label of the given undirected edge. If there was
   581     /// an "label" named edge map then it will write the map value belonging to 
   556     /// written an "label" named edge map then it will write the map
   582     /// the edge.
   557     /// value belonging to the edge.
   583     void writeLabel(std::ostream& os, const UEdge& item) const {
   558     void writeLabel(std::ostream& os, const UEdge& item) const {
   584       u_edgeset_writer.writeLabel(os, item);
   559       u_edgeset_writer.writeLabel(os, item);
   585     } 
   560     } 
   586 
   561 
   587 
   562 
   597     UEdgeWriter<Graph> u_edge_writer;
   572     UEdgeWriter<Graph> u_edge_writer;
   598     
   573     
   599     AttributeWriter<WriterTraits> attribute_writer;
   574     AttributeWriter<WriterTraits> attribute_writer;
   600   };
   575   };
   601 
   576 
   602   /// \brief Write an undirected graph to the output.
       
   603   ///
       
   604   /// It is a helper function to write an undirected graph to the given output
       
   605   /// stream. It gives back an UGraphWriter object and this object
       
   606   /// can write more maps, labeled nodes and edges and attributes.
       
   607   /// \warning Do not forget to call the \c run() function.
       
   608   ///
       
   609   /// \param os The output stream.
       
   610   /// \param g The graph.
       
   611   template <typename Graph>
       
   612   UGraphWriter<Graph> uGraphWriter(std::ostream& os, const Graph &g) {
       
   613     return UGraphWriter<Graph>(os, g);
       
   614   }
       
   615 
       
   616   /// \brief Write an undirected graph to the output.
       
   617   ///
       
   618   /// It is a helper function to write an undirected graph to the given output
       
   619   /// file. It gives back an UGraphWriter object and this object
       
   620   /// can write more maps, labeled nodes, edges, undirected edges and 
       
   621   /// attributes.
       
   622   ///
       
   623   /// \warning Do not forget to call the \c run() function.
       
   624   ///
       
   625   /// \param fn The output file.
       
   626   /// \param g The graph.
       
   627   template <typename Graph>
       
   628   UGraphWriter<Graph> uGraphWriter(const std::string& fn, 
       
   629 					   const Graph &g) {
       
   630     return UGraphWriter<Graph>(fn, g);
       
   631   }
       
   632 
       
   633   /// @}
   577   /// @}
   634 
   578 
   635 }
   579 }
   636 
   580 
   637 #endif
   581 #endif