lemon/graph_writer.h
changeset 1526 8c14aa8f27a2
parent 1435 8e85e6bbefdf
child 1534 b86aad11f842
equal deleted inserted replaced
0:8091c8f3eaef 1:0c1fbae3474f
    31   /// \addtogroup io_group
    31   /// \addtogroup io_group
    32   /// @{
    32   /// @{
    33 
    33 
    34   /// \brief The graph writer class.
    34   /// \brief The graph writer class.
    35   ///
    35   ///
    36   /// The \c GraphWriter class provides the graph output. To write a graph
    36   /// The \c GraphWriter class provides the graph output. 
    37   /// you should first give writing commands for the writer. You can declare
    37   /// Before you read this documentation it might be useful to read the general
    38   /// write command as \c NodeMap or \c EdgeMap writing and labeled Node and
    38   /// description of  \ref graph-io-page "Graph Input-Output".
       
    39   /// To write a graph
       
    40   /// you should first give writing commands to the writer. You can declare
       
    41   /// write commands as \c NodeMap or \c EdgeMap writing and labeled Node and
    39   /// Edge writing.
    42   /// Edge writing.
    40   ///
    43   ///
    41   /// \code
    44   /// \code
    42   /// GraphWriter<ListGraph> writer(std::cout, graph);
    45   /// GraphWriter<ListGraph> writer(std::cout, graph);
    43   /// \endcode
    46   /// \endcode
    44   ///
    47   ///
    45   /// The \c writeNodeMap() function declares a \c NodeMap writing 
    48   /// The \c writeNodeMap() function declares a \c NodeMap writing 
    46   /// command in the \c GraphWriter. You should give as parameter 
    49   /// command in the \c GraphWriter. You should give as parameter 
    47   /// the name of the map and the map object. The NodeMap writing 
    50   /// the name of the map and the map object. The NodeMap writing 
    48   /// command with name "id" should write a unique map because it 
    51   /// command with name "id" should write a unique map because it 
    49   /// is regarded as ID map.
    52   /// is regarded as ID map (such a map is essential if the graph has edges).
    50   ///
    53   ///
    51   /// \code
    54   /// \code
    52   /// IdMap<ListGraph, Node> nodeIdMap;
    55   /// IdMap<ListGraph, Node> nodeIdMap;
    53   /// writer.writeNodeMap("id", nodeIdMap);
    56   /// writer.writeNodeMap("id", nodeIdMap);
    54   ///
    57   ///
    67   /// writer.writeEdgeMap("weight", weightMap);
    70   /// writer.writeEdgeMap("weight", weightMap);
    68   /// writer.writeEdgeMap("label", labelMap);
    71   /// writer.writeEdgeMap("label", labelMap);
    69   /// \endcode
    72   /// \endcode
    70   ///
    73   ///
    71   /// With \c writeNode() and \c writeEdge() functions you can 
    74   /// With \c writeNode() and \c writeEdge() functions you can 
    72   /// point out Nodes and Edges in the graph. By example, you can 
    75   /// point out Nodes and Edges in the graph. For example, you can 
    73   /// write out the source and target of the graph.
    76   /// write out the source and target of a maximum flow instance.
    74   ///
    77   ///
    75   /// \code
    78   /// \code
    76   /// writer.writeNode("source", sourceNode);
    79   /// writer.writeNode("source", sourceNode);
    77   /// writer.writeNode("target", targetNode);
    80   /// writer.writeNode("target", targetNode);
    78   ///
    81   ///
    79   /// writer.writeEdge("observed", edge);
    82   /// writer.writeEdge("observed", edge);
    80   /// \endcode
    83   /// \endcode
    81   ///
    84   ///
    82   /// After you give all write commands you must call the \c run() member
    85   /// After you give all write commands you must call the \c run() member
    83   /// function, which execute all the writer commands.
    86   /// function, which executes all the writing commands.
    84   ///
    87   ///
    85   /// \code
    88   /// \code
    86   /// writer.run();
    89   /// writer.run();
    87   /// \endcode
    90   /// \endcode
    88   ///
    91   ///
   103 
   106 
   104     typedef _WriterTraits WriterTraits;
   107     typedef _WriterTraits WriterTraits;
   105 
   108 
   106     /// \brief Construct a new GraphWriter.
   109     /// \brief Construct a new GraphWriter.
   107     ///
   110     ///
   108     /// Construct a new GraphWriter. It writes the given graph
   111     /// This function constructs a new GraphWriter to write the given graph
   109     /// to the given stream.
   112     /// to the given stream.
   110     GraphWriter(std::ostream& _os, const Graph& _graph) 
   113     GraphWriter(std::ostream& _os, const Graph& _graph) 
   111       : writer(new LemonWriter(_os)), own_writer(true), 
   114       : writer(new LemonWriter(_os)), own_writer(true), 
   112 	nodeset_writer(*writer, _graph, std::string()),
   115 	nodeset_writer(*writer, _graph, std::string()),
   113 	edgeset_writer(*writer, _graph, nodeset_writer, std::string()),
   116 	edgeset_writer(*writer, _graph, nodeset_writer, std::string()),
   115 	edge_writer(*writer, edgeset_writer, std::string()),
   118 	edge_writer(*writer, edgeset_writer, std::string()),
   116 	attribute_writer(*writer, std::string()) {}
   119 	attribute_writer(*writer, std::string()) {}
   117 
   120 
   118     /// \brief Construct a new GraphWriter.
   121     /// \brief Construct a new GraphWriter.
   119     ///
   122     ///
   120     /// Construct a new GraphWriter. It writes into the given graph
   123     /// This function constructs a new GraphWriter to write the given graph
   121     /// to the given file.
   124     /// to the given file.
   122     GraphWriter(const std::string& _filename, const Graph& _graph) 
   125     GraphWriter(const std::string& _filename, const Graph& _graph) 
   123       : writer(new LemonWriter(_filename)), own_writer(true), 
   126       : writer(new LemonWriter(_filename)), own_writer(true), 
   124 	nodeset_writer(*writer, _graph, std::string()),
   127 	nodeset_writer(*writer, _graph, std::string()),
   125 	edgeset_writer(*writer, _graph, nodeset_writer, std::string()),
   128 	edgeset_writer(*writer, _graph, nodeset_writer, std::string()),
   127 	edge_writer(*writer, edgeset_writer, std::string()),
   130 	edge_writer(*writer, edgeset_writer, std::string()),
   128 	attribute_writer(*writer, std::string()) {}
   131 	attribute_writer(*writer, std::string()) {}
   129 
   132 
   130     /// \brief Construct a new GraphWriter.
   133     /// \brief Construct a new GraphWriter.
   131     ///
   134     ///
   132     /// Construct a new GraphWriter. It writes into the given graph
   135     /// This function constructs a new GraphWriter to write the given graph
   133     /// to given LemonReader.
   136     /// to the given LemonReader.
   134     GraphWriter(LemonWriter& _writer, const Graph& _graph)
   137     GraphWriter(LemonWriter& _writer, const Graph& _graph)
   135       : writer(_writer), own_writer(false), 
   138       : writer(_writer), own_writer(false), 
   136 	nodeset_writer(*writer, _graph, std::string()),
   139 	nodeset_writer(*writer, _graph, std::string()),
   137 	edgeset_writer(*writer, _graph, nodeset_writer, std::string()),
   140 	edgeset_writer(*writer, _graph, nodeset_writer, std::string()),
   138 	node_writer(*writer, nodeset_writer, std::string()),
   141 	node_writer(*writer, nodeset_writer, std::string()),
   139 	edge_writer(*writer, edgeset_writer, std::string()),
   142 	edge_writer(*writer, edgeset_writer, std::string()),
   140 	attribute_writer(*writer, std::string()) {}
   143 	attribute_writer(*writer, std::string()) {}
   141 
   144 
   142     /// \brief Destruct the graph writer.
   145     /// \brief Destruct the graph writer.
   143     ///
   146     ///
   144     /// Destruct the graph writer.
   147     /// This function destructs the graph writer.
   145     ~GraphWriter() {
   148     ~GraphWriter() {
   146       if (own_writer) 
   149       if (own_writer) 
   147 	delete writer;
   150 	delete writer;
   148     }
   151     }
   149 
   152 
   150     /// \brief Add a new node map writer command for the writer.
   153     /// \brief Issue a new node map writing command for the writer.
   151     ///
   154     ///
   152     /// Add a new node map writer command for the writer.
   155    /// This function issues a new <i> node map writing command</i> to the writer.
   153     template <typename Map>
   156     template <typename Map>
   154     GraphWriter& writeNodeMap(std::string name, const Map& map) {
   157     GraphWriter& writeNodeMap(std::string name, const Map& map) {
   155       nodeset_writer.writeNodeMap(name, map);
   158       nodeset_writer.writeNodeMap(name, map);
   156       return *this;
   159       return *this;
   157     }
   160     }
   158 
   161 
   159     /// \brief Add a new node map writer command for the writer.
   162     /// \brief Issue a new node map writing command for the writer.
   160     ///
   163     ///
   161     /// Add a new node map writer command for the writer.
   164    /// This function issues a new <i> node map writing command</i> to the writer.
   162     template <typename Writer, typename Map>
   165     template <typename Writer, typename Map>
   163     GraphWriter& writeNodeMap(std::string name, const Map& map, 
   166     GraphWriter& writeNodeMap(std::string name, const Map& map, 
   164 			      const Writer& writer = Writer()) {
   167 			      const Writer& writer = Writer()) {
   165       nodeset_writer.writeNodeMap(name, map, writer);
   168       nodeset_writer.writeNodeMap(name, map, writer);
   166       return *this;
   169       return *this;
   167     }
   170     }
   168 
   171 
   169 
   172 
   170     /// \brief Add a new edge map writer command for the writer.
   173     /// \brief Issue a new edge map writing command for the writer.
   171     ///
   174     ///
   172     /// Add a new edge map writer command for the writer.
   175    /// This function issues a new <i> edge map writing command</i> to the writer.
   173     template <typename Map>
   176     template <typename Map>
   174     GraphWriter& writeEdgeMap(std::string name, const Map& map) { 
   177     GraphWriter& writeEdgeMap(std::string name, const Map& map) { 
   175       edgeset_writer.writeEdgeMap(name, map);
   178       edgeset_writer.writeEdgeMap(name, map);
   176       return *this;
   179       return *this;
   177     }
   180     }
   178 
   181 
   179 
   182 
   180     /// \brief Add a new edge map writer command for the writer.
   183     /// \brief Issue a new edge map writing command for the writer.
   181     ///
   184     ///
   182     /// Add a new edge map writer command for the writer.
   185    /// This function issues a new <i> edge map writing command</i> to the writer.
   183     template <typename Writer, typename Map>
   186     template <typename Writer, typename Map>
   184     GraphWriter& writeEdgeMap(std::string name, const Map& map,
   187     GraphWriter& writeEdgeMap(std::string name, const Map& map,
   185 			      const Writer& writer = Writer()) {
   188 			      const Writer& writer = Writer()) {
   186       edgeset_writer.writeEdgeMap(name, map, writer);
   189       edgeset_writer.writeEdgeMap(name, map, writer);
   187       return *this;
   190       return *this;
   188     }
   191     }
   189 
   192 
   190     /// \brief Add a new labeled node writer for the writer.
   193     /// \brief Issue a new labeled node writing command to the writer.
   191     ///
   194     ///
   192     /// Add a new labeled node writer for the writer.
   195     /// This function issues a new <i> labeled node writing command</i> 
       
   196     /// to the writer.
   193     GraphWriter& writeNode(std::string name, const Node& node) {
   197     GraphWriter& writeNode(std::string name, const Node& node) {
   194       node_writer.writeNode(name, node);
   198       node_writer.writeNode(name, node);
   195       return *this;
   199       return *this;
   196     }
   200     }
   197 
   201 
   198     /// \brief Add a new labeled edge writer for the writer.
   202     /// \brief Issue a new labeled edge writing command to the writer.
   199     ///
   203     ///
   200     /// Add a new labeled edge writer for the writer.
   204     /// This function issues a new <i> labeled edge writing command</i> 
       
   205     /// to the writer.
   201     GraphWriter& writeEdge(std::string name, const Edge& edge) {
   206     GraphWriter& writeEdge(std::string name, const Edge& edge) {
   202       edge_writer.writeEdge(name, edge);
   207       edge_writer.writeEdge(name, edge);
   203     }
   208     }
   204 
   209 
   205     /// \brief Add a new attribute writer command.
   210     /// \brief Issue a new attribute writing command.
   206     ///
   211     ///
   207     ///  Add a new attribute writer command.
   212     /// This function issues a new <i> attribute writing command</i> 
       
   213     /// to the writer.
   208     template <typename Value>
   214     template <typename Value>
   209     GraphWriter& writeAttribute(std::string name, const Value& value) {
   215     GraphWriter& writeAttribute(std::string name, const Value& value) {
   210       attribute_writer.writeAttribute(name, value);
   216       attribute_writer.writeAttribute(name, value);
   211       return *this;
   217       return *this;
   212     }
   218     }
   213     
   219     
   214     /// \brief Add a new attribute writer command.
   220     /// \brief Issue a new attribute writing command.
   215     ///
   221     ///
   216     ///  Add a new attribute writer command.
   222     /// This function issues a new <i> attribute writing command</i> 
       
   223     /// to the writer.
   217     template <typename Writer, typename Value>
   224     template <typename Writer, typename Value>
   218     GraphWriter& writeAttribute(std::string name, const Value& value, 
   225     GraphWriter& writeAttribute(std::string name, const Value& value, 
   219 			       const Writer& writer) {
   226 			       const Writer& writer) {
   220       attribute_writer.writeAttribute<Writer>(name, value, writer);
   227       attribute_writer.writeAttribute<Writer>(name, value, writer);
   221       return *this;
   228       return *this;
   222     }
   229     }
   223 
   230 
   224     /// \brief Conversion operator to LemonWriter.
   231     /// \brief Conversion operator to LemonWriter.
   225     ///
   232     ///
   226     /// Conversion operator to LemonWriter. It make possible
   233     /// Conversion operator to LemonWriter. It makes possible
   227     /// to access the encapsulated \e LemonWriter, this way
   234     /// to access the encapsulated \e LemonWriter, this way
   228     /// you can attach to this writer new instances of 
   235     /// you can attach to this writer new instances of 
   229     /// \e LemonWriter::SectionWriter.
   236     /// \e LemonWriter::SectionWriter.
   230     operator LemonWriter&() {
   237     operator LemonWriter&() {
   231       return *writer;
   238       return *writer;
   232     }
   239     }
   233 
   240 
   234     /// \brief Executes the writer commands.
   241     /// \brief Executes the writing commands.
   235     ///
   242     ///
   236     /// Executes the writer commands.
   243     /// Executes the writing commands.
   237     void run() {
   244     void run() {
   238       writer->run();
   245       writer->run();
   239     }
   246     }
   240 
   247 
   241     /// \brief Write the id of the given node.
   248     /// \brief Write the id of the given node.
   242     ///
   249     ///
   243     /// It writes the id of the given node. If there was written an "id"
   250     /// It writes the id of the given node. If there was written an "id"
   244     /// named node map then it will write the map value belongs to the node.
   251     /// named node map then it will write the map value belonging to the node.
   245     void writeId(std::ostream& os, const Node& item) const {
   252     void writeId(std::ostream& os, const Node& item) const {
   246       nodeset_writer.writeId(os, item);
   253       nodeset_writer.writeId(os, item);
   247     } 
   254     } 
   248 
   255 
   249     /// \brief Write the id of the given edge.
   256     /// \brief Write the id of the given edge.
   250     ///
   257     ///
   251     /// It writes the id of the given edge. If there was written an "id"
   258     /// It writes the id of the given edge. If there was written an "id"
   252     /// named edge map then it will write the map value belongs to the edge.
   259     /// named edge map then it will write the map value belonging to the edge.
   253     void writeId(std::ostream& os, const Edge& item) const {
   260     void writeId(std::ostream& os, const Edge& item) const {
   254       edgeset_writer.writeId(os, item);
   261       edgeset_writer.writeId(os, item);
   255     } 
   262     } 
   256 
   263 
   257   private:
   264   private:
   371   }
   378   }
   372 
   379 
   373   /// \brief The undirected graph writer class.
   380   /// \brief The undirected graph writer class.
   374   ///
   381   ///
   375   /// The \c UndirGraphWriter class provides the undir graph output. To write 
   382   /// The \c UndirGraphWriter class provides the undir graph output. To write 
   376   /// a graph you should first give writing commands for the writer. You can 
   383   /// a graph you should first give writing commands to the writer. You can 
   377   /// declare write command as \c NodeMap, \c EdgeMap or \c UndirEdgeMap 
   384   /// declare write command as \c NodeMap, \c EdgeMap or \c UndirEdgeMap 
   378   /// writing and labeled Node, Edge or UndirEdge writing.
   385   /// writing and labeled Node, Edge or UndirEdge writing.
   379   ///
   386   ///
   380   /// \code
   387   /// \code
   381   /// UndirGraphWriter<UndirListGraph> writer(std::cout, graph);
   388   /// UndirGraphWriter<UndirListGraph> writer(std::cout, graph);
   414   /// writer.writeEdgeMap("capacity", capacityMap);
   421   /// writer.writeEdgeMap("capacity", capacityMap);
   415   /// \endcode
   422   /// \endcode
   416   ///
   423   ///
   417   ///
   424   ///
   418   /// With \c writeNode() and \c writeUndirEdge() functions you can 
   425   /// With \c writeNode() and \c writeUndirEdge() functions you can 
   419   /// point out nodes and undirected edges in the graph. By example, you can 
   426   /// designate nodes and undirected edges in the graph. For example, you can 
   420   /// write out the source and target of the graph.
   427   /// write out the source and target of the graph.
   421   ///
   428   ///
   422   /// \code
   429   /// \code
   423   /// writer.writeNode("source", sourceNode);
   430   /// writer.writeNode("source", sourceNode);
   424   /// writer.writeNode("target", targetNode);
   431   /// writer.writeNode("target", targetNode);
   425   ///
   432   ///
   426   /// writer.writeUndirEdge("observed", undirEdge);
   433   /// writer.writeUndirEdge("observed", undirEdge);
   427   /// \endcode
   434   /// \endcode
   428   ///
   435   ///
   429   /// After you give all write commands you must call the \c run() member
   436   /// After you give all write commands you must call the \c run() member
   430   /// function, which execute all the writer commands.
   437   /// function, which executes all the writing commands.
   431   ///
   438   ///
   432   /// \code
   439   /// \code
   433   /// writer.run();
   440   /// writer.run();
   434   /// \endcode
   441   /// \endcode
   435   ///
   442   ///
   463 	undir_edge_writer(*writer, undir_edgeset_writer, std::string()),
   470 	undir_edge_writer(*writer, undir_edgeset_writer, std::string()),
   464 	attribute_writer(*writer, std::string()) {}
   471 	attribute_writer(*writer, std::string()) {}
   465 
   472 
   466     /// \brief Construct a new UndirGraphWriter.
   473     /// \brief Construct a new UndirGraphWriter.
   467     ///
   474     ///
   468     /// Construct a new UndirGraphWriter. It writes into the given graph
   475     /// Construct a new UndirGraphWriter. It writes the given graph
   469     /// to the given file.
   476     /// to the given file.
   470     UndirGraphWriter(const std::string& _filename, const Graph& _graph) 
   477     UndirGraphWriter(const std::string& _filename, const Graph& _graph) 
   471       : writer(new LemonWriter(_filename)), own_writer(true), 
   478       : writer(new LemonWriter(_filename)), own_writer(true), 
   472 	nodeset_writer(*writer, _graph, std::string()),
   479 	nodeset_writer(*writer, _graph, std::string()),
   473 	undir_edgeset_writer(*writer, _graph, nodeset_writer, std::string()),
   480 	undir_edgeset_writer(*writer, _graph, nodeset_writer, std::string()),
   475 	undir_edge_writer(*writer, undir_edgeset_writer, std::string()),
   482 	undir_edge_writer(*writer, undir_edgeset_writer, std::string()),
   476 	attribute_writer(*writer, std::string()) {}
   483 	attribute_writer(*writer, std::string()) {}
   477 
   484 
   478     /// \brief Construct a new UndirGraphWriter.
   485     /// \brief Construct a new UndirGraphWriter.
   479     ///
   486     ///
   480     /// Construct a new UndirGraphWriter. It writes into the given graph
   487     /// Construct a new UndirGraphWriter. It writes the given graph
   481     /// to given LemonReader.
   488     /// to given LemonReader.
   482     UndirGraphWriter(LemonWriter& _writer, const Graph& _graph)
   489     UndirGraphWriter(LemonWriter& _writer, const Graph& _graph)
   483       : writer(_writer), own_writer(false), 
   490       : writer(_writer), own_writer(false), 
   484 	nodeset_writer(*writer, _graph, std::string()),
   491 	nodeset_writer(*writer, _graph, std::string()),
   485 	undir_edgeset_writer(*writer, _graph, nodeset_writer, std::string()),
   492 	undir_edgeset_writer(*writer, _graph, nodeset_writer, std::string()),
   493     ~UndirGraphWriter() {
   500     ~UndirGraphWriter() {
   494       if (own_writer) 
   501       if (own_writer) 
   495 	delete writer;
   502 	delete writer;
   496     }
   503     }
   497 
   504 
   498     /// \brief Add a new node map writer command for the writer.
   505     /// \brief Issue a new node map writing command to the writer.
   499     ///
   506     ///
   500     /// Add a new node map writer command for the writer.
   507    /// This function issues a new <i> node map writing command</i> to the writer.
   501     template <typename Map>
   508     template <typename Map>
   502     UndirGraphWriter& writeNodeMap(std::string name, const Map& map) {
   509     UndirGraphWriter& writeNodeMap(std::string name, const Map& map) {
   503       nodeset_writer.writeNodeMap(name, map);
   510       nodeset_writer.writeNodeMap(name, map);
   504       return *this;
   511       return *this;
   505     }
   512     }
   506 
   513 
   507     /// \brief Add a new node map writer command for the writer.
   514     /// \brief Issue a new node map writing command to the writer.
   508     ///
   515     ///
   509     /// Add a new node map writer command for the writer.
   516    /// This function issues a new <i> node map writing command</i> to the writer.
   510     template <typename Writer, typename Map>
   517     template <typename Writer, typename Map>
   511     UndirGraphWriter& writeNodeMap(std::string name, const Map& map, 
   518     UndirGraphWriter& writeNodeMap(std::string name, const Map& map, 
   512 			      const Writer& writer = Writer()) {
   519 			      const Writer& writer = Writer()) {
   513       nodeset_writer.writeNodeMap(name, map, writer);
   520       nodeset_writer.writeNodeMap(name, map, writer);
   514       return *this;
   521       return *this;
   515     }
   522     }
   516 
   523 
   517     /// \brief Add a new edge map writer command for the writer.
   524     /// \brief Issue a new edge map writing command to the writer.
   518     ///
   525     ///
   519     /// Add a new edge map writer command for the writer.
   526    /// This function issues a new <i> edge map writing command</i> to the writer.
   520     template <typename Map>
   527     template <typename Map>
   521     UndirGraphWriter& writeEdgeMap(std::string name, const Map& map) { 
   528     UndirGraphWriter& writeEdgeMap(std::string name, const Map& map) { 
   522       undir_edgeset_writer.writeEdgeMap(name, map);
   529       undir_edgeset_writer.writeEdgeMap(name, map);
   523       return *this;
   530       return *this;
   524     }
   531     }
   525 
   532 
   526     /// \brief Add a new edge map writer command for the writer.
   533     /// \brief Issue a new edge map writing command to the writer.
   527     ///
   534     ///
   528     /// Add a new edge map writer command for the writer.
   535    /// This function issues a new <i> edge map writing command</i> to the writer.
   529     template <typename Writer, typename Map>
   536     template <typename Writer, typename Map>
   530     UndirGraphWriter& writeEdgeMap(std::string name, const Map& map,
   537     UndirGraphWriter& writeEdgeMap(std::string name, const Map& map,
   531 				   const Writer& writer = Writer()) {
   538 				   const Writer& writer = Writer()) {
   532       undir_edgeset_writer.writeEdgeMap(name, map, writer);
   539       undir_edgeset_writer.writeEdgeMap(name, map, writer);
   533       return *this;
   540       return *this;
   534     }
   541     }
   535 
   542 
   536     /// \brief Add a new undirected edge map writer command for the writer.
   543     /// \brief Issue a new undirected edge map writing command to the writer.
   537     ///
   544     ///
   538     /// Add a new undirected edge map writer command for the writer.
   545     /// This function issues a new <i> undirected edge map writing
       
   546     /// command</i> to the writer.
   539     template <typename Map>
   547     template <typename Map>
   540     UndirGraphWriter& writeUndirEdgeMap(std::string name, const Map& map) { 
   548     UndirGraphWriter& writeUndirEdgeMap(std::string name, const Map& map) { 
   541       undir_edgeset_writer.writeUndirEdgeMap(name, map);
   549       undir_edgeset_writer.writeUndirEdgeMap(name, map);
   542       return *this;
   550       return *this;
   543     }
   551     }
   544 
   552 
   545     /// \brief Add a new undirected edge map writer command for the writer.
   553     /// \brief Issue a new undirected edge map writing command to the writer.
   546     ///
   554     ///
   547     /// Add a new edge undirected map writer command for the writer.
   555     /// This function issues a new <i> undirected edge map writing
       
   556     /// command</i> to the writer.
   548     template <typename Writer, typename Map>
   557     template <typename Writer, typename Map>
   549     UndirGraphWriter& writeUndirEdgeMap(std::string name, const Map& map,
   558     UndirGraphWriter& writeUndirEdgeMap(std::string name, const Map& map,
   550 					const Writer& writer = Writer()) {
   559 					const Writer& writer = Writer()) {
   551       undir_edgeset_writer.writeUndirEdgeMap(name, map, writer);
   560       undir_edgeset_writer.writeUndirEdgeMap(name, map, writer);
   552       return *this;
   561       return *this;
   553     }
   562     }
   554 
   563 
   555     /// \brief Add a new labeled node writer for the writer.
   564     /// \brief Issue a new labeled node writer to the writer.
   556     ///
   565     ///
   557     /// Add a new labeled node writer for the writer.
   566     /// This function issues a new <i> labeled node writing
       
   567     /// command</i> to the writer.
   558     UndirGraphWriter& writeNode(std::string name, const Node& node) {
   568     UndirGraphWriter& writeNode(std::string name, const Node& node) {
   559       node_writer.writeNode(name, node);
   569       node_writer.writeNode(name, node);
   560       return *this;
   570       return *this;
   561     }
   571     }
   562 
   572 
   563     /// \brief Add a new labeled edge writer for the writer.
   573     /// \brief Issue a new labeled edge writer to the writer.
   564     ///
   574     ///
   565     /// Add a new labeled edge writer for the writer.
   575     /// This function issues a new <i> labeled edge writing
       
   576     /// command</i> to the writer.
   566     UndirGraphWriter& writeEdge(std::string name, const Edge& edge) {
   577     UndirGraphWriter& writeEdge(std::string name, const Edge& edge) {
   567       undir_edge_writer.writeEdge(name, edge);
   578       undir_edge_writer.writeEdge(name, edge);
   568     }
   579     }
   569 
   580 
   570     /// \brief Add a new labeled undirected edge writer for the writer.
   581     /// \brief Issue a new labeled undirected edge writing command to
   571     ///
   582     /// the writer.
   572     /// Add a new labeled undirected edge writer for the writer.
   583     ///
       
   584     /// Issue a new <i>labeled undirected edge writing command</i> to
       
   585     /// the writer.
   573     UndirGraphWriter& writeUndirEdge(std::string name, const UndirEdge& edge) {
   586     UndirGraphWriter& writeUndirEdge(std::string name, const UndirEdge& edge) {
   574       undir_edge_writer.writeUndirEdge(name, edge);
   587       undir_edge_writer.writeUndirEdge(name, edge);
   575     }
   588     }
   576 
   589 
   577     /// \brief Add a new attribute writer command.
   590     /// \brief Issue a new attribute writing command.
   578     ///
   591     ///
   579     ///  Add a new attribute writer command.
   592     /// This function issues a new <i> attribute writing
       
   593     /// command</i> to the writer.
   580     template <typename Value>
   594     template <typename Value>
   581     UndirGraphWriter& writeAttribute(std::string name, const Value& value) {
   595     UndirGraphWriter& writeAttribute(std::string name, const Value& value) {
   582       attribute_writer.writeAttribute(name, value);
   596       attribute_writer.writeAttribute(name, value);
   583       return *this;
   597       return *this;
   584     }
   598     }
   585     
   599     
   586     /// \brief Add a new attribute writer command.
   600     /// \brief Issue a new attribute writing command.
   587     ///
   601     ///
   588     ///  Add a new attribute writer command.
   602     /// This function issues a new <i> attribute writing
       
   603     /// command</i> to the writer.
   589     template <typename Writer, typename Value>
   604     template <typename Writer, typename Value>
   590     UndirGraphWriter& writeAttribute(std::string name, const Value& value, 
   605     UndirGraphWriter& writeAttribute(std::string name, const Value& value, 
   591 			       const Writer& writer) {
   606 			       const Writer& writer) {
   592       attribute_writer.writeAttribute<Writer>(name, value, writer);
   607       attribute_writer.writeAttribute<Writer>(name, value, writer);
   593       return *this;
   608       return *this;
   594     }
   609     }
   595 
   610 
   596     /// \brief Conversion operator to LemonWriter.
   611     /// \brief Conversion operator to LemonWriter.
   597     ///
   612     ///
   598     /// Conversion operator to LemonWriter. It make possible
   613     /// Conversion operator to LemonWriter. It makes possible
   599     /// to access the encapsulated \e LemonWriter, this way
   614     /// to access the encapsulated \e LemonWriter, this way
   600     /// you can attach to this writer new instances of 
   615     /// you can attach to this writer new instances of 
   601     /// \e LemonWriter::SectionWriter.
   616     /// \e LemonWriter::SectionWriter.
   602     operator LemonWriter&() {
   617     operator LemonWriter&() {
   603       return *writer;
   618       return *writer;
   604     }
   619     }
   605 
   620 
   606     /// \brief Executes the writer commands.
   621     /// \brief Executes the writing commands.
   607     ///
   622     ///
   608     /// Executes the writer commands.
   623     /// Executes the writing commands.
   609     void run() {
   624     void run() {
   610       writer->run();
   625       writer->run();
   611     }
   626     }
   612 
   627 
   613     /// \brief Write the id of the given node.
   628     /// \brief Write the id of the given node.
   614     ///
   629     ///
   615     /// It writes the id of the given node. If there was written an "id"
   630     /// It writes the id of the given node. If there was written an "id"
   616     /// named node map then it will write the map value belongs to the node.
   631     /// named node map then it will write the map value belonging to the node.
   617     void writeId(std::ostream& os, const Node& item) const {
   632     void writeId(std::ostream& os, const Node& item) const {
   618       nodeset_writer.writeId(os, item);
   633       nodeset_writer.writeId(os, item);
   619     } 
   634     } 
   620 
   635 
   621     /// \brief Write the id of the given edge.
   636     /// \brief Write the id of the given edge.
   622     ///
   637     ///
   623     /// It writes the id of the given edge. If there was written an "id"
   638     /// It writes the id of the given edge. If there was written an "id"
   624     /// named edge map then it will write the map value belongs to the edge.
   639     /// named edge map then it will write the map value belonging to the edge.
   625     void writeId(std::ostream& os, const Edge& item) const {
   640     void writeId(std::ostream& os, const Edge& item) const {
   626       undir_edgeset_writer.writeId(os, item);
   641       undir_edgeset_writer.writeId(os, item);
   627     } 
   642     } 
   628 
   643 
   629     /// \brief Write the id of the given undirected edge.
   644     /// \brief Write the id of the given undirected edge.
   630     ///
   645     ///
   631     /// It writes the id of the given undirected edge. If there was written 
   646     /// It writes the id of the given undirected edge. If there was written 
   632     /// an "id" named edge map then it will write the map value belongs to 
   647     /// an "id" named edge map then it will write the map value belonging to 
   633     /// the edge.
   648     /// the edge.
   634     void writeId(std::ostream& os, const UndirEdge& item) const {
   649     void writeId(std::ostream& os, const UndirEdge& item) const {
   635       undir_edgeset_writer.writeId(os, item);
   650       undir_edgeset_writer.writeId(os, item);
   636     } 
   651     } 
   637 
   652 
   649     
   664     
   650     AttributeWriter<WriterTraits> attribute_writer;
   665     AttributeWriter<WriterTraits> attribute_writer;
   651   };
   666   };
   652 
   667 
   653 
   668 
   654   /// \brief Write an undirected graph to the output.
   669   /// \brief Write an undirected multigraph (undirected graph + capacity
   655   ///
   670   /// map on the edges) to the output.
   656   /// Write an undirected graph to the output.
   671   ///
       
   672   /// Write an undirected multigraph (undirected graph + capacity
       
   673   /// map on the edges) to the output.
   657   /// \param os The output stream.
   674   /// \param os The output stream.
   658   /// \param g The graph.
   675   /// \param g The graph.
   659   /// \param capacity The capacity undirected map.
   676   /// \param capacity The capacity undirected map.
   660   template<typename Graph, typename CapacityMap>
   677   template<typename Graph, typename CapacityMap>
   661   void writeUndirGraph(std::ostream& os, const Graph &g, 
   678   void writeUndirGraph(std::ostream& os, const Graph &g,