Removing old input/output functions
authordeba
Wed, 26 Oct 2005 11:09:29 +0000
changeset 174451d5d41e15b1
parent 1743 503d0c79078a
child 1745 d356e54bdafc
Removing old input/output functions
demo/dim_to_lgf.cc
lemon/bits/item_reader.h
lemon/graph_reader.h
lemon/graph_writer.h
test/heap_test.cc
     1.1 --- a/demo/dim_to_lgf.cc	Wed Oct 26 10:59:51 2005 +0000
     1.2 +++ b/demo/dim_to_lgf.cc	Wed Oct 26 11:09:29 2005 +0000
     1.3 @@ -161,28 +161,42 @@
     1.4      Node s, t;
     1.5      StringMap cost(graph), capacity(graph);
     1.6      readDimacs(is, graph, capacity, s, t, cost);
     1.7 -    writeGraph(os, graph, capacity, s, t, cost);
     1.8 +    GraphWriter<Graph>(os, graph).
     1.9 +      writeEdgeMap("capacity", capacity).
    1.10 +      writeNode("source", s).
    1.11 +      writeNode("target", t).
    1.12 +      writeEdgeMap("cost", cost).
    1.13 +      run();
    1.14    } else if (typeName == "maxflow") {
    1.15      Graph graph;
    1.16      Node s, t;
    1.17      StringMap capacity(graph);
    1.18      readDimacs(is, graph, capacity, s, t);
    1.19 -    writeGraph(os, graph, capacity, s, t);
    1.20 +    GraphWriter<Graph>(os, graph).
    1.21 +      writeEdgeMap("capacity", capacity).
    1.22 +      writeNode("source", s).
    1.23 +      writeNode("target", t).
    1.24 +      run();
    1.25    } else if (typeName == "shortestpath") {
    1.26      Graph graph;
    1.27      Node s;
    1.28      StringMap capacity(graph);
    1.29      readDimacs(is, graph, capacity, s);
    1.30 -    writeGraph(os, graph, capacity, s);
    1.31 +    GraphWriter<Graph>(os, graph).
    1.32 +      writeEdgeMap("capacity", capacity).
    1.33 +      writeNode("source", s).
    1.34 +      run();
    1.35    } else if (typeName == "capacitated") {
    1.36      Graph graph;
    1.37      StringMap capacity(graph);
    1.38      readDimacs(is, graph, capacity);
    1.39 -    writeGraph(os, graph, capacity);
    1.40 +    GraphWriter<Graph>(os, graph).
    1.41 +      writeEdgeMap("capacity", capacity).
    1.42 +      run();
    1.43    } else if (typeName == "plain") {
    1.44      Graph graph;
    1.45      readDimacs(is, graph);
    1.46 -    writeGraph(os, graph);
    1.47 +    GraphWriter<Graph>(os, graph).run();
    1.48    } else {
    1.49      cerr << "Invalid type error" << endl;
    1.50      return -1;
     2.1 --- a/lemon/bits/item_reader.h	Wed Oct 26 10:59:51 2005 +0000
     2.2 +++ b/lemon/bits/item_reader.h	Wed Oct 26 11:09:29 2005 +0000
     2.3 @@ -245,8 +245,9 @@
     2.4    /// \ingroup item_io
     2.5    /// \brief Reader for parsed string.
     2.6    ///
     2.7 -  /// Reader for parsed strings. You can give the open and close
     2.8 -  /// parse characters.
     2.9 +  /// Reader for parsed strings. You can define the open and close
    2.10 +  /// parse characters. It reads from the input a character sequence
    2.11 +  /// which is right parsed.
    2.12    ///
    2.13    /// \author Balazs Dezso
    2.14    class ParsedStringReader {
    2.15 @@ -357,8 +358,15 @@
    2.16        case '(':
    2.17  	ParsedStringReader().read(is, value);
    2.18  	break;
    2.19 +      case '[':
    2.20 +	ParsedStringReader('[', ']').read(is, value);
    2.21 +	break;
    2.22 +      case '/':
    2.23 +	ParsedStringReader('/', '/').read(is, value);
    2.24 +	break;
    2.25        default:
    2.26 -	is >> value; 
    2.27 +	if (!(is >> value)) 
    2.28 +	  throw DataFormatError("DefaultReader format error");
    2.29  	break;
    2.30        }
    2.31      }
     3.1 --- a/lemon/graph_reader.h	Wed Oct 26 10:59:51 2005 +0000
     3.2 +++ b/lemon/graph_reader.h	Wed Oct 26 11:09:29 2005 +0000
     3.3 @@ -339,97 +339,37 @@
     3.4    };
     3.5  
     3.6  
     3.7 -  ///\anchor readGraph()
     3.8 +  /// \brief Read a graph from the input.
     3.9    ///
    3.10 -  /// \brief Read a graph from an input stream.
    3.11 +  /// It is a helper function to read a graph from the given input
    3.12 +  /// stream. It gives back an GraphReader object and this object
    3.13 +  /// can read more maps, labeled nodes, edges and attributes.
    3.14    ///
    3.15 -  /// Read a graph from an input stream.
    3.16 +  /// \warning Do not forget to call the \c run() function.
    3.17 +  ///
    3.18    /// \param is The input stream.
    3.19    /// \param g The graph.
    3.20    template<typename Graph>
    3.21 -  void readGraph(std::istream& is, Graph &g) {
    3.22 -    GraphReader<Graph> reader(is, g);
    3.23 -    reader.run();
    3.24 +  GraphReader<Graph> graphReader(std::istream& is, Graph &g) {
    3.25 +    return GraphReader<Graph>(is, g);
    3.26    }
    3.27  
    3.28 -  /// \brief Read a capacitated graph instance from an input stream.
    3.29 -  /// 
    3.30 -  /// Read a capacitated graph (graph+capacity on the
    3.31 -  /// edges) from an input stream.
    3.32 -  /// \param is The input stream.
    3.33 +  /// \brief Read a graph from the input.
    3.34 +  ///
    3.35 +  /// It is a helper function to read a graph from the given input
    3.36 +  /// file. It gives back an GraphReader object and this object
    3.37 +  /// can read more maps, labeled nodes, edges and attributes.
    3.38 +  ///
    3.39 +  /// \warning Do not forget to call the \c run() function.
    3.40 +  ///
    3.41 +  /// \param fn The input filename.
    3.42    /// \param g The graph.
    3.43 -  /// \param capacity The capacity map.
    3.44 -  template<typename Graph, typename CapacityMap>
    3.45 -  void readGraph(std::istream& is, Graph &g, CapacityMap& capacity) {
    3.46 -    GraphReader<Graph> reader(is, g);
    3.47 -    reader.readEdgeMap("capacity", capacity);
    3.48 -    reader.run();
    3.49 +  template<typename Graph>
    3.50 +  GraphReader<Graph> graphReader(const std::string& fn, Graph &g) {
    3.51 +    return GraphReader<Graph>(fn, g);
    3.52    }
    3.53  
    3.54 -  /// \brief Read a shortest path instance from an input stream.
    3.55 -  /// 
    3.56 -  /// Read a shortest path instance (graph+capacity on the
    3.57 -  /// edges+designated source) from an input stream.
    3.58 -  /// \param is The input stream.
    3.59 -  /// \param g The graph.
    3.60 -  /// \param capacity The capacity map.
    3.61 -  /// \param s The source node.
    3.62 -  template<typename Graph, typename CapacityMap>
    3.63 -  void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, 
    3.64 -		  typename Graph::Node &s) {
    3.65 -    GraphReader<Graph> reader(is, g);
    3.66 -    reader.readEdgeMap("capacity", capacity);
    3.67 -    reader.readNode("source", s);
    3.68 -    reader.run();
    3.69 -  }
    3.70 -
    3.71 -
    3.72 -
    3.73 -  /// \brief Read a max flow instance from an input stream.
    3.74 -  ///
    3.75 -  /// Read a max flow instance (graph+capacity on the
    3.76 -  /// edges+designated source and target) from an input stream.
    3.77 -  ///
    3.78 -  /// \param is The input stream.
    3.79 -  /// \param g The graph.
    3.80 -  /// \param capacity The capacity map.
    3.81 -  /// \param s The source node.
    3.82 -  /// \param t The target node.
    3.83 -  template<typename Graph, typename CapacityMap>
    3.84 -  void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, 
    3.85 -		  typename Graph::Node &s, typename Graph::Node &t) {
    3.86 -    GraphReader<Graph> reader(is, g);
    3.87 -    reader.readEdgeMap("capacity", capacity);
    3.88 -    reader.readNode("source", s);
    3.89 -    reader.readNode("target", t);
    3.90 -    reader.run();
    3.91 -  }
    3.92 -
    3.93 -  /// \brief Read a min cost flow instance from an input stream.
    3.94 -  ///
    3.95 -  /// Read a min cost flow instance (graph+capacity on the edges+cost
    3.96 -  /// function on the edges+designated source and target) from an input stream.
    3.97 -  ///
    3.98 -  /// \param is The input stream.
    3.99 -  /// \param g The graph.
   3.100 -  /// \param capacity The capacity map.
   3.101 -  /// \param s The source node.
   3.102 -  /// \param t The target node.
   3.103 -  /// \param cost The cost map.
   3.104 -  template<typename Graph, typename CapacityMap, typename CostMap>
   3.105 -  void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, 
   3.106 -		  typename Graph::Node &s, typename Graph::Node &t, 
   3.107 -		  CostMap& cost) {
   3.108 -    GraphReader<Graph> reader(is, g);
   3.109 -    reader.readEdgeMap("capacity", capacity);
   3.110 -    reader.readEdgeMap("cost", cost);
   3.111 -    reader.readNode("source", s);
   3.112 -    reader.readNode("target", t);
   3.113 -    reader.run();
   3.114 -  }
   3.115 -
   3.116 -
   3.117 -  /// \brief The undir graph reader class.
   3.118 +  /// \brief The undirected graph reader class.
   3.119    ///
   3.120    /// The \c UndirGraphReader class provides the graph input. 
   3.121    /// Before you read this documentation it might be useful to read the general
   3.122 @@ -806,33 +746,38 @@
   3.123      AttributeReader<ReaderTraits> attribute_reader;
   3.124    };
   3.125  
   3.126 -  /// \brief Read an undirected graph from an input stream.
   3.127 +  /// \brief Read an undirected graph from the input.
   3.128    ///
   3.129 -  /// Read an undirected graph from an input stream.
   3.130 +  /// It is a helper function to read an undirected graph from the given input
   3.131 +  /// stream. It gives back an UndirGraphReader object and this object
   3.132 +  /// can read more maps, labeled nodes, edges, undirected edges and
   3.133 +  /// attributes.
   3.134 +  ///
   3.135 +  /// \warning Do not forget to call the \c run() function.
   3.136 +  ///
   3.137    /// \param is The input stream.
   3.138    /// \param g The graph.
   3.139    template<typename Graph>
   3.140 -  void readUndirGraph(std::istream& is, Graph &g) {
   3.141 -    UndirGraphReader<Graph> reader(is, g);
   3.142 -    reader.run();
   3.143 +  UndirGraphReader<Graph> undirGraphReader(std::istream& is, Graph &g) {
   3.144 +    return GraphReader<Graph>(is, g);
   3.145    }
   3.146  
   3.147 -  /// \brief Read an undirected multigraph (undirected graph + capacity
   3.148 -  /// map on the edges) from an input stream.
   3.149 +  /// \brief Read an undirected graph from the input.
   3.150    ///
   3.151 -  /// Read an undirected multigraph (undirected graph + capacity
   3.152 -  /// map on the edges) from an input stream.
   3.153 -  /// \param is The input stream.
   3.154 +  /// It is a helper function to read an undirected graph from the given input
   3.155 +  /// file. It gives back an UndirGraphReader object and this object
   3.156 +  /// can read more maps, labeled nodes, edges, undirected edges and 
   3.157 +  /// attributes.
   3.158 +  ///
   3.159 +  /// \warning Do not forget to call the \c run() function.
   3.160 +  ///
   3.161 +  /// \param fn The input filename.
   3.162    /// \param g The graph.
   3.163 -  /// \param capacity The capacity map.
   3.164 -  template<typename Graph, typename CapacityMap>
   3.165 -  void readUndirGraph(std::istream& is, Graph &g, CapacityMap& capacity) {
   3.166 -    UndirGraphReader<Graph> reader(is, g);
   3.167 -    reader.readUndirEdgeMap("capacity", capacity);
   3.168 -    reader.run();
   3.169 +  template<typename Graph>
   3.170 +  UndirGraphReader<Graph> undirGraphReader(const std::string& fn, Graph &g) {
   3.171 +    return GraphReader<Graph>(fn, g);
   3.172    }
   3.173  
   3.174 -
   3.175    /// @}
   3.176  }
   3.177  
     4.1 --- a/lemon/graph_writer.h	Wed Oct 26 10:59:51 2005 +0000
     4.2 +++ b/lemon/graph_writer.h	Wed Oct 26 11:09:29 2005 +0000
     4.3 @@ -284,114 +284,33 @@
     4.4    };
     4.5  
     4.6  
     4.7 -  ///\anchor writeGraph()
     4.8 -  ///
     4.9 +
    4.10    /// \brief Write a graph to the output.
    4.11    ///
    4.12 -  /// Write a graph to the output.
    4.13 -  /// \param os The output stream.
    4.14 -  /// \param g The graph.
    4.15 -  template<typename Graph>
    4.16 -  void writeGraph(std::ostream& os, const Graph &g) {
    4.17 -    GraphWriter<Graph> writer(os, g);
    4.18 -    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
    4.19 -    writer.writeNodeMap("id", nodeIdMap);
    4.20 -    IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
    4.21 -    writer.writeEdgeMap("id", edgeIdMap);
    4.22 -    writer.run();
    4.23 -  }
    4.24 -
    4.25 -  /// \brief Write a capacitated graph instance to the output.
    4.26 -  /// 
    4.27 -  /// Write a capacitated graph (graph+capacity on the
    4.28 -  /// edges) to the output.
    4.29 -  /// \param os The output stream.
    4.30 -  /// \param g The graph.
    4.31 -  /// \param capacity The capacity map.
    4.32 -  template<typename Graph, typename CapacityMap>
    4.33 -  void writeGraph(std::ostream& os, const Graph &g, 
    4.34 -		  const CapacityMap& capacity) {
    4.35 -    GraphWriter<Graph> writer(os, g);
    4.36 -    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
    4.37 -    writer.writeNodeMap("id", nodeIdMap);
    4.38 -    IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
    4.39 -    writer.writeEdgeMap("id", edgeIdMap);
    4.40 -    writer.writeEdgeMap("capacity", capacity);
    4.41 -    writer.run();
    4.42 -  }
    4.43 -
    4.44 -  /// \brief Write a shortest path instance to the output.
    4.45 -  /// 
    4.46 -  /// Write a shortest path instance (graph+capacity on the
    4.47 -  /// edges+designated source) to the output.
    4.48 -  /// \param os The output stream.
    4.49 -  /// \param g The graph.
    4.50 -  /// \param capacity The capacity map.
    4.51 -  /// \param s The source node.
    4.52 -  template<typename Graph, typename CapacityMap>
    4.53 -  void writeGraph(std::ostream& os, const Graph &g, 
    4.54 -		  const CapacityMap& capacity, const typename Graph::Node &s) {
    4.55 -    GraphWriter<Graph> writer(os, g);
    4.56 -    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
    4.57 -    writer.writeNodeMap("id", nodeIdMap);
    4.58 -    IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
    4.59 -    writer.writeEdgeMap("id", edgeIdMap);
    4.60 -    writer.writeEdgeMap("capacity", capacity);
    4.61 -    writer.writeNode("source", s);
    4.62 -    writer.run();
    4.63 -  }
    4.64 -
    4.65 -
    4.66 -  /// \brief Write a max flow instance to the output.
    4.67 -  ///
    4.68 -  /// Write a max flow instance (graph+capacity on the
    4.69 -  /// edges+designated source and target) to the output.
    4.70 +  /// It is a helper function to write a graph to the given output
    4.71 +  /// stream. It gives back a GraphWriter object and this object
    4.72 +  /// can write more maps, labeled nodes and edges and attributes.
    4.73 +  /// \warning Do not forget to call the \c run() function.
    4.74    ///
    4.75    /// \param os The output stream.
    4.76    /// \param g The graph.
    4.77 -  /// \param capacity The capacity map.
    4.78 -  /// \param s The source node.
    4.79 -  /// \param t The target node.
    4.80 -  template<typename Graph, typename CapacityMap>
    4.81 -  void writeGraph(std::ostream& os, const Graph &g, 
    4.82 -		  const CapacityMap& capacity, const typename Graph::Node &s,
    4.83 -		  const typename Graph::Node &t) {
    4.84 -    GraphWriter<Graph> writer(os, g);
    4.85 -    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
    4.86 -    writer.writeNodeMap("id", nodeIdMap);
    4.87 -    IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
    4.88 -    writer.writeEdgeMap("id", edgeIdMap);
    4.89 -    writer.writeEdgeMap("capacity", capacity);
    4.90 -    writer.writeNode("source", s);
    4.91 -    writer.writeNode("target", t);
    4.92 -    writer.run();
    4.93 +  template <typename Graph>
    4.94 +  GraphWriter<Graph> graphWriter(std::ostream& os, const Graph &g) {
    4.95 +    return GraphWriter<Graph>(os, g);
    4.96    }
    4.97  
    4.98 -  /// \brief Write a min cost flow instance to the output.
    4.99 +  /// \brief Write a graph to the output.
   4.100    ///
   4.101 -  /// Write a min cost flow instance (graph+capacity on the edges+cost
   4.102 -  /// function on the edges+designated source and target) to the output.
   4.103 +  /// It is a helper function to write a graph to the given output
   4.104 +  /// file. It gives back a GraphWriter object and this object
   4.105 +  /// can write more maps, labeled nodes and edges and attributes.
   4.106 +  /// \warning Do not forget to call the \c run() function.
   4.107    ///
   4.108 -  /// \param os The output stream.
   4.109 +  /// \param fn The filename.
   4.110    /// \param g The graph.
   4.111 -  /// \param capacity The capacity map.
   4.112 -  /// \param s The source node.
   4.113 -  /// \param t The target node.
   4.114 -  /// \param cost The cost map.
   4.115 -  template<typename Graph, typename CapacityMap, typename CostMap>
   4.116 -  void writeGraph(std::ostream& os, const Graph &g, 
   4.117 -		  const CapacityMap& capacity, const typename Graph::Node &s,
   4.118 -		  const typename Graph::Node &t, const CostMap& cost) {
   4.119 -    GraphWriter<Graph> writer(os, g);
   4.120 -    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
   4.121 -    writer.writeNodeMap("id", nodeIdMap);
   4.122 -    IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
   4.123 -    writer.writeEdgeMap("id", edgeIdMap);
   4.124 -    writer.writeEdgeMap("capacity", capacity);
   4.125 -    writer.writeEdgeMap("cost", cost);
   4.126 -    writer.writeNode("source", s);
   4.127 -    writer.writeNode("target", t);
   4.128 -    writer.run();
   4.129 +  template <typename Graph>
   4.130 +  GraphWriter<Graph> graphWriter(const std::string& fn, const Graph &g) {
   4.131 +    return GraphWriter<Graph>(fn, g);
   4.132    }
   4.133  
   4.134    /// \brief The undirected graph writer class.
   4.135 @@ -684,32 +603,35 @@
   4.136  
   4.137    /// \brief Write an undirected graph to the output.
   4.138    ///
   4.139 -  /// Write an undirected graph to the output.
   4.140 +  /// It is a helper function to write an undirected graph to the given output
   4.141 +  /// stream. It gives back an UndirGraphWriter object and this object
   4.142 +  /// can write more maps, labeled nodes and edges and attributes.
   4.143 +  /// \warning Do not forget to call the \c run() function.
   4.144 +  ///
   4.145    /// \param os The output stream.
   4.146    /// \param g The graph.
   4.147 -  template<typename Graph>
   4.148 -  void writeUndirGraph(std::ostream& os, const Graph &g) {
   4.149 -    UndirGraphWriter<Graph> writer(os, g);
   4.150 -    writer.run();
   4.151 +  template <typename Graph>
   4.152 +  UndirGraphWriter<Graph> undirGraphWriter(std::ostream& os, const Graph &g) {
   4.153 +    return UndirGraphWriter<Graph>(os, g);
   4.154    }
   4.155  
   4.156 -  /// \brief Write an undirected multigraph (undirected graph + capacity
   4.157 -  /// map on the edges) to the output.
   4.158 +  /// \brief Write an undirected graph to the output.
   4.159    ///
   4.160 -  /// Write an undirected multigraph (undirected graph + capacity
   4.161 -  /// map on the edges) to the output.
   4.162 -  /// \param os The output stream.
   4.163 +  /// It is a helper function to write an undirected graph to the given output
   4.164 +  /// file. It gives back an UndirGraphWriter object and this object
   4.165 +  /// can write more maps, labeled nodes, edges, undirected edges and 
   4.166 +  /// attributes.
   4.167 +  ///
   4.168 +  /// \warning Do not forget to call the \c run() function.
   4.169 +  ///
   4.170 +  /// \param fn The output file.
   4.171    /// \param g The graph.
   4.172 -  /// \param capacity The capacity undirected map.
   4.173 -  template<typename Graph, typename CapacityMap>
   4.174 -  void writeUndirGraph(std::ostream& os, const Graph &g, 
   4.175 -		       const CapacityMap& capacity) {
   4.176 -    UndirGraphWriter<Graph> writer(os, g);
   4.177 -    writer.writeUndirEdgeMap("capacity", capacity);
   4.178 -    writer.run();
   4.179 +  template <typename Graph>
   4.180 +  UndirGraphWriter<Graph> undirGraphWriter(const std::string& fn, 
   4.181 +					   const Graph &g) {
   4.182 +    return UndirGraphWriter<Graph>(fn, g);
   4.183    }
   4.184  
   4.185 -
   4.186    /// @}
   4.187  
   4.188  }
     5.1 --- a/test/heap_test.cc	Wed Oct 26 10:59:51 2005 +0000
     5.2 +++ b/test/heap_test.cc	Wed Oct 26 11:09:29 2005 +0000
     5.3 @@ -55,7 +55,10 @@
     5.4    
     5.5    std::ifstream input(f_name.c_str());
     5.6    check(input, "Input file '" << f_name << "' not found.");
     5.7 -  readGraph(input, graph, length, start);  
     5.8 +  GraphReader<Graph>(input, graph).
     5.9 +    readEdgeMap("length", length).
    5.10 +    readNode("source", start).
    5.11 +    run();  
    5.12   
    5.13    {
    5.14      std::cerr << "Checking Bin Heap" << std::endl;