COIN-OR::LEMON - Graph Library

source: lemon-0.x/lemon/graph_reader.h @ 2390:8450951a8e2d

Last change on this file since 2390:8450951a8e2d was 2386:81b47fc5c444, checked in by Balazs Dezso, 17 years ago

Hard Warning checking

  • based on the remark of the ZIB user
  • we do not use -Winline
File size: 24.4 KB
RevLine 
[1137]1/* -*- C++ -*-
2 *
[1956]3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
[1359]7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
[1137]8 *
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
12 *
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
15 * purpose.
16 *
17 */
18
[2084]19///\ingroup lemon_io
[1137]20///\file
[1287]21///\brief Lemon Graph Format reader.
[1137]22
[1214]23#ifndef LEMON_GRAPH_READER_H
24#define LEMON_GRAPH_READER_H
25
[1137]26#include <iostream>
27
28#include <lemon/error.h>
[1408]29#include <lemon/lemon_reader.h>
[1137]30
31namespace lemon {
32
[2084]33  /// \addtogroup lemon_io
[1333]34  /// @{
[1137]35
36  /// \brief The graph reader class.
37  ///
[1534]38  /// The \c GraphReader class provides the graph input.
39  /// Before you read this documentation it might be useful to read the general
40  /// description of  \ref graph-io-page "Graph Input-Output".
[1540]41  ///
[2334]42  /// The file to be read may contain several maps and labeled
43  /// (designated) nodes or edges.
[1333]44  ///
45  /// If you read a graph you need not read all the maps and items just those
46  /// that you need. The interface of the \c GraphReader is very similar to
47  /// the GraphWriter but the reading method does not depend on the order the
[1540]48  /// given commands (i.e. you don't have to insist on the order in which the
49  /// maps are given in the file).
[1333]50  ///
[2100]51  /// The reader object assumes that not read values do not contain
[1333]52  /// whitespaces, therefore it has some extra possibilities to control how
53  /// it should skip the values when the string representation contains spaces.
54  ///
[1946]55  ///\code
[1333]56  /// GraphReader<ListGraph> reader(std::cin, graph);
[1946]57  ///\endcode
[1333]58  ///
[1394]59  /// The \c readNodeMap() function reads a map from the \c \@nodeset section.
[1333]60  /// If there is a map that you do not want to read from the file and there is
61  /// whitespace in the string represenation of the values then you should
62  /// call the \c skipNodeMap() template member function with proper
63  /// parameters.
64  ///
[1946]65  ///\code
[1421]66  /// reader.readNodeMap("coords", coords);
[1333]67  ///
[1901]68  /// reader.skipNodeMap("description", desc);
[1333]69  ///
[1394]70  /// reader.readNodeMap("color", colorMap);
[1946]71  ///\endcode
[1333]72  ///
[1394]73  /// With the \c readEdgeMap() member function you can give an edge map
[1333]74  /// reading command similar to the NodeMaps.
75  ///
[1946]76  ///\code
[1394]77  /// reader.readEdgeMap("weight", weightMap);
78  /// reader.readEdgeMap("label", labelMap);
[1946]79  ///\endcode
[1333]80  ///
[1408]81  /// With \c readNode() and \c readEdge() functions you can read
82  /// labeled Nodes and Edges.
[1333]83  ///
[1946]84  ///\code
[1394]85  /// reader.readNode("source", sourceNode);
86  /// reader.readNode("target", targetNode);
[1333]87  ///
[1394]88  /// reader.readEdge("observed", edge);
[1946]89  ///\endcode
[1333]90  ///
[1408]91  /// With the \c readAttribute() functions you can read an attribute
[1540]92  /// into a variable. You can specify the reader for the attribute as
[1408]93  /// the nodemaps.
94  ///
[1333]95  /// After you give all read commands you must call the \c run() member
[1540]96  /// function, which executes all the commands.
[1333]97  ///
[1946]98  ///\code
[1333]99  /// reader.run();
[1946]100  ///\endcode
[1333]101  ///
[1287]102  /// \see DefaultReaderTraits
103  /// \see QuotedStringReader
[1138]104  /// \see \ref GraphWriter
105  /// \see \ref graph-io-page
[1333]106  /// \author Balazs Dezso
[1137]107  template <typename _Graph, typename _ReaderTraits = DefaultReaderTraits>
108  class GraphReader {
109  public:
110   
111    typedef _Graph Graph;
112    typedef typename Graph::Node Node;
113    typedef typename Graph::Edge Edge;
114
115    typedef _ReaderTraits ReaderTraits;
[1408]116    typedef typename ReaderTraits::Skipper DefaultSkipper;
[1137]117
118    /// \brief Construct a new GraphReader.
119    ///
[1208]120    /// Construct a new GraphReader. It reads into the given graph
[1540]121    /// and it uses the given reader as the default skipper.
[1705]122    GraphReader(std::istream& _is, Graph& _graph,
[1408]123                const DefaultSkipper& _skipper = DefaultSkipper())
[1421]124      : reader(new LemonReader(_is)), own_reader(true), skipper(_skipper),
125        nodeset_reader(*reader, _graph, std::string(), skipper),
126        edgeset_reader(*reader, _graph, nodeset_reader,
127                       std::string(), skipper),
[1408]128        node_reader(*reader, nodeset_reader, std::string()),
129        edge_reader(*reader, edgeset_reader, std::string()),
130        attribute_reader(*reader, std::string()) {}
131
132    /// \brief Construct a new GraphReader.
133    ///
134    /// Construct a new GraphReader. It reads into the given graph
[1540]135    /// and it uses the given reader as the default skipper.
[1705]136    GraphReader(const std::string& _filename, Graph& _graph,
[1408]137                const DefaultSkipper& _skipper = DefaultSkipper())
138      : reader(new LemonReader(_filename)), own_reader(true),
[1421]139        skipper(_skipper),
140        nodeset_reader(*reader, _graph, std::string(), skipper),
141        edgeset_reader(*reader, _graph, nodeset_reader,
142                       std::string(), skipper),
[1408]143        node_reader(*reader, nodeset_reader, std::string()),
144        edge_reader(*reader, edgeset_reader, std::string()),
145        attribute_reader(*reader, std::string()) {}
146
147    /// \brief Construct a new GraphReader.
148    ///
149    /// Construct a new GraphReader. It reads into the given graph
[1540]150    /// and it uses the given reader as the default skipper.
[1705]151    GraphReader(LemonReader& _reader, Graph& _graph,
[1408]152                const DefaultSkipper& _skipper = DefaultSkipper())
[1421]153      : reader(_reader), own_reader(false), skipper(_skipper),
154        nodeset_reader(*reader, _graph, std::string(), skipper),
155        edgeset_reader(*reader, _graph, nodeset_reader,
156                       std::string(), skipper),
[1408]157        node_reader(*reader, nodeset_reader, std::string()),
158        edge_reader(*reader, edgeset_reader, std::string()),
159        attribute_reader(*reader, std::string()) {}
[1137]160
161    /// \brief Destruct the graph reader.
162    ///
163    /// Destruct the graph reader.
164    ~GraphReader() {
[1408]165      if (own_reader)
166        delete reader;
[1137]167    }
168
[1540]169    /// \brief Give a new node map reading command to the reader.
[1137]170    ///
[1540]171    /// Give a new node map reading command to the reader.
[1137]172    template <typename Map>
[1394]173    GraphReader& readNodeMap(std::string name, Map& map) {
[1421]174      nodeset_reader.readNodeMap(name, map);
175      return *this;
176    }
177
178    template <typename Map>
179    GraphReader& readNodeMap(std::string name, const Map& map) {
180      nodeset_reader.readNodeMap(name, map);
[1408]181      return *this;
[1137]182    }
183
[1540]184    /// \brief Give a new node map reading command to the reader.
[1137]185    ///
[1540]186    /// Give a new node map reading command to the reader.
[2386]187    template <typename ItemReader, typename Map>
[1394]188    GraphReader& readNodeMap(std::string name, Map& map,
[2386]189                             const ItemReader& ir = ItemReader()) {
190      nodeset_reader.readNodeMap(name, map, ir);
[1421]191      return *this;
192    }
193
[2386]194    template <typename ItemReader, typename Map>
[1421]195    GraphReader& readNodeMap(std::string name, const Map& map,
[2386]196                             const ItemReader& ir = ItemReader()) {
197      nodeset_reader.readNodeMap(name, map, ir);
[1137]198      return *this;
199    }
200
[1540]201    /// \brief Give a new node map skipping command to the reader.
[1137]202    ///
[1540]203    /// Give a new node map skipping command to the reader.
[2386]204    template <typename ItemReader>
[1137]205    GraphReader& skipNodeMap(std::string name,
[2386]206                             const ItemReader& ir = ItemReader()) {
207      nodeset_reader.skipNodeMap(name, ir);
[1137]208      return *this;
209    }
210
[1540]211    /// \brief Give a new edge map reading command to the reader.
[1137]212    ///
[1540]213    /// Give a new edge map reading command to the reader.
[1137]214    template <typename Map>
[1394]215    GraphReader& readEdgeMap(std::string name, Map& map) {
[1421]216      edgeset_reader.readEdgeMap(name, map);
217      return *this;
218    }
219
220    template <typename Map>
221    GraphReader& readEdgeMap(std::string name, const Map& map) {
222      edgeset_reader.readEdgeMap(name, map);
[1408]223      return *this;
[1137]224    }
225
226
[1540]227    /// \brief Give a new edge map reading command to the reader.
[1137]228    ///
[1540]229    /// Give a new edge map reading command to the reader.
[2386]230    template <typename ItemReader, typename Map>
[1394]231    GraphReader& readEdgeMap(std::string name, Map& map,
[2386]232                             const ItemReader& ir = ItemReader()) {
233      edgeset_reader.readEdgeMap(name, map, ir);
[1421]234      return *this;
235    }
236
[2386]237    template <typename ItemReader, typename Map>
[1421]238    GraphReader& readEdgeMap(std::string name, const Map& map,
[2386]239                             const ItemReader& ir = ItemReader()) {
240      edgeset_reader.readEdgeMap(name, map, ir);
[1137]241      return *this;
242    }
243
[1540]244    /// \brief Give a new edge map skipping command to the reader.
[1137]245    ///
[1540]246    /// Give a new edge map skipping command to the reader.
[2386]247    template <typename ItemReader>
[1421]248    GraphReader& skipEdgeMap(std::string name,
[2386]249                             const ItemReader& ir = ItemReader()) {
250      edgeset_reader.skipEdgeMap(name, ir);
[1137]251      return *this;
252    }
253
[1540]254    /// \brief Give a new labeled node reading command to the reader.
[1137]255    ///
[1540]256    /// Give a new labeled node reading command to the reader.
[1394]257    GraphReader& readNode(std::string name, Node& node) {
[1408]258      node_reader.readNode(name, node);
[1137]259      return *this;
260    }
261
[1540]262    /// \brief Give a new labeled edge reading command to the reader.
[1137]263    ///
[1540]264    /// Give a new labeled edge reading command to the reader.
[1394]265    GraphReader& readEdge(std::string name, Edge& edge) {
[1408]266      edge_reader.readEdge(name, edge);
[1476]267      return *this;
[1408]268    }
269
[1540]270    /// \brief Give a new attribute reading command.
[1408]271    ///
[1540]272    ///  Give a new attribute reading command.
[1408]273    template <typename Value>
274    GraphReader& readAttribute(std::string name, Value& value) {
275      attribute_reader.readAttribute(name, value);
[1137]276      return *this;
277    }
[1408]278   
[1540]279    /// \brief Give a new attribute reading command.
[1408]280    ///
[1540]281    ///  Give a new attribute reading command.
[2386]282    template <typename ItemReader, typename Value>
[1408]283    GraphReader& readAttribute(std::string name, Value& value,
[2386]284                               const ItemReader& ir = ItemReader()) {
285      attribute_reader.readAttribute(name, value, ir);
[1408]286      return *this;
287    }
288
289    /// \brief Conversion operator to LemonReader.
290    ///
[1540]291    /// Conversion operator to LemonReader. It makes possible to access the
292    /// encapsulated \e LemonReader, this way you can attach to this reader
293    /// new instances of \e LemonReader::SectionReader. For more details see
294    /// the \ref rwbackground "Background of Reading and Writing".
[1408]295    operator LemonReader&() {
296      return *reader;
297    }
[1137]298
[1540]299    /// \brief Executes the reading commands.
[1137]300    ///
[1540]301    /// Executes the reading commands.
[1137]302    void run() {
[1408]303      reader->run();
[1396]304    }
305
[1901]306
307    /// \brief Returns true if the reader can give back the items by its label.
[1429]308    ///
[1901]309    /// \brief Returns true if the reader can give back the items by its label.
310    bool isLabelReader() const {
311      return nodeset_reader.isLabelReader() && edgeset_reader.isLabelReader();
312    }
313
314    /// \brief Gives back the node by its label.
315    ///
316    /// It reads an label from the stream and gives back which node belongs to
[1935]317    /// it. It is possible only if there was read a "label" named node map.
[1901]318    void readLabel(std::istream& is, Node& node) const {
319      nodeset_reader.readLabel(is, node);
[1429]320    }
321
[1901]322    /// \brief Gives back the edge by its label.
[1429]323    ///
[1901]324    /// It reads an label from the stream and gives back which edge belongs to
[1935]325    /// it. It is possible only if there was read a "label" named edge map.
[1901]326    void readLabel(std::istream& is, Edge& edge) const {
327      return edgeset_reader.readLabel(is, edge);
[1429]328    }
329
[1137]330  private:
331
[1408]332    LemonReader* reader;
333    bool own_reader;
[1137]334
[1408]335    DefaultSkipper skipper;
[1137]336
[1408]337    NodeSetReader<Graph, ReaderTraits> nodeset_reader;
338    EdgeSetReader<Graph, ReaderTraits> edgeset_reader;
339
340    NodeReader<Graph> node_reader;
341    EdgeReader<Graph> edge_reader;
342   
343    AttributeReader<ReaderTraits> attribute_reader;
[1137]344  };
345
[1534]346
[1744]347  /// \brief The undirected graph reader class.
[1421]348  ///
[1909]349  /// The \c UGraphReader class provides the graph input.
[1540]350  /// Before you read this documentation it might be useful to read the general
351  /// description of  \ref graph-io-page "Graph Input-Output".
352  ///
[1421]353  /// The given file format may contain several maps and labeled nodes or
354  /// edges.
355  ///
356  /// If you read a graph you need not read all the maps and items just those
[1909]357  /// that you need. The interface of the \c UGraphReader is very similar
358  /// to the UGraphWriter but the reading method does not depend on the
[1540]359  /// order of the given commands.
[1421]360  ///
[2100]361  /// The reader object suppose that each not read value does not contain
[1421]362  /// whitespaces, therefore it has some extra possibilities to control how
363  /// it should skip the values when the string representation contains spaces.
364  ///
[1946]365  ///\code
[1909]366  /// UGraphReader<ListUGraph> reader(std::cin, graph);
[1946]367  ///\endcode
[1421]368  ///
369  /// The \c readNodeMap() function reads a map from the \c \@nodeset section.
370  /// If there is a map that you do not want to read from the file and there is
371  /// whitespace in the string represenation of the values then you should
372  /// call the \c skipNodeMap() template member function with proper
373  /// parameters.
374  ///
[1946]375  ///\code
[1421]376  /// reader.readNodeMap("coords", coords);
377  ///
[1901]378  /// reader.skipNodeMap("description", desc);
[1421]379  ///
380  /// reader.readNodeMap("color", colorMap);
[1946]381  ///\endcode
[1421]382  ///
[1909]383  /// With the \c readUEdgeMap() member function you can give an
384  /// uedge map reading command similar to the NodeMaps.
[1421]385  ///
[1946]386  ///\code
[1909]387  /// reader.readUEdgeMap("capacity", capacityMap);
[1946]388  ///\endcode
[1421]389  ///
390  /// The reading of the directed edge maps is just a syntactical sugar.
391  /// It reads two undirected edgemaps into a directed edge map. The
392  /// undirected edge maps' name should be start with the \c '+' and the
393  /// \c '-' character and the same.
394  ///
[1946]395  ///\code
[1421]396  /// reader.readEdgeMap("flow", flowMap);
[1946]397  ///\endcode
[1421]398  ///
[1909]399  /// With \c readNode() and \c readUEdge() functions you can read
400  /// labeled Nodes and UEdges.
[1421]401  ///
[1946]402  ///\code
[1421]403  /// reader.readNode("source", sourceNode);
404  /// reader.readNode("target", targetNode);
405  ///
[1909]406  /// reader.readUEdge("observed", uEdge);
[1946]407  ///\endcode
[1421]408  ///
409  /// With the \c readAttribute() functions you can read an attribute
410  /// in a variable. You can specify the reader for the attribute as
411  /// the nodemaps.
412  ///
413  /// After you give all read commands you must call the \c run() member
414  /// function, which execute all the commands.
415  ///
[1946]416  ///\code
[1421]417  /// reader.run();
[1946]418  ///\endcode
[1421]419  ///
420  /// \see GraphReader
421  /// \see DefaultReaderTraits
[1909]422  /// \see \ref UGraphWriter
[1421]423  /// \see \ref graph-io-page
424  ///
425  /// \author Balazs Dezso
426  template <typename _Graph, typename _ReaderTraits = DefaultReaderTraits>
[1909]427  class UGraphReader {
[1421]428  public:
429   
430    typedef _Graph Graph;
431    typedef typename Graph::Node Node;
432    typedef typename Graph::Edge Edge;
[1909]433    typedef typename Graph::UEdge UEdge;
[1421]434
435    typedef _ReaderTraits ReaderTraits;
436    typedef typename ReaderTraits::Skipper DefaultSkipper;
437
[1909]438    /// \brief Construct a new UGraphReader.
[1421]439    ///
[1909]440    /// Construct a new UGraphReader. It reads into the given graph
[1421]441    /// and it use the given reader as the default skipper.
[1909]442    UGraphReader(std::istream& _is, Graph& _graph,
[1421]443                     const DefaultSkipper& _skipper = DefaultSkipper())
444      : reader(new LemonReader(_is)), own_reader(true), skipper(_skipper),
445        nodeset_reader(*reader, _graph, std::string(), skipper),
[1909]446        u_edgeset_reader(*reader, _graph, nodeset_reader,
[1421]447                             std::string(), skipper),
448        node_reader(*reader, nodeset_reader, std::string()),
[1909]449        u_edge_reader(*reader, u_edgeset_reader, std::string()),
[1421]450        attribute_reader(*reader, std::string()) {}
451
[1909]452    /// \brief Construct a new UGraphReader.
[1421]453    ///
[1909]454    /// Construct a new UGraphReader. It reads into the given graph
[1421]455    /// and it use the given reader as the default skipper.
[1909]456    UGraphReader(const std::string& _filename, Graph& _graph,
[1421]457                     const DefaultSkipper& _skipper = DefaultSkipper())
458      : reader(new LemonReader(_filename)), own_reader(true),
459        skipper(_skipper),
460        nodeset_reader(*reader, _graph, std::string(), skipper),
[1909]461        u_edgeset_reader(*reader, _graph, nodeset_reader,
[1421]462                             std::string(), skipper),
463        node_reader(*reader, nodeset_reader, std::string()),
[1909]464        u_edge_reader(*reader, u_edgeset_reader, std::string()),
[1421]465        attribute_reader(*reader, std::string()) {}
466
[1909]467    /// \brief Construct a new UGraphReader.
[1421]468    ///
[1909]469    /// Construct a new UGraphReader. It reads into the given graph
[1421]470    /// and it use the given reader as the default skipper.
[1909]471    UGraphReader(LemonReader& _reader, Graph& _graph,
[1421]472                     const DefaultSkipper& _skipper = DefaultSkipper())
473      : reader(_reader), own_reader(false), skipper(_skipper),
474        nodeset_reader(*reader, _graph, std::string(), skipper),
[1909]475        u_edgeset_reader(*reader, _graph, nodeset_reader,
[1421]476                             std::string(), skipper),
477        node_reader(*reader, nodeset_reader, std::string()),
[1909]478        u_edge_reader(*reader, u_edgeset_reader, std::string()),
[1421]479        attribute_reader(*reader, std::string()) {}
480
481    /// \brief Destruct the graph reader.
482    ///
483    /// Destruct the graph reader.
[1909]484    ~UGraphReader() {
[1421]485      if (own_reader)
486        delete reader;
487    }
488
[1540]489    /// \brief Give a new node map reading command to the reader.
[1421]490    ///
[1540]491    /// Give a new node map reading command to the reader.
[1421]492    template <typename Map>
[1909]493    UGraphReader& readNodeMap(std::string name, Map& map) {
[1421]494      nodeset_reader.readNodeMap(name, map);
495      return *this;
496    }
497
498    template <typename Map>
[1909]499    UGraphReader& readNodeMap(std::string name, const Map& map) {
[1421]500      nodeset_reader.readNodeMap(name, map);
501      return *this;
502    }
503
[1540]504    /// \brief Give a new node map reading command to the reader.
[1421]505    ///
[1540]506    /// Give a new node map reading command to the reader.
[2386]507    template <typename ItemReader, typename Map>
[1909]508    UGraphReader& readNodeMap(std::string name, Map& map,
[2386]509                              const ItemReader& ir = ItemReader()) {
510      nodeset_reader.readNodeMap(name, map, ir);
[1421]511      return *this;
512    }
513
[2386]514    template <typename ItemReader, typename Map>
[1909]515    UGraphReader& readNodeMap(std::string name, const Map& map,
[2386]516                              const ItemReader& ir = ItemReader()) {
517      nodeset_reader.readNodeMap(name, map, ir);
[1421]518      return *this;
519    }
520
[1540]521    /// \brief Give a new node map skipping command to the reader.
[1421]522    ///
[1540]523    /// Give a new node map skipping command to the reader.
[2386]524    template <typename ItemReader>
[1909]525    UGraphReader& skipNodeMap(std::string name,
[2386]526                              const ItemReader& ir = ItemReader()) {
527      nodeset_reader.skipNodeMap(name, ir);
[1421]528      return *this;
529    }
530
[1540]531    /// \brief Give a new undirected edge map reading command to the reader.
[1421]532    ///
[1540]533    /// Give a new undirected edge map reading command to the reader.
[1421]534    template <typename Map>
[1909]535    UGraphReader& readUEdgeMap(std::string name, Map& map) {
536      u_edgeset_reader.readUEdgeMap(name, map);
[1421]537      return *this;
538    }
539
540    template <typename Map>
[1909]541    UGraphReader& readUEdgeMap(std::string name, const Map& map) {
542      u_edgeset_reader.readUEdgeMap(name, map);
[1421]543      return *this;
544    }
545
546
[1540]547    /// \brief Give a new undirected edge map reading command to the reader.
[1421]548    ///
[1540]549    /// Give a new undirected edge map reading command to the reader.
[2386]550    template <typename ItemReader, typename Map>
[1909]551    UGraphReader& readUEdgeMap(std::string name, Map& map,
[2386]552                               const ItemReader& ir = ItemReader()) {
553      u_edgeset_reader.readUEdgeMap(name, map, ir);
[1421]554      return *this;
555    }
556
[2386]557    template <typename ItemReader, typename Map>
[1909]558    UGraphReader& readUEdgeMap(std::string name, const Map& map,
[2386]559                               const ItemReader& ir = ItemReader()) {
560      u_edgeset_reader.readUEdgeMap(name, map, ir);
[1421]561      return *this;
562    }
563
[1540]564    /// \brief Give a new undirected edge map skipping command to the reader.
[1421]565    ///
[1540]566    /// Give a new undirected edge map skipping command to the reader.
[2386]567    template <typename ItemReader>
[1909]568    UGraphReader& skipUEdgeMap(std::string name,
[2386]569                                       const ItemReader& ir = ItemReader()) {
570      u_edgeset_reader.skipUMap(name, ir);
[1421]571      return *this;
572    }
573
574
[1540]575    /// \brief Give a new edge map reading command to the reader.
[1421]576    ///
[1540]577    /// Give a new edge map reading command to the reader.
[1421]578    template <typename Map>
[1909]579    UGraphReader& readEdgeMap(std::string name, Map& map) {
580      u_edgeset_reader.readEdgeMap(name, map);
[1421]581      return *this;
582    }
583
584    template <typename Map>
[1909]585    UGraphReader& readEdgeMap(std::string name, const Map& map) {
586      u_edgeset_reader.readEdgeMap(name, map);
[1421]587      return *this;
588    }
589
590
[1540]591    /// \brief Give a new edge map reading command to the reader.
[1421]592    ///
[1540]593    /// Give a new edge map reading command to the reader.
[2386]594    template <typename ItemReader, typename Map>
[1909]595    UGraphReader& readEdgeMap(std::string name, Map& map,
[2386]596                              const ItemReader& ir = ItemReader()) {
597      u_edgeset_reader.readEdgeMap(name, map, ir);
[1421]598      return *this;
599    }
600
[2386]601    template <typename ItemReader, typename Map>
[1909]602    UGraphReader& readEdgeMap(std::string name, const Map& map,
[2386]603                              const ItemReader& ir = ItemReader()) {
604      u_edgeset_reader.readEdgeMap(name, map, ir);
[1421]605      return *this;
606    }
607
[1540]608    /// \brief Give a new edge map skipping command to the reader.
[1421]609    ///
[1540]610    /// Give a new edge map skipping command to the reader.
[2386]611    template <typename ItemReader>
[1909]612    UGraphReader& skipEdgeMap(std::string name,
[2386]613                              const ItemReader& ir = ItemReader()) {
614      u_edgeset_reader.skipEdgeMap(name, ir);
[1421]615      return *this;
616    }
617
[1540]618    /// \brief Give a new labeled node reading command to the reader.
[1421]619    ///
[1540]620    /// Give a new labeled node reading command to the reader.
[1909]621    UGraphReader& readNode(std::string name, Node& node) {
[1421]622      node_reader.readNode(name, node);
623      return *this;
624    }
625
[1540]626    /// \brief Give a new labeled edge reading command to the reader.
[1421]627    ///
[1540]628    /// Give a new labeled edge reading command to the reader.
[1909]629    UGraphReader& readEdge(std::string name, Edge& edge) {
630      u_edge_reader.readEdge(name, edge);
[1429]631    }
632
[1540]633    /// \brief Give a new labeled undirected edge reading command to the
634    /// reader.
[1429]635    ///
[1540]636    /// Give a new labeled undirected edge reading command to the reader.
[1909]637    UGraphReader& readUEdge(std::string name, UEdge& edge) {
638      u_edge_reader.readUEdge(name, edge);
[1421]639    }
640
[1540]641    /// \brief Give a new attribute reading command.
[1421]642    ///
[1540]643    ///  Give a new attribute reading command.
[1421]644    template <typename Value>
[1909]645    UGraphReader& readAttribute(std::string name, Value& value) {
[1421]646      attribute_reader.readAttribute(name, value);
647      return *this;
648    }
649   
[1540]650    /// \brief Give a new attribute reading command.
[1421]651    ///
[1540]652    ///  Give a new attribute reading command.
[2386]653    template <typename ItemReader, typename Value>
[1909]654    UGraphReader& readAttribute(std::string name, Value& value,
[2386]655                               const ItemReader& ir = ItemReader()) {
656      attribute_reader.readAttribute(name, value, ir);
[1421]657      return *this;
658    }
659
660    /// \brief Conversion operator to LemonReader.
661    ///
662    /// Conversion operator to LemonReader. It make possible
663    /// to access the encapsulated \e LemonReader, this way
664    /// you can attach to this reader new instances of
665    /// \e LemonReader::SectionReader.
666    operator LemonReader&() {
667      return *reader;
668    }
669
[1540]670    /// \brief Executes the reading commands.
[1421]671    ///
[1540]672    /// Executes the reading commands.
[1421]673    void run() {
674      reader->run();
675    }
676
[1901]677
678    /// \brief Returns true if the reader can give back the items by its label.
[1429]679    ///
[1901]680    /// \brief Returns true if the reader can give back the items by its label.
681    bool isLabelReader() const {
682      return nodeset_reader.isLabelReader() &&
[1909]683        u_edgeset_reader.isLabelReader();
[1901]684    }
685
686    /// \brief Gives back the node by its label.
687    ///
688    /// It reads an label from the stream and gives back which node belongs to
[1935]689    /// it. It is possible only if there was read a "label" named node map.
[1901]690    void readLabel(std::istream& is, Node& node) const {
691      return nodeset_reader.readLabel(is, node);
[1429]692    }
693
[1935]694    /// \brief Gives back the edge by its label
[1429]695    ///
[1901]696    /// It reads an label from the stream and gives back which edge belongs to
[1935]697    /// it. It is possible only if there was read a "label" named edge map.
[1901]698    void readLabel(std::istream& is, Edge& edge) const {
[1909]699      return u_edgeset_reader.readLabel(is, edge);
[1429]700    }
701
[1901]702    /// \brief Gives back the undirected edge by its label.
[1429]703    ///
[1901]704    /// It reads an label from the stream and gives back which undirected edge
[1935]705    /// belongs to it. It is possible only if there was read a "label" named
[1429]706    /// edge map.
[1909]707    void readLabel(std::istream& is, UEdge& uedge) const {
708      return u_edgeset_reader.readLabel(is, uedge);
[1429]709    }
710   
711
[1421]712  private:
713
714    LemonReader* reader;
715    bool own_reader;
716
717    DefaultSkipper skipper;
718
719    NodeSetReader<Graph, ReaderTraits> nodeset_reader;
[1909]720    UEdgeSetReader<Graph, ReaderTraits> u_edgeset_reader;
[1421]721
722    NodeReader<Graph> node_reader;
[1909]723    UEdgeReader<Graph> u_edge_reader;
[1421]724   
725    AttributeReader<ReaderTraits> attribute_reader;
726  };
727
728
[1333]729  /// @}
[1137]730}
[1214]731
732#endif
Note: See TracBrowser for help on using the repository browser.