lemon/graph_reader.h
author deba
Tue, 17 Oct 2006 10:50:57 +0000
changeset 2247 269a0dcee70b
parent 2100 6fbe90faf02a
child 2334 c1e936e6a46b
permissions -rw-r--r--
Update the Path concept
Concept check for paths

DirPath renamed to Path
The interface updated to the new lemon interface
Make difference between the empty path and the path from one node
Builder interface have not been changed
// I wanted but there was not accordance about it

UPath is removed
It was a buggy implementation, it could not iterate on the
nodes in the right order
Right way to use undirected paths => path of edges in undirected graphs

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