# HG changeset patch # User deba # Date 1130324969 0 # Node ID 51d5d41e15b16e3eb468bc1384ed112e2b5bc38d # Parent 503d0c79078a2488a9a91305cf338c9ce1bb611a Removing old input/output functions diff -r 503d0c79078a -r 51d5d41e15b1 demo/dim_to_lgf.cc --- a/demo/dim_to_lgf.cc Wed Oct 26 10:59:51 2005 +0000 +++ b/demo/dim_to_lgf.cc Wed Oct 26 11:09:29 2005 +0000 @@ -161,28 +161,42 @@ Node s, t; StringMap cost(graph), capacity(graph); readDimacs(is, graph, capacity, s, t, cost); - writeGraph(os, graph, capacity, s, t, cost); + GraphWriter(os, graph). + writeEdgeMap("capacity", capacity). + writeNode("source", s). + writeNode("target", t). + writeEdgeMap("cost", cost). + run(); } else if (typeName == "maxflow") { Graph graph; Node s, t; StringMap capacity(graph); readDimacs(is, graph, capacity, s, t); - writeGraph(os, graph, capacity, s, t); + GraphWriter(os, graph). + writeEdgeMap("capacity", capacity). + writeNode("source", s). + writeNode("target", t). + run(); } else if (typeName == "shortestpath") { Graph graph; Node s; StringMap capacity(graph); readDimacs(is, graph, capacity, s); - writeGraph(os, graph, capacity, s); + GraphWriter(os, graph). + writeEdgeMap("capacity", capacity). + writeNode("source", s). + run(); } else if (typeName == "capacitated") { Graph graph; StringMap capacity(graph); readDimacs(is, graph, capacity); - writeGraph(os, graph, capacity); + GraphWriter(os, graph). + writeEdgeMap("capacity", capacity). + run(); } else if (typeName == "plain") { Graph graph; readDimacs(is, graph); - writeGraph(os, graph); + GraphWriter(os, graph).run(); } else { cerr << "Invalid type error" << endl; return -1; diff -r 503d0c79078a -r 51d5d41e15b1 lemon/bits/item_reader.h --- a/lemon/bits/item_reader.h Wed Oct 26 10:59:51 2005 +0000 +++ b/lemon/bits/item_reader.h Wed Oct 26 11:09:29 2005 +0000 @@ -245,8 +245,9 @@ /// \ingroup item_io /// \brief Reader for parsed string. /// - /// Reader for parsed strings. You can give the open and close - /// parse characters. + /// Reader for parsed strings. You can define the open and close + /// parse characters. It reads from the input a character sequence + /// which is right parsed. /// /// \author Balazs Dezso class ParsedStringReader { @@ -357,8 +358,15 @@ case '(': ParsedStringReader().read(is, value); break; + case '[': + ParsedStringReader('[', ']').read(is, value); + break; + case '/': + ParsedStringReader('/', '/').read(is, value); + break; default: - is >> value; + if (!(is >> value)) + throw DataFormatError("DefaultReader format error"); break; } } diff -r 503d0c79078a -r 51d5d41e15b1 lemon/graph_reader.h --- a/lemon/graph_reader.h Wed Oct 26 10:59:51 2005 +0000 +++ b/lemon/graph_reader.h Wed Oct 26 11:09:29 2005 +0000 @@ -339,97 +339,37 @@ }; - ///\anchor readGraph() + /// \brief Read a graph from the input. /// - /// \brief Read a graph from an input stream. + /// It is a helper function to read a graph from the given input + /// stream. It gives back an GraphReader object and this object + /// can read more maps, labeled nodes, edges and attributes. /// - /// Read a graph from an input stream. + /// \warning Do not forget to call the \c run() function. + /// /// \param is The input stream. /// \param g The graph. template - void readGraph(std::istream& is, Graph &g) { - GraphReader reader(is, g); - reader.run(); + GraphReader graphReader(std::istream& is, Graph &g) { + return GraphReader(is, g); } - /// \brief Read a capacitated graph instance from an input stream. - /// - /// Read a capacitated graph (graph+capacity on the - /// edges) from an input stream. - /// \param is The input stream. + /// \brief Read a graph from the input. + /// + /// It is a helper function to read a graph from the given input + /// file. It gives back an GraphReader object and this object + /// can read more maps, labeled nodes, edges and attributes. + /// + /// \warning Do not forget to call the \c run() function. + /// + /// \param fn The input filename. /// \param g The graph. - /// \param capacity The capacity map. - template - void readGraph(std::istream& is, Graph &g, CapacityMap& capacity) { - GraphReader reader(is, g); - reader.readEdgeMap("capacity", capacity); - reader.run(); + template + GraphReader graphReader(const std::string& fn, Graph &g) { + return GraphReader(fn, g); } - /// \brief Read a shortest path instance from an input stream. - /// - /// Read a shortest path instance (graph+capacity on the - /// edges+designated source) from an input stream. - /// \param is The input stream. - /// \param g The graph. - /// \param capacity The capacity map. - /// \param s The source node. - template - void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, - typename Graph::Node &s) { - GraphReader reader(is, g); - reader.readEdgeMap("capacity", capacity); - reader.readNode("source", s); - reader.run(); - } - - - - /// \brief Read a max flow instance from an input stream. - /// - /// Read a max flow instance (graph+capacity on the - /// edges+designated source and target) from an input stream. - /// - /// \param is The input stream. - /// \param g The graph. - /// \param capacity The capacity map. - /// \param s The source node. - /// \param t The target node. - template - void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, - typename Graph::Node &s, typename Graph::Node &t) { - GraphReader reader(is, g); - reader.readEdgeMap("capacity", capacity); - reader.readNode("source", s); - reader.readNode("target", t); - reader.run(); - } - - /// \brief Read a min cost flow instance from an input stream. - /// - /// Read a min cost flow instance (graph+capacity on the edges+cost - /// function on the edges+designated source and target) from an input stream. - /// - /// \param is The input stream. - /// \param g The graph. - /// \param capacity The capacity map. - /// \param s The source node. - /// \param t The target node. - /// \param cost The cost map. - template - void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, - typename Graph::Node &s, typename Graph::Node &t, - CostMap& cost) { - GraphReader reader(is, g); - reader.readEdgeMap("capacity", capacity); - reader.readEdgeMap("cost", cost); - reader.readNode("source", s); - reader.readNode("target", t); - reader.run(); - } - - - /// \brief The undir graph reader class. + /// \brief The undirected graph reader class. /// /// The \c UndirGraphReader class provides the graph input. /// Before you read this documentation it might be useful to read the general @@ -806,33 +746,38 @@ AttributeReader attribute_reader; }; - /// \brief Read an undirected graph from an input stream. + /// \brief Read an undirected graph from the input. /// - /// Read an undirected graph from an input stream. + /// It is a helper function to read an undirected graph from the given input + /// stream. It gives back an UndirGraphReader object and this object + /// can read more maps, labeled nodes, edges, undirected edges and + /// attributes. + /// + /// \warning Do not forget to call the \c run() function. + /// /// \param is The input stream. /// \param g The graph. template - void readUndirGraph(std::istream& is, Graph &g) { - UndirGraphReader reader(is, g); - reader.run(); + UndirGraphReader undirGraphReader(std::istream& is, Graph &g) { + return GraphReader(is, g); } - /// \brief Read an undirected multigraph (undirected graph + capacity - /// map on the edges) from an input stream. + /// \brief Read an undirected graph from the input. /// - /// Read an undirected multigraph (undirected graph + capacity - /// map on the edges) from an input stream. - /// \param is The input stream. + /// It is a helper function to read an undirected graph from the given input + /// file. It gives back an UndirGraphReader object and this object + /// can read more maps, labeled nodes, edges, undirected edges and + /// attributes. + /// + /// \warning Do not forget to call the \c run() function. + /// + /// \param fn The input filename. /// \param g The graph. - /// \param capacity The capacity map. - template - void readUndirGraph(std::istream& is, Graph &g, CapacityMap& capacity) { - UndirGraphReader reader(is, g); - reader.readUndirEdgeMap("capacity", capacity); - reader.run(); + template + UndirGraphReader undirGraphReader(const std::string& fn, Graph &g) { + return GraphReader(fn, g); } - /// @} } diff -r 503d0c79078a -r 51d5d41e15b1 lemon/graph_writer.h --- a/lemon/graph_writer.h Wed Oct 26 10:59:51 2005 +0000 +++ b/lemon/graph_writer.h Wed Oct 26 11:09:29 2005 +0000 @@ -284,114 +284,33 @@ }; - ///\anchor writeGraph() - /// + /// \brief Write a graph to the output. /// - /// Write a graph to the output. - /// \param os The output stream. - /// \param g The graph. - template - void writeGraph(std::ostream& os, const Graph &g) { - GraphWriter writer(os, g); - IdMap nodeIdMap(g); - writer.writeNodeMap("id", nodeIdMap); - IdMap edgeIdMap(g); - writer.writeEdgeMap("id", edgeIdMap); - writer.run(); - } - - /// \brief Write a capacitated graph instance to the output. - /// - /// Write a capacitated graph (graph+capacity on the - /// edges) to the output. - /// \param os The output stream. - /// \param g The graph. - /// \param capacity The capacity map. - template - void writeGraph(std::ostream& os, const Graph &g, - const CapacityMap& capacity) { - GraphWriter writer(os, g); - IdMap nodeIdMap(g); - writer.writeNodeMap("id", nodeIdMap); - IdMap edgeIdMap(g); - writer.writeEdgeMap("id", edgeIdMap); - writer.writeEdgeMap("capacity", capacity); - writer.run(); - } - - /// \brief Write a shortest path instance to the output. - /// - /// Write a shortest path instance (graph+capacity on the - /// edges+designated source) to the output. - /// \param os The output stream. - /// \param g The graph. - /// \param capacity The capacity map. - /// \param s The source node. - template - void writeGraph(std::ostream& os, const Graph &g, - const CapacityMap& capacity, const typename Graph::Node &s) { - GraphWriter writer(os, g); - IdMap nodeIdMap(g); - writer.writeNodeMap("id", nodeIdMap); - IdMap edgeIdMap(g); - writer.writeEdgeMap("id", edgeIdMap); - writer.writeEdgeMap("capacity", capacity); - writer.writeNode("source", s); - writer.run(); - } - - - /// \brief Write a max flow instance to the output. - /// - /// Write a max flow instance (graph+capacity on the - /// edges+designated source and target) to the output. + /// It is a helper function to write a graph to the given output + /// stream. It gives back a GraphWriter object and this object + /// can write more maps, labeled nodes and edges and attributes. + /// \warning Do not forget to call the \c run() function. /// /// \param os The output stream. /// \param g The graph. - /// \param capacity The capacity map. - /// \param s The source node. - /// \param t The target node. - template - void writeGraph(std::ostream& os, const Graph &g, - const CapacityMap& capacity, const typename Graph::Node &s, - const typename Graph::Node &t) { - GraphWriter writer(os, g); - IdMap nodeIdMap(g); - writer.writeNodeMap("id", nodeIdMap); - IdMap edgeIdMap(g); - writer.writeEdgeMap("id", edgeIdMap); - writer.writeEdgeMap("capacity", capacity); - writer.writeNode("source", s); - writer.writeNode("target", t); - writer.run(); + template + GraphWriter graphWriter(std::ostream& os, const Graph &g) { + return GraphWriter(os, g); } - /// \brief Write a min cost flow instance to the output. + /// \brief Write a graph to the output. /// - /// Write a min cost flow instance (graph+capacity on the edges+cost - /// function on the edges+designated source and target) to the output. + /// It is a helper function to write a graph to the given output + /// file. It gives back a GraphWriter object and this object + /// can write more maps, labeled nodes and edges and attributes. + /// \warning Do not forget to call the \c run() function. /// - /// \param os The output stream. + /// \param fn The filename. /// \param g The graph. - /// \param capacity The capacity map. - /// \param s The source node. - /// \param t The target node. - /// \param cost The cost map. - template - void writeGraph(std::ostream& os, const Graph &g, - const CapacityMap& capacity, const typename Graph::Node &s, - const typename Graph::Node &t, const CostMap& cost) { - GraphWriter writer(os, g); - IdMap nodeIdMap(g); - writer.writeNodeMap("id", nodeIdMap); - IdMap edgeIdMap(g); - writer.writeEdgeMap("id", edgeIdMap); - writer.writeEdgeMap("capacity", capacity); - writer.writeEdgeMap("cost", cost); - writer.writeNode("source", s); - writer.writeNode("target", t); - writer.run(); + template + GraphWriter graphWriter(const std::string& fn, const Graph &g) { + return GraphWriter(fn, g); } /// \brief The undirected graph writer class. @@ -684,32 +603,35 @@ /// \brief Write an undirected graph to the output. /// - /// Write an undirected graph to the output. + /// It is a helper function to write an undirected graph to the given output + /// stream. It gives back an UndirGraphWriter object and this object + /// can write more maps, labeled nodes and edges and attributes. + /// \warning Do not forget to call the \c run() function. + /// /// \param os The output stream. /// \param g The graph. - template - void writeUndirGraph(std::ostream& os, const Graph &g) { - UndirGraphWriter writer(os, g); - writer.run(); + template + UndirGraphWriter undirGraphWriter(std::ostream& os, const Graph &g) { + return UndirGraphWriter(os, g); } - /// \brief Write an undirected multigraph (undirected graph + capacity - /// map on the edges) to the output. + /// \brief Write an undirected graph to the output. /// - /// Write an undirected multigraph (undirected graph + capacity - /// map on the edges) to the output. - /// \param os The output stream. + /// It is a helper function to write an undirected graph to the given output + /// file. It gives back an UndirGraphWriter object and this object + /// can write more maps, labeled nodes, edges, undirected edges and + /// attributes. + /// + /// \warning Do not forget to call the \c run() function. + /// + /// \param fn The output file. /// \param g The graph. - /// \param capacity The capacity undirected map. - template - void writeUndirGraph(std::ostream& os, const Graph &g, - const CapacityMap& capacity) { - UndirGraphWriter writer(os, g); - writer.writeUndirEdgeMap("capacity", capacity); - writer.run(); + template + UndirGraphWriter undirGraphWriter(const std::string& fn, + const Graph &g) { + return UndirGraphWriter(fn, g); } - /// @} } diff -r 503d0c79078a -r 51d5d41e15b1 test/heap_test.cc --- a/test/heap_test.cc Wed Oct 26 10:59:51 2005 +0000 +++ b/test/heap_test.cc Wed Oct 26 11:09:29 2005 +0000 @@ -55,7 +55,10 @@ std::ifstream input(f_name.c_str()); check(input, "Input file '" << f_name << "' not found."); - readGraph(input, graph, length, start); + GraphReader(input, graph). + readEdgeMap("length", length). + readNode("source", start). + run(); { std::cerr << "Checking Bin Heap" << std::endl;