lemon/graph_reader.h
author deba
Tue, 22 Jul 2008 11:20:06 +0000
changeset 2616 02971275e7bf
parent 2502 9c23c3762bc5
permissions -rw-r--r--
Back port bug fix from hg changeset [0915721396dc]
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@2553
     5
 * Copyright (C) 2003-2008
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@2334
    42
  /// The file to be read may contain several maps and labeled
athos@2334
    43
  /// (designated) nodes or 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@2386
   187
    template <typename ItemReader, typename Map>
deba@1394
   188
    GraphReader& readNodeMap(std::string name, Map& map, 
deba@2386
   189
			     const ItemReader& ir = ItemReader()) {
deba@2386
   190
      nodeset_reader.readNodeMap(name, map, ir);
deba@1421
   191
      return *this;
deba@1421
   192
    }
deba@1421
   193
deba@2386
   194
    template <typename ItemReader, typename Map>
deba@1421
   195
    GraphReader& readNodeMap(std::string name, const Map& map, 
deba@2386
   196
			     const ItemReader& ir = ItemReader()) {
deba@2386
   197
      nodeset_reader.readNodeMap(name, map, ir);
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@2386
   204
    template <typename ItemReader>
deba@1137
   205
    GraphReader& skipNodeMap(std::string name, 
deba@2386
   206
			     const ItemReader& ir = ItemReader()) {
deba@2386
   207
      nodeset_reader.skipNodeMap(name, ir);
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@2386
   230
    template <typename ItemReader, typename Map>
deba@1394
   231
    GraphReader& readEdgeMap(std::string name, Map& map,
deba@2386
   232
			     const ItemReader& ir = ItemReader()) {
deba@2386
   233
      edgeset_reader.readEdgeMap(name, map, ir);
deba@1421
   234
      return *this;
deba@1421
   235
    }
deba@1421
   236
deba@2386
   237
    template <typename ItemReader, typename Map>
deba@1421
   238
    GraphReader& readEdgeMap(std::string name, const Map& map,
deba@2386
   239
			     const ItemReader& ir = ItemReader()) {
deba@2386
   240
      edgeset_reader.readEdgeMap(name, map, ir);
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@2386
   247
    template <typename ItemReader>
deba@1421
   248
    GraphReader& skipEdgeMap(std::string name, 
deba@2386
   249
			     const ItemReader& ir = ItemReader()) {
deba@2386
   250
      edgeset_reader.skipEdgeMap(name, ir);
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@2386
   282
    template <typename ItemReader, typename Value>
deba@1408
   283
    GraphReader& readAttribute(std::string name, Value& value, 
deba@2386
   284
			       const ItemReader& ir = ItemReader()) {
deba@2386
   285
      attribute_reader.readAttribute(name, value, ir);
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@2467
   327
      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),
deba@2467
   446
	uedgeset_reader(*reader, _graph, nodeset_reader, 
deba@1421
   447
			     std::string(), skipper),
deba@1421
   448
	node_reader(*reader, nodeset_reader, std::string()),
deba@2467
   449
	uedge_reader(*reader, uedgeset_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),
deba@2467
   461
	uedgeset_reader(*reader, _graph, nodeset_reader, 
deba@1421
   462
			     std::string(), skipper),
deba@1421
   463
	node_reader(*reader, nodeset_reader, std::string()),
deba@2467
   464
	uedge_reader(*reader, uedgeset_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),
deba@2467
   475
	uedgeset_reader(*reader, _graph, nodeset_reader, 
deba@1421
   476
			     std::string(), skipper),
deba@1421
   477
	node_reader(*reader, nodeset_reader, std::string()),
deba@2467
   478
	uedge_reader(*reader, uedgeset_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@2386
   507
    template <typename ItemReader, typename Map>
klao@1909
   508
    UGraphReader& readNodeMap(std::string name, Map& map, 
deba@2386
   509
                              const ItemReader& ir = ItemReader()) {
deba@2386
   510
      nodeset_reader.readNodeMap(name, map, ir);
deba@1421
   511
      return *this;
deba@1421
   512
    }
deba@1421
   513
deba@2386
   514
    template <typename ItemReader, typename Map>
klao@1909
   515
    UGraphReader& readNodeMap(std::string name, const Map& map, 
deba@2386
   516
                              const ItemReader& ir = ItemReader()) {
deba@2386
   517
      nodeset_reader.readNodeMap(name, map, ir);
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@2386
   524
    template <typename ItemReader>
klao@1909
   525
    UGraphReader& skipNodeMap(std::string name, 
deba@2386
   526
                              const ItemReader& ir = ItemReader()) {
deba@2386
   527
      nodeset_reader.skipNodeMap(name, ir);
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) { 
deba@2467
   536
      uedgeset_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) { 
deba@2467
   542
      uedgeset_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@2386
   550
    template <typename ItemReader, typename Map>
klao@1909
   551
    UGraphReader& readUEdgeMap(std::string name, Map& map,
deba@2386
   552
                               const ItemReader& ir = ItemReader()) {
deba@2467
   553
      uedgeset_reader.readUEdgeMap(name, map, ir);
deba@1421
   554
      return *this;
deba@1421
   555
    }
deba@1421
   556
deba@2386
   557
    template <typename ItemReader, typename Map>
klao@1909
   558
    UGraphReader& readUEdgeMap(std::string name, const Map& map,
deba@2386
   559
                               const ItemReader& ir = ItemReader()) {
deba@2467
   560
      uedgeset_reader.readUEdgeMap(name, map, ir);
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@2386
   567
    template <typename ItemReader>
klao@1909
   568
    UGraphReader& skipUEdgeMap(std::string name,
deba@2386
   569
				       const ItemReader& ir = ItemReader()) {
deba@2467
   570
      uedgeset_reader.skipUMap(name, ir);
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) { 
deba@2467
   580
      uedgeset_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) { 
deba@2467
   586
      uedgeset_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@2386
   594
    template <typename ItemReader, typename Map>
klao@1909
   595
    UGraphReader& readEdgeMap(std::string name, Map& map,
deba@2386
   596
                              const ItemReader& ir = ItemReader()) {
deba@2467
   597
      uedgeset_reader.readEdgeMap(name, map, ir);
deba@1421
   598
      return *this;
deba@1421
   599
    }
deba@1421
   600
deba@2386
   601
    template <typename ItemReader, typename Map>
klao@1909
   602
    UGraphReader& readEdgeMap(std::string name, const Map& map,
deba@2386
   603
                              const ItemReader& ir = ItemReader()) {
deba@2467
   604
      uedgeset_reader.readEdgeMap(name, map, ir);
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@2386
   611
    template <typename ItemReader>
klao@1909
   612
    UGraphReader& skipEdgeMap(std::string name,
deba@2386
   613
                              const ItemReader& ir = ItemReader()) {
deba@2467
   614
      uedgeset_reader.skipEdgeMap(name, ir);
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) {
deba@2467
   630
      uedge_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) {
deba@2467
   638
      uedge_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@2386
   653
    template <typename ItemReader, typename Value>
klao@1909
   654
    UGraphReader& readAttribute(std::string name, Value& value, 
deba@2386
   655
			       const ItemReader& ir = ItemReader()) {
deba@2386
   656
      attribute_reader.readAttribute(name, value, ir);
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@2467
   680
    /// 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() && 
deba@2467
   683
        uedgeset_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 {
deba@2467
   699
      return uedgeset_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 {
deba@2467
   708
      return uedgeset_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;
deba@2467
   720
    UEdgeSetReader<Graph, ReaderTraits> uedgeset_reader;
deba@1421
   721
deba@1421
   722
    NodeReader<Graph> node_reader;
deba@2467
   723
    UEdgeReader<Graph> uedge_reader;
deba@1421
   724
    
deba@1421
   725
    AttributeReader<ReaderTraits> attribute_reader;
deba@1421
   726
  };
deba@1421
   727
deba@2502
   728
  /// \brief The bipartite graph reader class.
deba@2502
   729
  ///
deba@2502
   730
  /// The \c BpUGraphReader class provides the graph input. 
deba@2502
   731
  /// Before you read this documentation it might be useful to read the general
deba@2502
   732
  /// description of  \ref graph-io-page "Graph Input-Output".
deba@2502
   733
  ///
deba@2502
   734
  /// The given file format may contain several maps and labeled nodes or 
deba@2502
   735
  /// edges.
deba@2502
   736
  ///
deba@2502
   737
  /// If you read a graph you need not read all the maps and items just those
deba@2502
   738
  /// that you need. The interface of the \c BpUGraphReader is very similar
deba@2502
   739
  /// to the BpUGraphWriter but the reading method does not depend on the
deba@2502
   740
  /// order of the given commands.
deba@2502
   741
  ///
deba@2502
   742
  /// The reader object suppose that each not read value does not contain 
deba@2502
   743
  /// whitespaces, therefore it has some extra possibilities to control how
deba@2502
   744
  /// it should skip the values when the string representation contains spaces.
deba@2502
   745
  ///
deba@2502
   746
  ///\code
deba@2502
   747
  /// BpUGraphReader<ListBpUGraph> reader(std::cin, graph);
deba@2502
   748
  ///\endcode
deba@2502
   749
  ///
deba@2502
   750
  /// The \c readANodeMap() function reads a map from the A-part of
deba@2502
   751
  /// the\c \@bpnodeset section, while the \c readBNodeMap() reads
deba@2502
   752
  /// from the B-part of the section.  If you use the \c readNodeMap()
deba@2502
   753
  /// function, then the given map should appear in both part of the
deba@2502
   754
  /// section. If there is a map that you do not want to read from the
deba@2502
   755
  /// file and there is whitespace in the string represenation of the
deba@2502
   756
  /// values then you should call the \c skipANodeMap(), \c
deba@2502
   757
  /// skipBNodeMap() or \c skipNodeMap() template member function with
deba@2502
   758
  /// proper parameters.
deba@2502
   759
  ///
deba@2502
   760
  ///\code
deba@2502
   761
  /// reader.readNodeMap("coords", coords);
deba@2502
   762
  /// reader.readANodeMap("range", range);
deba@2502
   763
  /// reader.readANodeMap("benefit", benefit);
deba@2502
   764
  ///
deba@2502
   765
  /// reader.skipNodeMap("description", desc);
deba@2502
   766
  ///
deba@2502
   767
  /// reader.readNodeMap("color", colorMap);
deba@2502
   768
  ///\endcode
deba@2502
   769
  ///
deba@2502
   770
  /// With the \c readUEdgeMap() member function you can give an 
deba@2502
   771
  /// uedge map reading command similar to the NodeMaps. 
deba@2502
   772
  ///
deba@2502
   773
  ///\code
deba@2502
   774
  /// reader.readUEdgeMap("capacity", capacityMap);
deba@2502
   775
  /// reader.readEdgeMap("flow", flowMap);
deba@2502
   776
  ///\endcode 
deba@2502
   777
  ///
deba@2502
   778
  /// With \c readNode() and \c readUEdge() functions you can read 
deba@2502
   779
  /// labeled Nodes and UEdges.
deba@2502
   780
  ///
deba@2502
   781
  ///\code
deba@2502
   782
  /// reader.readNode("source", sourceNode);
deba@2502
   783
  /// reader.readNode("target", targetNode);
deba@2502
   784
  ///
deba@2502
   785
  /// reader.readUEdge("observed", uEdge);
deba@2502
   786
  ///\endcode
deba@2502
   787
  ///
deba@2502
   788
  /// With the \c readAttribute() functions you can read an attribute
deba@2502
   789
  /// in a variable. You can specify the reader for the attribute as
deba@2502
   790
  /// the nodemaps.
deba@2502
   791
  ///
deba@2502
   792
  /// After you give all read commands you must call the \c run() member
deba@2502
   793
  /// function, which execute all the commands.
deba@2502
   794
  ///
deba@2502
   795
  ///\code
deba@2502
   796
  /// reader.run();
deba@2502
   797
  ///\endcode
deba@2502
   798
  ///
deba@2502
   799
  /// \see GraphReader
deba@2502
   800
  /// \see DefaultReaderTraits
deba@2502
   801
  /// \see \ref UGraphWriter
deba@2502
   802
  /// \see \ref graph-io-page
deba@2502
   803
  ///
deba@2502
   804
  /// \author Balazs Dezso
deba@2502
   805
  template <typename _Graph, typename _ReaderTraits = DefaultReaderTraits> 
deba@2502
   806
  class BpUGraphReader {
deba@2502
   807
  public:
deba@2502
   808
    
deba@2502
   809
    typedef _Graph Graph;
deba@2502
   810
    typedef typename Graph::Node Node;
deba@2502
   811
    typedef typename Graph::Edge Edge;
deba@2502
   812
    typedef typename Graph::UEdge UEdge;
deba@2502
   813
deba@2502
   814
    typedef _ReaderTraits ReaderTraits;
deba@2502
   815
    typedef typename ReaderTraits::Skipper DefaultSkipper;
deba@2502
   816
deba@2502
   817
    /// \brief Construct a new BpUGraphReader.
deba@2502
   818
    ///
deba@2502
   819
    /// Construct a new BpUGraphReader. It reads into the given graph
deba@2502
   820
    /// and it use the given reader as the default skipper.
deba@2502
   821
    BpUGraphReader(std::istream& _is, Graph& _graph, 
deba@2502
   822
		     const DefaultSkipper& _skipper = DefaultSkipper()) 
deba@2502
   823
      : reader(new LemonReader(_is)), own_reader(true), skipper(_skipper),
deba@2502
   824
	nodeset_reader(*reader, _graph, std::string(), skipper),
deba@2502
   825
	uedgeset_reader(*reader, _graph, nodeset_reader, 
deba@2502
   826
			     std::string(), skipper),
deba@2502
   827
	node_reader(*reader, nodeset_reader, std::string()),
deba@2502
   828
	uedge_reader(*reader, uedgeset_reader, std::string()),
deba@2502
   829
	attribute_reader(*reader, std::string()) {}
deba@2502
   830
deba@2502
   831
    /// \brief Construct a new BpUGraphReader.
deba@2502
   832
    ///
deba@2502
   833
    /// Construct a new BpUGraphReader. It reads into the given graph
deba@2502
   834
    /// and it use the given reader as the default skipper.
deba@2502
   835
    BpUGraphReader(const std::string& _filename, Graph& _graph, 
deba@2502
   836
		     const DefaultSkipper& _skipper = DefaultSkipper()) 
deba@2502
   837
      : reader(new LemonReader(_filename)), own_reader(true), 
deba@2502
   838
	skipper(_skipper),
deba@2502
   839
	nodeset_reader(*reader, _graph, std::string(), skipper),
deba@2502
   840
	uedgeset_reader(*reader, _graph, nodeset_reader, 
deba@2502
   841
			     std::string(), skipper),
deba@2502
   842
	node_reader(*reader, nodeset_reader, std::string()),
deba@2502
   843
	uedge_reader(*reader, uedgeset_reader, std::string()),
deba@2502
   844
	attribute_reader(*reader, std::string()) {}
deba@2502
   845
deba@2502
   846
    /// \brief Construct a new BpUGraphReader.
deba@2502
   847
    ///
deba@2502
   848
    /// Construct a new BpUGraphReader. It reads into the given graph
deba@2502
   849
    /// and it use the given reader as the default skipper.
deba@2502
   850
    BpUGraphReader(LemonReader& _reader, Graph& _graph, 
deba@2502
   851
		     const DefaultSkipper& _skipper = DefaultSkipper()) 
deba@2502
   852
      : reader(_reader), own_reader(false), skipper(_skipper),
deba@2502
   853
	nodeset_reader(*reader, _graph, std::string(), skipper),
deba@2502
   854
	uedgeset_reader(*reader, _graph, nodeset_reader, 
deba@2502
   855
			     std::string(), skipper),
deba@2502
   856
	node_reader(*reader, nodeset_reader, std::string()),
deba@2502
   857
	uedge_reader(*reader, uedgeset_reader, std::string()),
deba@2502
   858
	attribute_reader(*reader, std::string()) {}
deba@2502
   859
deba@2502
   860
    /// \brief Destruct the graph reader.
deba@2502
   861
    ///
deba@2502
   862
    /// Destruct the graph reader.
deba@2502
   863
    ~BpUGraphReader() {
deba@2502
   864
      if (own_reader) 
deba@2502
   865
	delete reader;
deba@2502
   866
    }
deba@2502
   867
deba@2502
   868
    /// \brief Give a new node map reading command to the reader.
deba@2502
   869
    ///
deba@2502
   870
    /// Give a new node map reading command to the reader.
deba@2502
   871
    template <typename Map>
deba@2502
   872
    BpUGraphReader& readNodeMap(std::string name, Map& map) {
deba@2502
   873
      nodeset_reader.readNodeMap(name, map);
deba@2502
   874
      return *this;
deba@2502
   875
    }
deba@2502
   876
deba@2502
   877
    template <typename Map>
deba@2502
   878
    BpUGraphReader& readNodeMap(std::string name, const Map& map) {
deba@2502
   879
      nodeset_reader.readNodeMap(name, map);
deba@2502
   880
      return *this;
deba@2502
   881
    }
deba@2502
   882
deba@2502
   883
    /// \brief Give a new node map reading command to the reader.
deba@2502
   884
    ///
deba@2502
   885
    /// Give a new node map reading command to the reader.
deba@2502
   886
    template <typename ItemReader, typename Map>
deba@2502
   887
    BpUGraphReader& readNodeMap(std::string name, Map& map, 
deba@2502
   888
                              const ItemReader& ir = ItemReader()) {
deba@2502
   889
      nodeset_reader.readNodeMap(name, map, ir);
deba@2502
   890
      return *this;
deba@2502
   891
    }
deba@2502
   892
deba@2502
   893
    template <typename ItemReader, typename Map>
deba@2502
   894
    BpUGraphReader& readNodeMap(std::string name, const Map& map, 
deba@2502
   895
                              const ItemReader& ir = ItemReader()) {
deba@2502
   896
      nodeset_reader.readNodeMap(name, map, ir);
deba@2502
   897
      return *this;
deba@2502
   898
    }
deba@2502
   899
deba@2502
   900
    /// \brief Give a new node map skipping command to the reader.
deba@2502
   901
    ///
deba@2502
   902
    /// Give a new node map skipping command to the reader.
deba@2502
   903
    template <typename ItemReader>
deba@2502
   904
    BpUGraphReader& skipNodeMap(std::string name, 
deba@2502
   905
                              const ItemReader& ir = ItemReader()) {
deba@2502
   906
      nodeset_reader.skipNodeMap(name, ir);
deba@2502
   907
      return *this;
deba@2502
   908
    }
deba@2502
   909
deba@2502
   910
    /// \brief Give a new A-node map reading command to the reader.
deba@2502
   911
    ///
deba@2502
   912
    /// Give a new A-node map reading command to the reader.
deba@2502
   913
    template <typename Map>
deba@2502
   914
    BpUGraphReader& readANodeMap(std::string name, Map& map) {
deba@2502
   915
      nodeset_reader.readANodeMap(name, map);
deba@2502
   916
      return *this;
deba@2502
   917
    }
deba@2502
   918
deba@2502
   919
    template <typename Map>
deba@2502
   920
    BpUGraphReader& readANodeMap(std::string name, const Map& map) {
deba@2502
   921
      nodeset_reader.readANodeMap(name, map);
deba@2502
   922
      return *this;
deba@2502
   923
    }
deba@2502
   924
deba@2502
   925
    /// \brief Give a new A-node map reading command to the reader.
deba@2502
   926
    ///
deba@2502
   927
    /// Give a new A-node map reading command to the reader.
deba@2502
   928
    template <typename ItemReader, typename Map>
deba@2502
   929
    BpUGraphReader& readANodeMap(std::string name, Map& map, 
deba@2502
   930
                              const ItemReader& ir = ItemReader()) {
deba@2502
   931
      nodeset_reader.readANodeMap(name, map, ir);
deba@2502
   932
      return *this;
deba@2502
   933
    }
deba@2502
   934
deba@2502
   935
    template <typename ItemReader, typename Map>
deba@2502
   936
    BpUGraphReader& readANodeMap(std::string name, const Map& map, 
deba@2502
   937
                              const ItemReader& ir = ItemReader()) {
deba@2502
   938
      nodeset_reader.readNodeMap(name, map, ir);
deba@2502
   939
      return *this;
deba@2502
   940
    }
deba@2502
   941
deba@2502
   942
    /// \brief Give a new A-node map skipping command to the reader.
deba@2502
   943
    ///
deba@2502
   944
    /// Give a new A-node map skipping command to the reader.
deba@2502
   945
    template <typename ItemReader>
deba@2502
   946
    BpUGraphReader& skipANodeMap(std::string name, 
deba@2502
   947
                              const ItemReader& ir = ItemReader()) {
deba@2502
   948
      nodeset_reader.skipANodeMap(name, ir);
deba@2502
   949
      return *this;
deba@2502
   950
    }
deba@2502
   951
deba@2502
   952
    /// \brief Give a new B-node map reading command to the reader.
deba@2502
   953
    ///
deba@2502
   954
    /// Give a new B-node map reading command to the reader.
deba@2502
   955
    template <typename Map>
deba@2502
   956
    BpUGraphReader& readBNodeMap(std::string name, Map& map) {
deba@2502
   957
      nodeset_reader.readBNodeMap(name, map);
deba@2502
   958
      return *this;
deba@2502
   959
    }
deba@2502
   960
deba@2502
   961
    template <typename Map>
deba@2502
   962
    BpUGraphReader& readBNodeMap(std::string name, const Map& map) {
deba@2502
   963
      nodeset_reader.readBNodeMap(name, map);
deba@2502
   964
      return *this;
deba@2502
   965
    }
deba@2502
   966
deba@2502
   967
    /// \brief Give a new B-node map reading command to the reader.
deba@2502
   968
    ///
deba@2502
   969
    /// Give a new B-node map reading command to the reader.
deba@2502
   970
    template <typename ItemReader, typename Map>
deba@2502
   971
    BpUGraphReader& readBNodeMap(std::string name, Map& map, 
deba@2502
   972
                              const ItemReader& ir = ItemReader()) {
deba@2502
   973
      nodeset_reader.readBNodeMap(name, map, ir);
deba@2502
   974
      return *this;
deba@2502
   975
    }
deba@2502
   976
deba@2502
   977
    template <typename ItemReader, typename Map>
deba@2502
   978
    BpUGraphReader& readBNodeMap(std::string name, const Map& map, 
deba@2502
   979
                              const ItemReader& ir = ItemReader()) {
deba@2502
   980
      nodeset_reader.readNodeMap(name, map, ir);
deba@2502
   981
      return *this;
deba@2502
   982
    }
deba@2502
   983
deba@2502
   984
    /// \brief Give a new B-node map skipping command to the reader.
deba@2502
   985
    ///
deba@2502
   986
    /// Give a new B-node map skipping command to the reader.
deba@2502
   987
    template <typename ItemReader>
deba@2502
   988
    BpUGraphReader& skipBNodeMap(std::string name, 
deba@2502
   989
                              const ItemReader& ir = ItemReader()) {
deba@2502
   990
      nodeset_reader.skipBNodeMap(name, ir);
deba@2502
   991
      return *this;
deba@2502
   992
    }
deba@2502
   993
deba@2502
   994
    /// \brief Give a new undirected edge map reading command to the reader.
deba@2502
   995
    ///
deba@2502
   996
    /// Give a new undirected edge map reading command to the reader.
deba@2502
   997
    template <typename Map>
deba@2502
   998
    BpUGraphReader& readUEdgeMap(std::string name, Map& map) { 
deba@2502
   999
      uedgeset_reader.readUEdgeMap(name, map);
deba@2502
  1000
      return *this;
deba@2502
  1001
    }
deba@2502
  1002
deba@2502
  1003
    template <typename Map>
deba@2502
  1004
    BpUGraphReader& readUEdgeMap(std::string name, const Map& map) { 
deba@2502
  1005
      uedgeset_reader.readUEdgeMap(name, map);
deba@2502
  1006
      return *this;
deba@2502
  1007
    }
deba@2502
  1008
deba@2502
  1009
deba@2502
  1010
    /// \brief Give a new undirected edge map reading command to the reader.
deba@2502
  1011
    ///
deba@2502
  1012
    /// Give a new undirected edge map reading command to the reader.
deba@2502
  1013
    template <typename ItemReader, typename Map>
deba@2502
  1014
    BpUGraphReader& readUEdgeMap(std::string name, Map& map,
deba@2502
  1015
                               const ItemReader& ir = ItemReader()) {
deba@2502
  1016
      uedgeset_reader.readUEdgeMap(name, map, ir);
deba@2502
  1017
      return *this;
deba@2502
  1018
    }
deba@2502
  1019
deba@2502
  1020
    template <typename ItemReader, typename Map>
deba@2502
  1021
    BpUGraphReader& readUEdgeMap(std::string name, const Map& map,
deba@2502
  1022
                               const ItemReader& ir = ItemReader()) {
deba@2502
  1023
      uedgeset_reader.readUEdgeMap(name, map, ir);
deba@2502
  1024
      return *this;
deba@2502
  1025
    }
deba@2502
  1026
deba@2502
  1027
    /// \brief Give a new undirected edge map skipping command to the reader.
deba@2502
  1028
    ///
deba@2502
  1029
    /// Give a new undirected edge map skipping command to the reader.
deba@2502
  1030
    template <typename ItemReader>
deba@2502
  1031
    BpUGraphReader& skipUEdgeMap(std::string name,
deba@2502
  1032
				       const ItemReader& ir = ItemReader()) {
deba@2502
  1033
      uedgeset_reader.skipUMap(name, ir);
deba@2502
  1034
      return *this;
deba@2502
  1035
    }
deba@2502
  1036
deba@2502
  1037
deba@2502
  1038
    /// \brief Give a new edge map reading command to the reader.
deba@2502
  1039
    ///
deba@2502
  1040
    /// Give a new edge map reading command to the reader.
deba@2502
  1041
    template <typename Map>
deba@2502
  1042
    BpUGraphReader& readEdgeMap(std::string name, Map& map) { 
deba@2502
  1043
      uedgeset_reader.readEdgeMap(name, map);
deba@2502
  1044
      return *this;
deba@2502
  1045
    }
deba@2502
  1046
deba@2502
  1047
    template <typename Map>
deba@2502
  1048
    BpUGraphReader& readEdgeMap(std::string name, const Map& map) { 
deba@2502
  1049
      uedgeset_reader.readEdgeMap(name, map);
deba@2502
  1050
      return *this;
deba@2502
  1051
    }
deba@2502
  1052
deba@2502
  1053
deba@2502
  1054
    /// \brief Give a new edge map reading command to the reader.
deba@2502
  1055
    ///
deba@2502
  1056
    /// Give a new edge map reading command to the reader.
deba@2502
  1057
    template <typename ItemReader, typename Map>
deba@2502
  1058
    BpUGraphReader& readEdgeMap(std::string name, Map& map,
deba@2502
  1059
                              const ItemReader& ir = ItemReader()) {
deba@2502
  1060
      uedgeset_reader.readEdgeMap(name, map, ir);
deba@2502
  1061
      return *this;
deba@2502
  1062
    }
deba@2502
  1063
deba@2502
  1064
    template <typename ItemReader, typename Map>
deba@2502
  1065
    BpUGraphReader& readEdgeMap(std::string name, const Map& map,
deba@2502
  1066
                              const ItemReader& ir = ItemReader()) {
deba@2502
  1067
      uedgeset_reader.readEdgeMap(name, map, ir);
deba@2502
  1068
      return *this;
deba@2502
  1069
    }
deba@2502
  1070
deba@2502
  1071
    /// \brief Give a new edge map skipping command to the reader.
deba@2502
  1072
    ///
deba@2502
  1073
    /// Give a new edge map skipping command to the reader.
deba@2502
  1074
    template <typename ItemReader>
deba@2502
  1075
    BpUGraphReader& skipEdgeMap(std::string name,
deba@2502
  1076
                              const ItemReader& ir = ItemReader()) {
deba@2502
  1077
      uedgeset_reader.skipEdgeMap(name, ir);
deba@2502
  1078
      return *this;
deba@2502
  1079
    }
deba@2502
  1080
deba@2502
  1081
    /// \brief Give a new labeled node reading command to the reader.
deba@2502
  1082
    ///
deba@2502
  1083
    /// Give a new labeled node reading command to the reader.
deba@2502
  1084
    BpUGraphReader& readNode(std::string name, Node& node) {
deba@2502
  1085
      node_reader.readNode(name, node);
deba@2502
  1086
      return *this;
deba@2502
  1087
    }
deba@2502
  1088
deba@2502
  1089
    /// \brief Give a new labeled edge reading command to the reader.
deba@2502
  1090
    ///
deba@2502
  1091
    /// Give a new labeled edge reading command to the reader.
deba@2502
  1092
    BpUGraphReader& readEdge(std::string name, Edge& edge) {
deba@2502
  1093
      uedge_reader.readEdge(name, edge);
deba@2502
  1094
    }
deba@2502
  1095
deba@2502
  1096
    /// \brief Give a new labeled undirected edge reading command to the
deba@2502
  1097
    /// reader.
deba@2502
  1098
    ///
deba@2502
  1099
    /// Give a new labeled undirected edge reading command to the reader.
deba@2502
  1100
    BpUGraphReader& readUEdge(std::string name, UEdge& edge) {
deba@2502
  1101
      uedge_reader.readUEdge(name, edge);
deba@2502
  1102
    }
deba@2502
  1103
deba@2502
  1104
    /// \brief Give a new attribute reading command.
deba@2502
  1105
    ///
deba@2502
  1106
    ///  Give a new attribute reading command.
deba@2502
  1107
    template <typename Value>
deba@2502
  1108
    BpUGraphReader& readAttribute(std::string name, Value& value) {
deba@2502
  1109
      attribute_reader.readAttribute(name, value);
deba@2502
  1110
      return *this;
deba@2502
  1111
    }
deba@2502
  1112
    
deba@2502
  1113
    /// \brief Give a new attribute reading command.
deba@2502
  1114
    ///
deba@2502
  1115
    ///  Give a new attribute reading command.
deba@2502
  1116
    template <typename ItemReader, typename Value>
deba@2502
  1117
    BpUGraphReader& readAttribute(std::string name, Value& value, 
deba@2502
  1118
			       const ItemReader& ir = ItemReader()) {
deba@2502
  1119
      attribute_reader.readAttribute(name, value, ir);
deba@2502
  1120
      return *this;
deba@2502
  1121
    }
deba@2502
  1122
deba@2502
  1123
    /// \brief Conversion operator to LemonReader.
deba@2502
  1124
    ///
deba@2502
  1125
    /// Conversion operator to LemonReader. It make possible
deba@2502
  1126
    /// to access the encapsulated \e LemonReader, this way
deba@2502
  1127
    /// you can attach to this reader new instances of 
deba@2502
  1128
    /// \e LemonReader::SectionReader.
deba@2502
  1129
    operator LemonReader&() {
deba@2502
  1130
      return *reader;
deba@2502
  1131
    }
deba@2502
  1132
deba@2502
  1133
    /// \brief Executes the reading commands.
deba@2502
  1134
    ///
deba@2502
  1135
    /// Executes the reading commands.
deba@2502
  1136
    void run() {
deba@2502
  1137
      reader->run();
deba@2502
  1138
    }
deba@2502
  1139
deba@2502
  1140
deba@2502
  1141
    /// \brief Returns true if the reader can give back the items by its label.
deba@2502
  1142
    ///
deba@2502
  1143
    /// Returns true if the reader can give back the items by its label.
deba@2502
  1144
    bool isLabelReader() const {
deba@2502
  1145
      return nodeset_reader.isLabelReader() && 
deba@2502
  1146
        uedgeset_reader.isLabelReader();
deba@2502
  1147
    }
deba@2502
  1148
deba@2502
  1149
    /// \brief Gives back the node by its label.
deba@2502
  1150
    ///
deba@2502
  1151
    /// It reads an label from the stream and gives back which node belongs to
deba@2502
  1152
    /// it. It is possible only if there was read a "label" named node map.
deba@2502
  1153
    void readLabel(std::istream& is, Node& node) const {
deba@2502
  1154
      return nodeset_reader.readLabel(is, node);
deba@2502
  1155
    } 
deba@2502
  1156
deba@2502
  1157
    /// \brief Gives back the edge by its label
deba@2502
  1158
    ///
deba@2502
  1159
    /// It reads an label from the stream and gives back which edge belongs to
deba@2502
  1160
    /// it. It is possible only if there was read a "label" named edge map.
deba@2502
  1161
    void readLabel(std::istream& is, Edge& edge) const {
deba@2502
  1162
      return uedgeset_reader.readLabel(is, edge);
deba@2502
  1163
    } 
deba@2502
  1164
deba@2502
  1165
    /// \brief Gives back the undirected edge by its label.
deba@2502
  1166
    ///
deba@2502
  1167
    /// It reads an label from the stream and gives back which undirected edge 
deba@2502
  1168
    /// belongs to it. It is possible only if there was read a "label" named 
deba@2502
  1169
    /// edge map.
deba@2502
  1170
    void readLabel(std::istream& is, UEdge& uedge) const {
deba@2502
  1171
      return uedgeset_reader.readLabel(is, uedge);
deba@2502
  1172
    } 
deba@2502
  1173
    
deba@2502
  1174
deba@2502
  1175
  private:
deba@2502
  1176
deba@2502
  1177
    LemonReader* reader;
deba@2502
  1178
    bool own_reader;
deba@2502
  1179
deba@2502
  1180
    DefaultSkipper skipper;
deba@2502
  1181
deba@2502
  1182
    BpNodeSetReader<Graph, ReaderTraits> nodeset_reader;
deba@2502
  1183
    UEdgeSetReader<Graph, ReaderTraits> uedgeset_reader;
deba@2502
  1184
deba@2502
  1185
    NodeReader<Graph> node_reader;
deba@2502
  1186
    UEdgeReader<Graph> uedge_reader;
deba@2502
  1187
    
deba@2502
  1188
    AttributeReader<ReaderTraits> attribute_reader;
deba@2502
  1189
  };
deba@2502
  1190
deba@1421
  1191
deba@1333
  1192
  /// @}
deba@1137
  1193
}
deba@1214
  1194
deba@1214
  1195
#endif