1.1 --- a/src/lemon/graph_reader.h Sat May 21 21:04:57 2005 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,808 +0,0 @@
1.4 -/* -*- C++ -*-
1.5 - * src/lemon/graph_reader.h - Part of LEMON, a generic C++ optimization library
1.6 - *
1.7 - * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.8 - * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.9 - *
1.10 - * Permission to use, modify and distribute this software is granted
1.11 - * provided that this copyright notice appears in all copies. For
1.12 - * precise terms see the accompanying LICENSE file.
1.13 - *
1.14 - * This software is provided "AS IS" with no warranty of any kind,
1.15 - * express or implied, and with no claim as to its suitability for any
1.16 - * purpose.
1.17 - *
1.18 - */
1.19 -
1.20 -///\ingroup io_group
1.21 -///\file
1.22 -///\brief Lemon Graph Format reader.
1.23 -
1.24 -#ifndef LEMON_GRAPH_READER_H
1.25 -#define LEMON_GRAPH_READER_H
1.26 -
1.27 -#include <iostream>
1.28 -
1.29 -#include <lemon/error.h>
1.30 -#include <lemon/lemon_reader.h>
1.31 -
1.32 -namespace lemon {
1.33 -
1.34 - /// \addtogroup io_group
1.35 - /// @{
1.36 -
1.37 - /// \brief The graph reader class.
1.38 - ///
1.39 - /// The given file format may contain several maps and labeled nodes or
1.40 - /// edges.
1.41 - ///
1.42 - /// If you read a graph you need not read all the maps and items just those
1.43 - /// that you need. The interface of the \c GraphReader is very similar to
1.44 - /// the GraphWriter but the reading method does not depend on the order the
1.45 - /// given commands.
1.46 - ///
1.47 - /// The reader object suppose that each not readed value does not contain
1.48 - /// whitespaces, therefore it has some extra possibilities to control how
1.49 - /// it should skip the values when the string representation contains spaces.
1.50 - ///
1.51 - /// \code
1.52 - /// GraphReader<ListGraph> reader(std::cin, graph);
1.53 - /// \endcode
1.54 - ///
1.55 - /// The \c readNodeMap() function reads a map from the \c \@nodeset section.
1.56 - /// If there is a map that you do not want to read from the file and there is
1.57 - /// whitespace in the string represenation of the values then you should
1.58 - /// call the \c skipNodeMap() template member function with proper
1.59 - /// parameters.
1.60 - ///
1.61 - /// \code
1.62 - /// reader.readNodeMap("coords", coords);
1.63 - ///
1.64 - /// reader.readNodeMap<QuotedStringReader>("label", labelMap);
1.65 - /// reader.skipNodeMap<QuotedStringReader>("description");
1.66 - ///
1.67 - /// reader.readNodeMap("color", colorMap);
1.68 - /// \endcode
1.69 - ///
1.70 - /// With the \c readEdgeMap() member function you can give an edge map
1.71 - /// reading command similar to the NodeMaps.
1.72 - ///
1.73 - /// \code
1.74 - /// reader.readEdgeMap("weight", weightMap);
1.75 - /// reader.readEdgeMap("label", labelMap);
1.76 - /// \endcode
1.77 - ///
1.78 - /// With \c readNode() and \c readEdge() functions you can read
1.79 - /// labeled Nodes and Edges.
1.80 - ///
1.81 - /// \code
1.82 - /// reader.readNode("source", sourceNode);
1.83 - /// reader.readNode("target", targetNode);
1.84 - ///
1.85 - /// reader.readEdge("observed", edge);
1.86 - /// \endcode
1.87 - ///
1.88 - /// With the \c readAttribute() functions you can read an attribute
1.89 - /// in a variable. You can specify the reader for the attribute as
1.90 - /// the nodemaps.
1.91 - ///
1.92 - /// After you give all read commands you must call the \c run() member
1.93 - /// function, which execute all the commands.
1.94 - ///
1.95 - /// \code
1.96 - /// reader.run();
1.97 - /// \endcode
1.98 - ///
1.99 - /// \see DefaultReaderTraits
1.100 - /// \see QuotedStringReader
1.101 - /// \see \ref GraphWriter
1.102 - /// \see \ref graph-io-page
1.103 - /// \author Balazs Dezso
1.104 - template <typename _Graph, typename _ReaderTraits = DefaultReaderTraits>
1.105 - class GraphReader {
1.106 - public:
1.107 -
1.108 - typedef _Graph Graph;
1.109 - typedef typename Graph::Node Node;
1.110 - typedef typename Graph::Edge Edge;
1.111 -
1.112 - typedef _ReaderTraits ReaderTraits;
1.113 - typedef typename ReaderTraits::Skipper DefaultSkipper;
1.114 -
1.115 - /// \brief Construct a new GraphReader.
1.116 - ///
1.117 - /// Construct a new GraphReader. It reads into the given graph
1.118 - /// and it use the given reader as the default skipper.
1.119 - GraphReader(std::istream& _is,
1.120 - typename SmartParameter<Graph>::Type _graph,
1.121 - const DefaultSkipper& _skipper = DefaultSkipper())
1.122 - : reader(new LemonReader(_is)), own_reader(true), skipper(_skipper),
1.123 - nodeset_reader(*reader, _graph, std::string(), skipper),
1.124 - edgeset_reader(*reader, _graph, nodeset_reader,
1.125 - std::string(), skipper),
1.126 - node_reader(*reader, nodeset_reader, std::string()),
1.127 - edge_reader(*reader, edgeset_reader, std::string()),
1.128 - attribute_reader(*reader, std::string()) {}
1.129 -
1.130 - /// \brief Construct a new GraphReader.
1.131 - ///
1.132 - /// Construct a new GraphReader. It reads into the given graph
1.133 - /// and it use the given reader as the default skipper.
1.134 - GraphReader(const std::string& _filename,
1.135 - typename SmartParameter<Graph>::Type _graph,
1.136 - const DefaultSkipper& _skipper = DefaultSkipper())
1.137 - : reader(new LemonReader(_filename)), own_reader(true),
1.138 - skipper(_skipper),
1.139 - nodeset_reader(*reader, _graph, std::string(), skipper),
1.140 - edgeset_reader(*reader, _graph, nodeset_reader,
1.141 - std::string(), skipper),
1.142 - node_reader(*reader, nodeset_reader, std::string()),
1.143 - edge_reader(*reader, edgeset_reader, std::string()),
1.144 - attribute_reader(*reader, std::string()) {}
1.145 -
1.146 - /// \brief Construct a new GraphReader.
1.147 - ///
1.148 - /// Construct a new GraphReader. It reads into the given graph
1.149 - /// and it use the given reader as the default skipper.
1.150 - GraphReader(LemonReader& _reader,
1.151 - typename SmartParameter<Graph>::Type _graph,
1.152 - const DefaultSkipper& _skipper = DefaultSkipper())
1.153 - : reader(_reader), own_reader(false), skipper(_skipper),
1.154 - nodeset_reader(*reader, _graph, std::string(), skipper),
1.155 - edgeset_reader(*reader, _graph, nodeset_reader,
1.156 - std::string(), skipper),
1.157 - node_reader(*reader, nodeset_reader, std::string()),
1.158 - edge_reader(*reader, edgeset_reader, std::string()),
1.159 - attribute_reader(*reader, std::string()) {}
1.160 -
1.161 - /// \brief Destruct the graph reader.
1.162 - ///
1.163 - /// Destruct the graph reader.
1.164 - ~GraphReader() {
1.165 - if (own_reader)
1.166 - delete reader;
1.167 - }
1.168 -
1.169 - /// \brief Add a new node map reader command for the reader.
1.170 - ///
1.171 - /// Add a new node map reader command for the reader.
1.172 - template <typename Map>
1.173 - GraphReader& readNodeMap(std::string name, Map& map) {
1.174 - nodeset_reader.readNodeMap(name, map);
1.175 - return *this;
1.176 - }
1.177 -
1.178 - template <typename Map>
1.179 - GraphReader& readNodeMap(std::string name, const Map& map) {
1.180 - nodeset_reader.readNodeMap(name, map);
1.181 - return *this;
1.182 - }
1.183 -
1.184 - /// \brief Add a new node map reader command for the reader.
1.185 - ///
1.186 - /// Add a new node map reader command for the reader.
1.187 - template <typename Reader, typename Map>
1.188 - GraphReader& readNodeMap(std::string name, Map& map,
1.189 - const Reader& reader = Reader()) {
1.190 - nodeset_reader.readNodeMap(name, map, reader);
1.191 - return *this;
1.192 - }
1.193 -
1.194 - template <typename Reader, typename Map>
1.195 - GraphReader& readNodeMap(std::string name, const Map& map,
1.196 - const Reader& reader = Reader()) {
1.197 - nodeset_reader.readNodeMap(name, map, reader);
1.198 - return *this;
1.199 - }
1.200 -
1.201 - /// \brief Add a new node map skipper command for the reader.
1.202 - ///
1.203 - /// Add a new node map skipper command for the reader.
1.204 - template <typename Reader>
1.205 - GraphReader& skipNodeMap(std::string name,
1.206 - const Reader& reader = Reader()) {
1.207 - nodeset_reader.skipNodeMap(name, reader);
1.208 - return *this;
1.209 - }
1.210 -
1.211 - /// \brief Add a new edge map reader command for the reader.
1.212 - ///
1.213 - /// Add a new edge map reader command for the reader.
1.214 - template <typename Map>
1.215 - GraphReader& readEdgeMap(std::string name, Map& map) {
1.216 - edgeset_reader.readEdgeMap(name, map);
1.217 - return *this;
1.218 - }
1.219 -
1.220 - template <typename Map>
1.221 - GraphReader& readEdgeMap(std::string name, const Map& map) {
1.222 - edgeset_reader.readEdgeMap(name, map);
1.223 - return *this;
1.224 - }
1.225 -
1.226 -
1.227 - /// \brief Add a new edge map reader command for the reader.
1.228 - ///
1.229 - /// Add a new edge map reader command for the reader.
1.230 - template <typename Reader, typename Map>
1.231 - GraphReader& readEdgeMap(std::string name, Map& map,
1.232 - const Reader& reader = Reader()) {
1.233 - edgeset_reader.readEdgeMap(name, map, reader);
1.234 - return *this;
1.235 - }
1.236 -
1.237 - template <typename Reader, typename Map>
1.238 - GraphReader& readEdgeMap(std::string name, const Map& map,
1.239 - const Reader& reader = Reader()) {
1.240 - edgeset_reader.readEdgeMap(name, map, reader);
1.241 - return *this;
1.242 - }
1.243 -
1.244 - /// \brief Add a new edge map skipper command for the reader.
1.245 - ///
1.246 - /// Add a new edge map skipper command for the reader.
1.247 - template <typename Reader>
1.248 - GraphReader& skipEdgeMap(std::string name,
1.249 - const Reader& reader = Reader()) {
1.250 - edgeset_reader.skipEdgeMap(name, reader);
1.251 - return *this;
1.252 - }
1.253 -
1.254 - /// \brief Add a new labeled node reader for the reader.
1.255 - ///
1.256 - /// Add a new labeled node reader for the reader.
1.257 - GraphReader& readNode(std::string name, Node& node) {
1.258 - node_reader.readNode(name, node);
1.259 - return *this;
1.260 - }
1.261 -
1.262 - /// \brief Add a new labeled edge reader for the reader.
1.263 - ///
1.264 - /// Add a new labeled edge reader for the reader.
1.265 - GraphReader& readEdge(std::string name, Edge& edge) {
1.266 - edge_reader.readEdge(name, edge);
1.267 - }
1.268 -
1.269 - /// \brief Add a new attribute reader command.
1.270 - ///
1.271 - /// Add a new attribute reader command.
1.272 - template <typename Value>
1.273 - GraphReader& readAttribute(std::string name, Value& value) {
1.274 - attribute_reader.readAttribute(name, value);
1.275 - return *this;
1.276 - }
1.277 -
1.278 - /// \brief Add a new attribute reader command.
1.279 - ///
1.280 - /// Add a new attribute reader command.
1.281 - template <typename Reader, typename Value>
1.282 - GraphReader& readAttribute(std::string name, Value& value,
1.283 - const Reader& reader) {
1.284 - attribute_reader.readAttribute<Reader>(name, value, reader);
1.285 - return *this;
1.286 - }
1.287 -
1.288 - /// \brief Conversion operator to LemonReader.
1.289 - ///
1.290 - /// Conversion operator to LemonReader. It make possible
1.291 - /// to access the encapsulated \e LemonReader, this way
1.292 - /// you can attach to this reader new instances of
1.293 - /// \e LemonReader::SectionReader.
1.294 - operator LemonReader&() {
1.295 - return *reader;
1.296 - }
1.297 -
1.298 - /// \brief Executes the reader commands.
1.299 - ///
1.300 - /// Executes the reader commands.
1.301 - void run() {
1.302 - reader->run();
1.303 - }
1.304 -
1.305 - /// \brief Gives back the node by its id.
1.306 - ///
1.307 - /// It reads an id from the stream and gives back which node belongs to
1.308 - /// it. It is possible only if there was read an "id" named node map.
1.309 - Node readId(std::istream& is, Node) const {
1.310 - return nodeset_reader.readId(is, Node());
1.311 - }
1.312 -
1.313 - /// \brief Gives back the edge by its id.
1.314 - ///
1.315 - /// It reads an id from the stream and gives back which edge belongs to
1.316 - /// it. It is possible only if there was read an "id" named edge map.
1.317 - Edge readId(std::istream& is, Edge) const {
1.318 - return edgeset_reader.readId(is, Edge());
1.319 - }
1.320 -
1.321 - private:
1.322 -
1.323 - LemonReader* reader;
1.324 - bool own_reader;
1.325 -
1.326 - DefaultSkipper skipper;
1.327 -
1.328 - NodeSetReader<Graph, ReaderTraits> nodeset_reader;
1.329 - EdgeSetReader<Graph, ReaderTraits> edgeset_reader;
1.330 -
1.331 - NodeReader<Graph> node_reader;
1.332 - EdgeReader<Graph> edge_reader;
1.333 -
1.334 - AttributeReader<ReaderTraits> attribute_reader;
1.335 - };
1.336 -
1.337 - /// \brief Read a graph from the input.
1.338 - ///
1.339 - /// Read a graph from the input.
1.340 - /// \param is The input stream.
1.341 - /// \param g The graph.
1.342 - /// \param capacity The capacity map.
1.343 - /// \param s The source node.
1.344 - /// \param t The target node.
1.345 - /// \param cost The cost map.
1.346 - template<typename Graph, typename CapacityMap, typename CostMap>
1.347 - void readGraph(std::istream& is, Graph &g, CapacityMap& capacity,
1.348 - typename Graph::Node &s, typename Graph::Node &t,
1.349 - CostMap& cost) {
1.350 - GraphReader<Graph> reader(is, g);
1.351 - reader.readEdgeMap("capacity", capacity);
1.352 - reader.readEdgeMap("cost", cost);
1.353 - reader.readNode("source", s);
1.354 - reader.readNode("target", t);
1.355 - reader.run();
1.356 - }
1.357 -
1.358 - /// \brief Read a graph from the input.
1.359 - ///
1.360 - /// Read a graph from the input.
1.361 - /// \param is The input stream.
1.362 - /// \param g The graph.
1.363 - /// \param capacity The capacity map.
1.364 - /// \param s The source node.
1.365 - /// \param t The target node.
1.366 - template<typename Graph, typename CapacityMap>
1.367 - void readGraph(std::istream& is, Graph &g, CapacityMap& capacity,
1.368 - typename Graph::Node &s, typename Graph::Node &t) {
1.369 - GraphReader<Graph> reader(is, g);
1.370 - reader.readEdgeMap("capacity", capacity);
1.371 - reader.readNode("source", s);
1.372 - reader.readNode("target", t);
1.373 - reader.run();
1.374 - }
1.375 -
1.376 - /// \brief Read a graph from the input.
1.377 - ///
1.378 - /// Read a graph from the input.
1.379 - /// \param is The input stream.
1.380 - /// \param g The graph.
1.381 - /// \param capacity The capacity map.
1.382 - /// \param s The source node.
1.383 - template<typename Graph, typename CapacityMap>
1.384 - void readGraph(std::istream& is, Graph &g, CapacityMap& capacity,
1.385 - typename Graph::Node &s) {
1.386 - GraphReader<Graph> reader(is, g);
1.387 - reader.readEdgeMap("capacity", capacity);
1.388 - reader.readNode("source", s);
1.389 - reader.run();
1.390 - }
1.391 -
1.392 - /// \brief Read a graph from the input.
1.393 - ///
1.394 - /// Read a graph from the input.
1.395 - /// \param is The input stream.
1.396 - /// \param g The graph.
1.397 - /// \param capacity The capacity map.
1.398 - template<typename Graph, typename CapacityMap>
1.399 - void readGraph(std::istream& is, Graph &g, CapacityMap& capacity) {
1.400 - GraphReader<Graph> reader(is, g);
1.401 - reader.readEdgeMap("capacity", capacity);
1.402 - reader.run();
1.403 - }
1.404 -
1.405 - /// \brief Read a graph from the input.
1.406 - ///
1.407 - /// Read a graph from the input.
1.408 - /// \param is The input stream.
1.409 - /// \param g The graph.
1.410 - template<typename Graph>
1.411 - void readGraph(std::istream& is, Graph &g) {
1.412 - GraphReader<Graph> reader(is, g);
1.413 - reader.run();
1.414 - }
1.415 -
1.416 - /// \brief The undir graph reader class.
1.417 - ///
1.418 - /// The given file format may contain several maps and labeled nodes or
1.419 - /// edges.
1.420 - ///
1.421 - /// If you read a graph you need not read all the maps and items just those
1.422 - /// that you need. The interface of the \c GraphReader is very similar to
1.423 - /// the GraphWriter but the reading method does not depend on the order the
1.424 - /// given commands.
1.425 - ///
1.426 - /// The reader object suppose that each not readed value does not contain
1.427 - /// whitespaces, therefore it has some extra possibilities to control how
1.428 - /// it should skip the values when the string representation contains spaces.
1.429 - ///
1.430 - /// \code
1.431 - /// UndirGraphReader<UndirListGraph> reader(std::cin, graph);
1.432 - /// \endcode
1.433 - ///
1.434 - /// The \c readNodeMap() function reads a map from the \c \@nodeset section.
1.435 - /// If there is a map that you do not want to read from the file and there is
1.436 - /// whitespace in the string represenation of the values then you should
1.437 - /// call the \c skipNodeMap() template member function with proper
1.438 - /// parameters.
1.439 - ///
1.440 - /// \code
1.441 - /// reader.readNodeMap("coords", coords);
1.442 - ///
1.443 - /// reader.readNodeMap<QuotedStringReader>("label", labelMap);
1.444 - /// reader.skipNodeMap<QuotedStringReader>("description");
1.445 - ///
1.446 - /// reader.readNodeMap("color", colorMap);
1.447 - /// \endcode
1.448 - ///
1.449 - /// With the \c readUndirEdgeMap() member function you can give an
1.450 - /// undir edge map reading command similar to the NodeMaps.
1.451 - ///
1.452 - /// \code
1.453 - /// reader.readUndirEdgeMap("capacity", capacityMap);
1.454 - /// \endcode
1.455 - ///
1.456 - /// The reading of the directed edge maps is just a syntactical sugar.
1.457 - /// It reads two undirected edgemaps into a directed edge map. The
1.458 - /// undirected edge maps' name should be start with the \c '+' and the
1.459 - /// \c '-' character and the same.
1.460 - ///
1.461 - /// \code
1.462 - /// reader.readEdgeMap("flow", flowMap);
1.463 - /// \endcode
1.464 - ///
1.465 - /// With \c readNode() and \c readUndirEdge() functions you can read
1.466 - /// labeled Nodes and UndirEdges.
1.467 - ///
1.468 - /// \code
1.469 - /// reader.readNode("source", sourceNode);
1.470 - /// reader.readNode("target", targetNode);
1.471 - ///
1.472 - /// reader.readUndirEdge("observed", undirEdge);
1.473 - /// \endcode
1.474 - ///
1.475 - /// With the \c readAttribute() functions you can read an attribute
1.476 - /// in a variable. You can specify the reader for the attribute as
1.477 - /// the nodemaps.
1.478 - ///
1.479 - /// After you give all read commands you must call the \c run() member
1.480 - /// function, which execute all the commands.
1.481 - ///
1.482 - /// \code
1.483 - /// reader.run();
1.484 - /// \endcode
1.485 - ///
1.486 - /// \see GraphReader
1.487 - /// \see DefaultReaderTraits
1.488 - /// \see \ref UndirGraphWriter
1.489 - /// \see \ref graph-io-page
1.490 - ///
1.491 - /// \author Balazs Dezso
1.492 - template <typename _Graph, typename _ReaderTraits = DefaultReaderTraits>
1.493 - class UndirGraphReader {
1.494 - public:
1.495 -
1.496 - typedef _Graph Graph;
1.497 - typedef typename Graph::Node Node;
1.498 - typedef typename Graph::Edge Edge;
1.499 - typedef typename Graph::UndirEdge UndirEdge;
1.500 -
1.501 - typedef _ReaderTraits ReaderTraits;
1.502 - typedef typename ReaderTraits::Skipper DefaultSkipper;
1.503 -
1.504 - /// \brief Construct a new UndirGraphReader.
1.505 - ///
1.506 - /// Construct a new UndirGraphReader. It reads into the given graph
1.507 - /// and it use the given reader as the default skipper.
1.508 - UndirGraphReader(std::istream& _is, Graph& _graph,
1.509 - const DefaultSkipper& _skipper = DefaultSkipper())
1.510 - : reader(new LemonReader(_is)), own_reader(true), skipper(_skipper),
1.511 - nodeset_reader(*reader, _graph, std::string(), skipper),
1.512 - undir_edgeset_reader(*reader, _graph, nodeset_reader,
1.513 - std::string(), skipper),
1.514 - node_reader(*reader, nodeset_reader, std::string()),
1.515 - undir_edge_reader(*reader, undir_edgeset_reader, std::string()),
1.516 - attribute_reader(*reader, std::string()) {}
1.517 -
1.518 - /// \brief Construct a new UndirGraphReader.
1.519 - ///
1.520 - /// Construct a new UndirGraphReader. It reads into the given graph
1.521 - /// and it use the given reader as the default skipper.
1.522 - UndirGraphReader(const std::string& _filename, Graph& _graph,
1.523 - const DefaultSkipper& _skipper = DefaultSkipper())
1.524 - : reader(new LemonReader(_filename)), own_reader(true),
1.525 - skipper(_skipper),
1.526 - nodeset_reader(*reader, _graph, std::string(), skipper),
1.527 - undir_edgeset_reader(*reader, _graph, nodeset_reader,
1.528 - std::string(), skipper),
1.529 - node_reader(*reader, nodeset_reader, std::string()),
1.530 - undir_edge_reader(*reader, undir_edgeset_reader, std::string()),
1.531 - attribute_reader(*reader, std::string()) {}
1.532 -
1.533 - /// \brief Construct a new UndirGraphReader.
1.534 - ///
1.535 - /// Construct a new UndirGraphReader. It reads into the given graph
1.536 - /// and it use the given reader as the default skipper.
1.537 - UndirGraphReader(LemonReader& _reader, Graph& _graph,
1.538 - const DefaultSkipper& _skipper = DefaultSkipper())
1.539 - : reader(_reader), own_reader(false), skipper(_skipper),
1.540 - nodeset_reader(*reader, _graph, std::string(), skipper),
1.541 - undir_edgeset_reader(*reader, _graph, nodeset_reader,
1.542 - std::string(), skipper),
1.543 - node_reader(*reader, nodeset_reader, std::string()),
1.544 - undir_edge_reader(*reader, undir_edgeset_reader, std::string()),
1.545 - attribute_reader(*reader, std::string()) {}
1.546 -
1.547 - /// \brief Destruct the graph reader.
1.548 - ///
1.549 - /// Destruct the graph reader.
1.550 - ~UndirGraphReader() {
1.551 - if (own_reader)
1.552 - delete reader;
1.553 - }
1.554 -
1.555 - /// \brief Add a new node map reader command for the reader.
1.556 - ///
1.557 - /// Add a new node map reader command for the reader.
1.558 - template <typename Map>
1.559 - UndirGraphReader& readNodeMap(std::string name, Map& map) {
1.560 - nodeset_reader.readNodeMap(name, map);
1.561 - return *this;
1.562 - }
1.563 -
1.564 - template <typename Map>
1.565 - UndirGraphReader& readNodeMap(std::string name, const Map& map) {
1.566 - nodeset_reader.readNodeMap(name, map);
1.567 - return *this;
1.568 - }
1.569 -
1.570 - /// \brief Add a new node map reader command for the reader.
1.571 - ///
1.572 - /// Add a new node map reader command for the reader.
1.573 - template <typename Reader, typename Map>
1.574 - UndirGraphReader& readNodeMap(std::string name, Map& map,
1.575 - const Reader& reader = Reader()) {
1.576 - nodeset_reader.readNodeMap(name, map, reader);
1.577 - return *this;
1.578 - }
1.579 -
1.580 - template <typename Reader, typename Map>
1.581 - UndirGraphReader& readNodeMap(std::string name, const Map& map,
1.582 - const Reader& reader = Reader()) {
1.583 - nodeset_reader.readNodeMap(name, map, reader);
1.584 - return *this;
1.585 - }
1.586 -
1.587 - /// \brief Add a new node map skipper command for the reader.
1.588 - ///
1.589 - /// Add a new node map skipper command for the reader.
1.590 - template <typename Reader>
1.591 - UndirGraphReader& skipNodeMap(std::string name,
1.592 - const Reader& reader = Reader()) {
1.593 - nodeset_reader.skipNodeMap(name, reader);
1.594 - return *this;
1.595 - }
1.596 -
1.597 - /// \brief Add a new undirected edge map reader command for the reader.
1.598 - ///
1.599 - /// Add a new undirected edge map reader command for the reader.
1.600 - template <typename Map>
1.601 - UndirGraphReader& readUndirEdgeMap(std::string name, Map& map) {
1.602 - undir_edgeset_reader.readUndirEdgeMap(name, map);
1.603 - return *this;
1.604 - }
1.605 -
1.606 - template <typename Map>
1.607 - UndirGraphReader& readUndirEdgeMap(std::string name, const Map& map) {
1.608 - undir_edgeset_reader.readUndirEdgeMap(name, map);
1.609 - return *this;
1.610 - }
1.611 -
1.612 -
1.613 - /// \brief Add a new undirected edge map reader command for the reader.
1.614 - ///
1.615 - /// Add a new undirected edge map reader command for the reader.
1.616 - template <typename Reader, typename Map>
1.617 - UndirGraphReader& readUndirEdgeMap(std::string name, Map& map,
1.618 - const Reader& reader = Reader()) {
1.619 - undir_edgeset_reader.readUndirEdgeMap(name, map, reader);
1.620 - return *this;
1.621 - }
1.622 -
1.623 - template <typename Reader, typename Map>
1.624 - UndirGraphReader& readUndirEdgeMap(std::string name, const Map& map,
1.625 - const Reader& reader = Reader()) {
1.626 - undir_edgeset_reader.readUndirEdgeMap(name, map, reader);
1.627 - return *this;
1.628 - }
1.629 -
1.630 - /// \brief Add a new undirected edge map skipper command for the reader.
1.631 - ///
1.632 - /// Add a new undirected edge map skipper command for the reader.
1.633 - template <typename Reader>
1.634 - UndirGraphReader& skipUndirEdgeMap(std::string name,
1.635 - const Reader& reader = Reader()) {
1.636 - undir_edgeset_reader.skipUndirMap(name, reader);
1.637 - return *this;
1.638 - }
1.639 -
1.640 -
1.641 - /// \brief Add a new edge map reader command for the reader.
1.642 - ///
1.643 - /// Add a new edge map reader command for the reader.
1.644 - template <typename Map>
1.645 - UndirGraphReader& readEdgeMap(std::string name, Map& map) {
1.646 - undir_edgeset_reader.readEdgeMap(name, map);
1.647 - return *this;
1.648 - }
1.649 -
1.650 - template <typename Map>
1.651 - UndirGraphReader& readEdgeMap(std::string name, const Map& map) {
1.652 - undir_edgeset_reader.readEdgeMap(name, map);
1.653 - return *this;
1.654 - }
1.655 -
1.656 -
1.657 - /// \brief Add a new edge map reader command for the reader.
1.658 - ///
1.659 - /// Add a new edge map reader command for the reader.
1.660 - template <typename Reader, typename Map>
1.661 - UndirGraphReader& readEdgeMap(std::string name, Map& map,
1.662 - const Reader& reader = Reader()) {
1.663 - undir_edgeset_reader.readEdgeMap(name, map, reader);
1.664 - return *this;
1.665 - }
1.666 -
1.667 - template <typename Reader, typename Map>
1.668 - UndirGraphReader& readEdgeMap(std::string name, const Map& map,
1.669 - const Reader& reader = Reader()) {
1.670 - undir_edgeset_reader.readEdgeMap(name, map, reader);
1.671 - return *this;
1.672 - }
1.673 -
1.674 - /// \brief Add a new edge map skipper command for the reader.
1.675 - ///
1.676 - /// Add a new edge map skipper command for the reader.
1.677 - template <typename Reader>
1.678 - UndirGraphReader& skipEdgeMap(std::string name,
1.679 - const Reader& reader = Reader()) {
1.680 - undir_edgeset_reader.skipEdgeMap(name, reader);
1.681 - return *this;
1.682 - }
1.683 -
1.684 - /// \brief Add a new labeled node reader for the reader.
1.685 - ///
1.686 - /// Add a new labeled node reader for the reader.
1.687 - UndirGraphReader& readNode(std::string name, Node& node) {
1.688 - node_reader.readNode(name, node);
1.689 - return *this;
1.690 - }
1.691 -
1.692 - /// \brief Add a new labeled edge reader for the reader.
1.693 - ///
1.694 - /// Add a new labeled edge reader for the reader.
1.695 - UndirGraphReader& readEdge(std::string name, Edge& edge) {
1.696 - undir_edge_reader.readEdge(name, edge);
1.697 - }
1.698 -
1.699 - /// \brief Add a new labeled undirected edge reader for the reader.
1.700 - ///
1.701 - /// Add a new labeled undirected edge reader for the reader.
1.702 - UndirGraphReader& readUndirEdge(std::string name, UndirEdge& edge) {
1.703 - undir_edge_reader.readUndirEdge(name, edge);
1.704 - }
1.705 -
1.706 - /// \brief Add a new attribute reader command.
1.707 - ///
1.708 - /// Add a new attribute reader command.
1.709 - template <typename Value>
1.710 - UndirGraphReader& readAttribute(std::string name, Value& value) {
1.711 - attribute_reader.readAttribute(name, value);
1.712 - return *this;
1.713 - }
1.714 -
1.715 - /// \brief Add a new attribute reader command.
1.716 - ///
1.717 - /// Add a new attribute reader command.
1.718 - template <typename Reader, typename Value>
1.719 - UndirGraphReader& readAttribute(std::string name, Value& value,
1.720 - const Reader& reader) {
1.721 - attribute_reader.readAttribute<Reader>(name, value, reader);
1.722 - return *this;
1.723 - }
1.724 -
1.725 - /// \brief Conversion operator to LemonReader.
1.726 - ///
1.727 - /// Conversion operator to LemonReader. It make possible
1.728 - /// to access the encapsulated \e LemonReader, this way
1.729 - /// you can attach to this reader new instances of
1.730 - /// \e LemonReader::SectionReader.
1.731 - operator LemonReader&() {
1.732 - return *reader;
1.733 - }
1.734 -
1.735 - /// \brief Executes the reader commands.
1.736 - ///
1.737 - /// Executes the reader commands.
1.738 - void run() {
1.739 - reader->run();
1.740 - }
1.741 -
1.742 - /// \brief Gives back the node by its id.
1.743 - ///
1.744 - /// It reads an id from the stream and gives back which node belongs to
1.745 - /// it. It is possible only if there was read an "id" named node map.
1.746 - Node readId(std::istream& is, Node) const {
1.747 - return nodeset_reader.readId(is, Node());
1.748 - }
1.749 -
1.750 - /// \brief Gives back the edge by its id.
1.751 - ///
1.752 - /// It reads an id from the stream and gives back which edge belongs to
1.753 - /// it. It is possible only if there was read an "id" named edge map.
1.754 - Edge readId(std::istream& is, Edge) const {
1.755 - return undir_edgeset_reader.readId(is, Edge());
1.756 - }
1.757 -
1.758 - /// \brief Gives back the undirected edge by its id.
1.759 - ///
1.760 - /// It reads an id from the stream and gives back which undirected edge
1.761 - /// belongs to it. It is possible only if there was read an "id" named
1.762 - /// edge map.
1.763 - UndirEdge readId(std::istream& is, UndirEdge) const {
1.764 - return undir_edgeset_reader.readId(is, UndirEdge());
1.765 - }
1.766 -
1.767 -
1.768 - private:
1.769 -
1.770 - LemonReader* reader;
1.771 - bool own_reader;
1.772 -
1.773 - DefaultSkipper skipper;
1.774 -
1.775 - NodeSetReader<Graph, ReaderTraits> nodeset_reader;
1.776 - UndirEdgeSetReader<Graph, ReaderTraits> undir_edgeset_reader;
1.777 -
1.778 - NodeReader<Graph> node_reader;
1.779 - UndirEdgeReader<Graph> undir_edge_reader;
1.780 -
1.781 - AttributeReader<ReaderTraits> attribute_reader;
1.782 - };
1.783 -
1.784 - /// \brief Read an undir graph from the input.
1.785 - ///
1.786 - /// Read an undir graph from the input.
1.787 - /// \param is The input stream.
1.788 - /// \param g The graph.
1.789 - /// \param capacity The capacity map.
1.790 - template<typename Graph, typename CapacityMap>
1.791 - void readUndirGraph(std::istream& is, Graph &g, CapacityMap& capacity) {
1.792 - UndirGraphReader<Graph> reader(is, g);
1.793 - reader.readUndirEdgeMap("capacity", capacity);
1.794 - reader.run();
1.795 - }
1.796 -
1.797 - /// \brief Read an undir graph from the input.
1.798 - ///
1.799 - /// Read an undir graph from the input.
1.800 - /// \param is The input stream.
1.801 - /// \param g The graph.
1.802 - template<typename Graph>
1.803 - void readUndirGraph(std::istream& is, Graph &g) {
1.804 - UndirGraphReader<Graph> reader(is, g);
1.805 - reader.run();
1.806 - }
1.807 -
1.808 - /// @}
1.809 -}
1.810 -
1.811 -#endif