COIN-OR::LEMON - Graph Library

source: lemon-0.x/lemon/graph_writer.h @ 1955:daca31868d70

Last change on this file since 1955:daca31868d70 was 1946:17eb3eaad9f8, checked in by Alpar Juttner, 18 years ago
  • workaround for a Doxygen 1.4.6 bug
  • other doc fixes
File size: 21.4 KB
RevLine 
[1137]1/* -*- C++ -*-
[1435]2 * lemon/graph_writer.h - Part of LEMON, a generic C++ optimization library
[1137]3 *
[1875]4 * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
[1359]5 * (Egervary Research Group on Combinatorial Optimization, EGRES).
[1137]6 *
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
10 *
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
13 * purpose.
14 *
15 */
16
[1287]17///\ingroup io_group
[1137]18///\file
[1287]19///\brief Lemon Graph Format writer.
[1534]20///
[1137]21
[1214]22#ifndef LEMON_GRAPH_WRITER_H
23#define LEMON_GRAPH_WRITER_H
[1137]24
25#include <iostream>
26
27#include <lemon/error.h>
[1409]28#include <lemon/lemon_writer.h>
[1137]29
30namespace lemon {
31
[1333]32  /// \addtogroup io_group
33  /// @{
34
[1137]35  /// \brief The graph writer class.
36  ///
[1526]37  /// The \c GraphWriter class provides the graph output.
38  /// Before you read this documentation it might be useful to read the general
39  /// description of  \ref graph-io-page "Graph Input-Output".
[1540]40  ///
[1534]41  /// If you don't need very sophisticated
42  /// behaviour then you can use the versions of the public function
43  /// \ref writeGraph() to output a graph (or a max flow instance etc).
44  ///
[1526]45  /// To write a graph
46  /// you should first give writing commands to the writer. You can declare
47  /// write commands as \c NodeMap or \c EdgeMap writing and labeled Node and
[1333]48  /// Edge writing.
49  ///
[1946]50  ///\code
[1333]51  /// GraphWriter<ListGraph> writer(std::cout, graph);
[1946]52  ///\endcode
[1333]53  ///
[1394]54  /// The \c writeNodeMap() function declares a \c NodeMap writing
55  /// command in the \c GraphWriter. You should give as parameter
56  /// the name of the map and the map object. The NodeMap writing
[1901]57  /// command with name "label" should write a unique map because it
58  /// is regarded as label map (such a map is essential if the graph has edges).
[1333]59  ///
[1946]60  ///\code
[1901]61  /// IdMap<ListGraph, Node> nodeLabelMap;
62  /// writer.writeNodeMap("label", nodeLabelMap);
[1333]63  ///
[1421]64  /// writer.writeNodeMap("coords", coords);
[1394]65  /// writer.writeNodeMap("color", colorMap);
[1946]66  ///\endcode
[1333]67  ///
[1394]68  /// With the \c writeEdgeMap() member function you can give an edge map
[1333]69  /// writing command similar to the NodeMaps.
70  ///
[1946]71  ///\code
[1333]72  /// DescriptorMap<ListGraph, Edge, ListGraph::EdgeMap<int> >
73  ///   edgeDescMap(graph);
[1394]74  /// writer.writeEdgeMap("descriptor", edgeDescMap);
[1333]75  ///
[1394]76  /// writer.writeEdgeMap("weight", weightMap);
77  /// writer.writeEdgeMap("label", labelMap);
[1946]78  ///\endcode
[1333]79  ///
[1394]80  /// With \c writeNode() and \c writeEdge() functions you can
[1526]81  /// point out Nodes and Edges in the graph. For example, you can
82  /// write out the source and target of a maximum flow instance.
[1333]83  ///
[1946]84  ///\code
[1394]85  /// writer.writeNode("source", sourceNode);
86  /// writer.writeNode("target", targetNode);
[1333]87  ///
[1394]88  /// writer.writeEdge("observed", edge);
[1946]89  ///\endcode
[1333]90  ///
91  /// After you give all write commands you must call the \c run() member
[1526]92  /// function, which executes all the writing commands.
[1333]93  ///
[1946]94  ///\code
[1333]95  /// writer.run();
[1946]96  ///\endcode
[1333]97  ///
[1287]98  /// \see DefaultWriterTraits
99  /// \see QuotedStringWriter
[1333]100  /// \see IdMap
101  /// \see DescriptorMap
[1421]102  /// \see \ref GraphReader
[1138]103  /// \see \ref graph-io-page
[1333]104  /// \author Balazs Dezso
[1137]105  template <typename _Graph, typename _WriterTraits = DefaultWriterTraits>
106  class GraphWriter {
107  public:
108   
109    typedef _Graph Graph;
110    typedef typename Graph::Node Node;
111    typedef typename Graph::Edge Edge;
112
113    typedef _WriterTraits WriterTraits;
[1409]114
[1137]115    /// \brief Construct a new GraphWriter.
116    ///
[1526]117    /// This function constructs a new GraphWriter to write the given graph
[1409]118    /// to the given stream.
[1208]119    GraphWriter(std::ostream& _os, const Graph& _graph)
[1409]120      : writer(new LemonWriter(_os)), own_writer(true),
[1421]121        nodeset_writer(*writer, _graph, std::string()),
122        edgeset_writer(*writer, _graph, nodeset_writer, std::string()),
[1409]123        node_writer(*writer, nodeset_writer, std::string()),
124        edge_writer(*writer, edgeset_writer, std::string()),
125        attribute_writer(*writer, std::string()) {}
[1137]126
[1409]127    /// \brief Construct a new GraphWriter.
128    ///
[1526]129    /// This function constructs a new GraphWriter to write the given graph
[1409]130    /// to the given file.
131    GraphWriter(const std::string& _filename, const Graph& _graph)
132      : writer(new LemonWriter(_filename)), own_writer(true),
[1421]133        nodeset_writer(*writer, _graph, std::string()),
134        edgeset_writer(*writer, _graph, nodeset_writer, std::string()),
[1409]135        node_writer(*writer, nodeset_writer, std::string()),
136        edge_writer(*writer, edgeset_writer, std::string()),
137        attribute_writer(*writer, std::string()) {}
138
139    /// \brief Construct a new GraphWriter.
140    ///
[1526]141    /// This function constructs a new GraphWriter to write the given graph
142    /// to the given LemonReader.
[1409]143    GraphWriter(LemonWriter& _writer, const Graph& _graph)
144      : writer(_writer), own_writer(false),
[1421]145        nodeset_writer(*writer, _graph, std::string()),
146        edgeset_writer(*writer, _graph, nodeset_writer, std::string()),
[1409]147        node_writer(*writer, nodeset_writer, std::string()),
148        edge_writer(*writer, edgeset_writer, std::string()),
149        attribute_writer(*writer, std::string()) {}
[1137]150
151    /// \brief Destruct the graph writer.
152    ///
[1526]153    /// This function destructs the graph writer.
[1137]154    ~GraphWriter() {
[1409]155      if (own_writer)
156        delete writer;
[1137]157    }
158
[1526]159    /// \brief Issue a new node map writing command for the writer.
[1137]160    ///
[1526]161   /// This function issues a new <i> node map writing command</i> to the writer.
[1137]162    template <typename Map>
[1394]163    GraphWriter& writeNodeMap(std::string name, const Map& map) {
[1421]164      nodeset_writer.writeNodeMap(name, map);
[1409]165      return *this;
[1137]166    }
167
[1540]168
[1526]169    /// \brief Issue a new node map writing command for the writer.
[1137]170    ///
[1526]171   /// This function issues a new <i> node map writing command</i> to the writer.
[1137]172    template <typename Writer, typename Map>
[1394]173    GraphWriter& writeNodeMap(std::string name, const Map& map,
[1421]174                              const Writer& writer = Writer()) {
175      nodeset_writer.writeNodeMap(name, map, writer);
[1137]176      return *this;
177    }
178
179
[1526]180    /// \brief Issue a new edge map writing command for the writer.
[1137]181    ///
[1526]182   /// This function issues a new <i> edge map writing command</i> to the writer.
[1137]183    template <typename Map>
[1394]184    GraphWriter& writeEdgeMap(std::string name, const Map& map) {
[1421]185      edgeset_writer.writeEdgeMap(name, map);
[1409]186      return *this;
[1137]187    }
188
189
[1526]190    /// \brief Issue a new edge map writing command for the writer.
[1137]191    ///
[1526]192   /// This function issues a new <i> edge map writing command</i> to the writer.
[1137]193    template <typename Writer, typename Map>
[1409]194    GraphWriter& writeEdgeMap(std::string name, const Map& map,
[1421]195                              const Writer& writer = Writer()) {
196      edgeset_writer.writeEdgeMap(name, map, writer);
[1137]197      return *this;
198    }
199
[1526]200    /// \brief Issue a new labeled node writing command to the writer.
[1137]201    ///
[1526]202    /// This function issues a new <i> labeled node writing command</i>
203    /// to the writer.
[1394]204    GraphWriter& writeNode(std::string name, const Node& node) {
[1409]205      node_writer.writeNode(name, node);
[1137]206      return *this;
207    }
208
[1526]209    /// \brief Issue a new labeled edge writing command to the writer.
[1137]210    ///
[1526]211    /// This function issues a new <i> labeled edge writing command</i>
212    /// to the writer.
[1394]213    GraphWriter& writeEdge(std::string name, const Edge& edge) {
[1409]214      edge_writer.writeEdge(name, edge);
215    }
216
[1526]217    /// \brief Issue a new attribute writing command.
[1409]218    ///
[1526]219    /// This function issues a new <i> attribute writing command</i>
220    /// to the writer.
[1409]221    template <typename Value>
222    GraphWriter& writeAttribute(std::string name, const Value& value) {
223      attribute_writer.writeAttribute(name, value);
224      return *this;
225    }
226   
[1526]227    /// \brief Issue a new attribute writing command.
[1409]228    ///
[1526]229    /// This function issues a new <i> attribute writing command</i>
230    /// to the writer.
[1409]231    template <typename Writer, typename Value>
232    GraphWriter& writeAttribute(std::string name, const Value& value,
233                               const Writer& writer) {
234      attribute_writer.writeAttribute<Writer>(name, value, writer);
[1137]235      return *this;
236    }
237
[1409]238    /// \brief Conversion operator to LemonWriter.
239    ///
[1526]240    /// Conversion operator to LemonWriter. It makes possible
[1409]241    /// to access the encapsulated \e LemonWriter, this way
242    /// you can attach to this writer new instances of
[1540]243    /// \e LemonWriter::SectionWriter. For more details see
244    /// the \ref rwbackground "Background of Reading and Writing".
[1409]245    operator LemonWriter&() {
246      return *writer;
[1396]247    }
248
[1526]249    /// \brief Executes the writing commands.
[1137]250    ///
[1526]251    /// Executes the writing commands.
[1409]252    void run() {
253      writer->run();
[1137]254    }
255
[1901]256    /// \brief Write the label of the given node.
[1429]257    ///
[1901]258    /// It writes the label of the given node. If there was written an "label"
[1526]259    /// named node map then it will write the map value belonging to the node.
[1901]260    void writeLabel(std::ostream& os, const Node& item) const {
261      nodeset_writer.writeLabel(os, item);
[1429]262    }
263
[1901]264    /// \brief Write the label of the given edge.
[1429]265    ///
[1901]266    /// It writes the label of the given edge. If there was written an "label"
[1526]267    /// named edge map then it will write the map value belonging to the edge.
[1901]268    void writeLabel(std::ostream& os, const Edge& item) const {
269      edgeset_writer.writeLabel(os, item);
[1429]270    }
271
[1137]272  private:
273
[1409]274    LemonWriter* writer;
275    bool own_writer;
[1137]276
[1409]277    NodeSetWriter<Graph, WriterTraits> nodeset_writer;
278    EdgeSetWriter<Graph, WriterTraits> edgeset_writer;
279
280    NodeWriter<Graph> node_writer;
281    EdgeWriter<Graph> edge_writer;
282   
283    AttributeWriter<WriterTraits> attribute_writer;
[1137]284  };
285
[1409]286
[1744]287
[1333]288  /// \brief Write a graph to the output.
289  ///
[1744]290  /// It is a helper function to write a graph to the given output
291  /// stream. It gives back a GraphWriter object and this object
292  /// can write more maps, labeled nodes and edges and attributes.
293  /// \warning Do not forget to call the \c run() function.
[1534]294  ///
[1333]295  /// \param os The output stream.
296  /// \param g The graph.
[1744]297  template <typename Graph>
298  GraphWriter<Graph> graphWriter(std::ostream& os, const Graph &g) {
299    return GraphWriter<Graph>(os, g);
[1208]300  }
301
[1744]302  /// \brief Write a graph to the output.
[1333]303  ///
[1744]304  /// It is a helper function to write a graph to the given output
305  /// file. It gives back a GraphWriter object and this object
306  /// can write more maps, labeled nodes and edges and attributes.
307  /// \warning Do not forget to call the \c run() function.
[1534]308  ///
[1744]309  /// \param fn The filename.
[1333]310  /// \param g The graph.
[1744]311  template <typename Graph>
312  GraphWriter<Graph> graphWriter(const std::string& fn, const Graph &g) {
313    return GraphWriter<Graph>(fn, g);
[1208]314  }
315
[1421]316  /// \brief The undirected graph writer class.
317  ///
[1909]318  /// The \c UGraphWriter class provides the ugraph output. To write
[1526]319  /// a graph you should first give writing commands to the writer. You can
[1909]320  /// declare write command as \c NodeMap, \c EdgeMap or \c UEdgeMap
321  /// writing and labeled Node, Edge or UEdge writing.
[1421]322  ///
[1946]323  ///\code
[1909]324  /// UGraphWriter<ListUGraph> writer(std::cout, graph);
[1946]325  ///\endcode
[1421]326  ///
327  /// The \c writeNodeMap() function declares a \c NodeMap writing
[1909]328  /// command in the \c UGraphWriter. You should give as parameter
[1421]329  /// the name of the map and the map object. The NodeMap writing
[1901]330  /// command with name "label" should write a unique map because it
331  /// is regarded as label map.
[1421]332  ///
[1946]333  ///\code
[1909]334  /// IdMap<ListUGraph, Node> nodeLabelMap;
[1901]335  /// writer.writeNodeMap("label", nodeLabelMap);
[1421]336  ///
337  /// writer.writeNodeMap("coords", coords);
338  /// writer.writeNodeMap("color", colorMap);
[1946]339  ///\endcode
[1421]340  ///
[1909]341  /// With the \c writeUEdgeMap() member function you can give an
[1421]342  /// undirected edge map writing command similar to the NodeMaps.
343  ///
[1946]344  ///\code
[1421]345  /// DescriptorMap<ListGraph, Edge, ListGraph::EdgeMap<int> >
346  ///   edgeDescMap(graph);
[1909]347  /// writer.writeUEdgeMap("descriptor", edgeDescMap);
[1421]348  ///
[1909]349  /// writer.writeUEdgeMap("weight", weightMap);
350  /// writer.writeUEdgeMap("label", labelMap);
[1946]351  ///\endcode
[1421]352  ///
353  /// The EdgeMap handling is just a syntactical sugar. It writes
354  /// two undirected edge map with '+' and '-' prefix in the name.
355  ///
[1946]356  ///\code
[1421]357  /// writer.writeEdgeMap("capacity", capacityMap);
[1946]358  ///\endcode
[1421]359  ///
360  ///
[1909]361  /// With \c writeNode() and \c writeUEdge() functions you can
[1526]362  /// designate nodes and undirected edges in the graph. For example, you can
[1421]363  /// write out the source and target of the graph.
364  ///
[1946]365  ///\code
[1421]366  /// writer.writeNode("source", sourceNode);
367  /// writer.writeNode("target", targetNode);
368  ///
[1909]369  /// writer.writeUEdge("observed", uEdge);
[1946]370  ///\endcode
[1421]371  ///
372  /// After you give all write commands you must call the \c run() member
[1526]373  /// function, which executes all the writing commands.
[1421]374  ///
[1946]375  ///\code
[1421]376  /// writer.run();
[1946]377  ///\endcode
[1421]378  ///
379  /// \see DefaultWriterTraits
380  /// \see QuotedStringWriter
381  /// \see IdMap
382  /// \see DescriptorMap
383  /// \see \ref GraphWriter
384  /// \see \ref graph-io-page
385  /// \author Balazs Dezso
386  template <typename _Graph, typename _WriterTraits = DefaultWriterTraits>
[1909]387  class UGraphWriter {
[1421]388  public:
389   
390    typedef _Graph Graph;
391    typedef typename Graph::Node Node;
392    typedef typename Graph::Edge Edge;
[1909]393    typedef typename Graph::UEdge UEdge;
[1421]394
395    typedef _WriterTraits WriterTraits;
396
[1909]397    /// \brief Construct a new UGraphWriter.
[1421]398    ///
[1909]399    /// Construct a new UGraphWriter. It writes the given graph
[1421]400    /// to the given stream.
[1909]401    UGraphWriter(std::ostream& _os, const Graph& _graph)
[1421]402      : writer(new LemonWriter(_os)), own_writer(true),
403        nodeset_writer(*writer, _graph, std::string()),
[1909]404        u_edgeset_writer(*writer, _graph, nodeset_writer, std::string()),
[1421]405        node_writer(*writer, nodeset_writer, std::string()),
[1909]406        u_edge_writer(*writer, u_edgeset_writer, std::string()),
[1421]407        attribute_writer(*writer, std::string()) {}
408
[1909]409    /// \brief Construct a new UGraphWriter.
[1421]410    ///
[1909]411    /// Construct a new UGraphWriter. It writes the given graph
[1421]412    /// to the given file.
[1909]413    UGraphWriter(const std::string& _filename, const Graph& _graph)
[1421]414      : writer(new LemonWriter(_filename)), own_writer(true),
415        nodeset_writer(*writer, _graph, std::string()),
[1909]416        u_edgeset_writer(*writer, _graph, nodeset_writer, std::string()),
[1421]417        node_writer(*writer, nodeset_writer, std::string()),
[1909]418        u_edge_writer(*writer, u_edgeset_writer, std::string()),
[1421]419        attribute_writer(*writer, std::string()) {}
420
[1909]421    /// \brief Construct a new UGraphWriter.
[1421]422    ///
[1909]423    /// Construct a new UGraphWriter. It writes the given graph
[1421]424    /// to given LemonReader.
[1909]425    UGraphWriter(LemonWriter& _writer, const Graph& _graph)
[1421]426      : writer(_writer), own_writer(false),
427        nodeset_writer(*writer, _graph, std::string()),
[1909]428        u_edgeset_writer(*writer, _graph, nodeset_writer, std::string()),
[1421]429        node_writer(*writer, nodeset_writer, std::string()),
[1909]430        u_edge_writer(*writer, u_edgeset_writer, std::string()),
[1421]431        attribute_writer(*writer, std::string()) {}
432
433    /// \brief Destruct the graph writer.
434    ///
435    /// Destruct the graph writer.
[1909]436    ~UGraphWriter() {
[1421]437      if (own_writer)
438        delete writer;
439    }
440
[1526]441    /// \brief Issue a new node map writing command to the writer.
[1421]442    ///
[1526]443   /// This function issues a new <i> node map writing command</i> to the writer.
[1421]444    template <typename Map>
[1909]445    UGraphWriter& writeNodeMap(std::string name, const Map& map) {
[1421]446      nodeset_writer.writeNodeMap(name, map);
447      return *this;
448    }
449
[1526]450    /// \brief Issue a new node map writing command to the writer.
[1421]451    ///
[1526]452   /// This function issues a new <i> node map writing command</i> to the writer.
[1421]453    template <typename Writer, typename Map>
[1909]454    UGraphWriter& writeNodeMap(std::string name, const Map& map,
[1421]455                              const Writer& writer = Writer()) {
456      nodeset_writer.writeNodeMap(name, map, writer);
457      return *this;
458    }
459
[1526]460    /// \brief Issue a new edge map writing command to the writer.
[1421]461    ///
[1526]462   /// This function issues a new <i> edge map writing command</i> to the writer.
[1421]463    template <typename Map>
[1909]464    UGraphWriter& writeEdgeMap(std::string name, const Map& map) {
465      u_edgeset_writer.writeEdgeMap(name, map);
[1421]466      return *this;
467    }
468
[1526]469    /// \brief Issue a new edge map writing command to the writer.
[1421]470    ///
[1526]471   /// This function issues a new <i> edge map writing command</i> to the writer.
[1421]472    template <typename Writer, typename Map>
[1909]473    UGraphWriter& writeEdgeMap(std::string name, const Map& map,
[1421]474                                   const Writer& writer = Writer()) {
[1909]475      u_edgeset_writer.writeEdgeMap(name, map, writer);
[1421]476      return *this;
477    }
478
[1526]479    /// \brief Issue a new undirected edge map writing command to the writer.
[1421]480    ///
[1526]481    /// This function issues a new <i> undirected edge map writing
482    /// command</i> to the writer.
[1421]483    template <typename Map>
[1909]484    UGraphWriter& writeUEdgeMap(std::string name, const Map& map) {
485      u_edgeset_writer.writeUEdgeMap(name, map);
[1421]486      return *this;
487    }
488
[1526]489    /// \brief Issue a new undirected edge map writing command to the writer.
[1421]490    ///
[1526]491    /// This function issues a new <i> undirected edge map writing
492    /// command</i> to the writer.
[1540]493   template <typename Writer, typename Map>
[1909]494    UGraphWriter& writeUEdgeMap(std::string name, const Map& map,
[1421]495                                        const Writer& writer = Writer()) {
[1909]496      u_edgeset_writer.writeUEdgeMap(name, map, writer);
[1421]497      return *this;
498    }
499
[1526]500    /// \brief Issue a new labeled node writer to the writer.
[1421]501    ///
[1526]502    /// This function issues a new <i> labeled node writing
503    /// command</i> to the writer.
[1909]504    UGraphWriter& writeNode(std::string name, const Node& node) {
[1421]505      node_writer.writeNode(name, node);
506      return *this;
507    }
508
[1526]509    /// \brief Issue a new labeled edge writer to the writer.
[1421]510    ///
[1526]511    /// This function issues a new <i> labeled edge writing
512    /// command</i> to the writer.
[1909]513    UGraphWriter& writeEdge(std::string name, const Edge& edge) {
514      u_edge_writer.writeEdge(name, edge);
[1429]515    }
516
[1526]517    /// \brief Issue a new labeled undirected edge writing command to
518    /// the writer.
[1429]519    ///
[1526]520    /// Issue a new <i>labeled undirected edge writing command</i> to
521    /// the writer.
[1909]522    UGraphWriter& writeUEdge(std::string name, const UEdge& edge) {
523      u_edge_writer.writeUEdge(name, edge);
[1421]524    }
525
[1526]526    /// \brief Issue a new attribute writing command.
[1421]527    ///
[1526]528    /// This function issues a new <i> attribute writing
529    /// command</i> to the writer.
[1421]530    template <typename Value>
[1909]531    UGraphWriter& writeAttribute(std::string name, const Value& value) {
[1421]532      attribute_writer.writeAttribute(name, value);
533      return *this;
534    }
535   
[1526]536    /// \brief Issue a new attribute writing command.
[1421]537    ///
[1526]538    /// This function issues a new <i> attribute writing
539    /// command</i> to the writer.
[1421]540    template <typename Writer, typename Value>
[1909]541    UGraphWriter& writeAttribute(std::string name, const Value& value,
[1421]542                               const Writer& writer) {
543      attribute_writer.writeAttribute<Writer>(name, value, writer);
544      return *this;
545    }
546
547    /// \brief Conversion operator to LemonWriter.
548    ///
[1526]549    /// Conversion operator to LemonWriter. It makes possible
[1421]550    /// to access the encapsulated \e LemonWriter, this way
551    /// you can attach to this writer new instances of
552    /// \e LemonWriter::SectionWriter.
553    operator LemonWriter&() {
554      return *writer;
555    }
556
[1526]557    /// \brief Executes the writing commands.
[1421]558    ///
[1526]559    /// Executes the writing commands.
[1421]560    void run() {
561      writer->run();
562    }
563
[1901]564    /// \brief Write the label of the given node.
[1429]565    ///
[1901]566    /// It writes the label of the given node. If there was written an "label"
[1526]567    /// named node map then it will write the map value belonging to the node.
[1901]568    void writeLabel(std::ostream& os, const Node& item) const {
569      nodeset_writer.writeLabel(os, item);
[1429]570    }
571
[1901]572    /// \brief Write the label of the given edge.
[1429]573    ///
[1901]574    /// It writes the label of the given edge. If there was written an "label"
[1526]575    /// named edge map then it will write the map value belonging to the edge.
[1901]576    void writeLabel(std::ostream& os, const Edge& item) const {
[1909]577      u_edgeset_writer.writeLabel(os, item);
[1429]578    }
579
[1901]580    /// \brief Write the label of the given undirected edge.
[1429]581    ///
[1901]582    /// It writes the label of the given undirected edge. If there was written
583    /// an "label" named edge map then it will write the map value belonging to
[1429]584    /// the edge.
[1909]585    void writeLabel(std::ostream& os, const UEdge& item) const {
586      u_edgeset_writer.writeLabel(os, item);
[1429]587    }
588
589
[1421]590  private:
591
592    LemonWriter* writer;
593    bool own_writer;
594
595    NodeSetWriter<Graph, WriterTraits> nodeset_writer;
[1909]596    UEdgeSetWriter<Graph, WriterTraits> u_edgeset_writer;
[1421]597
598    NodeWriter<Graph> node_writer;
[1909]599    UEdgeWriter<Graph> u_edge_writer;
[1421]600   
601    AttributeWriter<WriterTraits> attribute_writer;
602  };
603
[1534]604  /// \brief Write an undirected graph to the output.
605  ///
[1744]606  /// It is a helper function to write an undirected graph to the given output
[1909]607  /// stream. It gives back an UGraphWriter object and this object
[1744]608  /// can write more maps, labeled nodes and edges and attributes.
609  /// \warning Do not forget to call the \c run() function.
610  ///
[1534]611  /// \param os The output stream.
612  /// \param g The graph.
[1744]613  template <typename Graph>
[1909]614  UGraphWriter<Graph> uGraphWriter(std::ostream& os, const Graph &g) {
615    return UGraphWriter<Graph>(os, g);
[1534]616  }
[1421]617
[1744]618  /// \brief Write an undirected graph to the output.
[1421]619  ///
[1744]620  /// It is a helper function to write an undirected graph to the given output
[1909]621  /// file. It gives back an UGraphWriter object and this object
[1744]622  /// can write more maps, labeled nodes, edges, undirected edges and
623  /// attributes.
624  ///
625  /// \warning Do not forget to call the \c run() function.
626  ///
627  /// \param fn The output file.
[1421]628  /// \param g The graph.
[1744]629  template <typename Graph>
[1909]630  UGraphWriter<Graph> uGraphWriter(const std::string& fn,
[1744]631                                           const Graph &g) {
[1909]632    return UGraphWriter<Graph>(fn, g);
[1421]633  }
634
[1333]635  /// @}
[1137]636
637}
[1214]638
639#endif
Note: See TracBrowser for help on using the repository browser.