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