[Lemon-commits] [lemon_svn] deba: r2272 - in hugo/trunk: demo lemon lemon/bits test

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:51:25 CET 2006


Author: deba
Date: Wed Oct 26 13:09:29 2005
New Revision: 2272

Modified:
   hugo/trunk/demo/dim_to_lgf.cc
   hugo/trunk/lemon/bits/item_reader.h
   hugo/trunk/lemon/graph_reader.h
   hugo/trunk/lemon/graph_writer.h
   hugo/trunk/test/heap_test.cc

Log:
Removing old input/output functions



Modified: hugo/trunk/demo/dim_to_lgf.cc
==============================================================================
--- hugo/trunk/demo/dim_to_lgf.cc	(original)
+++ hugo/trunk/demo/dim_to_lgf.cc	Wed Oct 26 13:09:29 2005
@@ -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<Graph>(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<Graph>(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<Graph>(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<Graph>(os, graph).
+      writeEdgeMap("capacity", capacity).
+      run();
   } else if (typeName == "plain") {
     Graph graph;
     readDimacs(is, graph);
-    writeGraph(os, graph);
+    GraphWriter<Graph>(os, graph).run();
   } else {
     cerr << "Invalid type error" << endl;
     return -1;

Modified: hugo/trunk/lemon/bits/item_reader.h
==============================================================================
--- hugo/trunk/lemon/bits/item_reader.h	(original)
+++ hugo/trunk/lemon/bits/item_reader.h	Wed Oct 26 13:09:29 2005
@@ -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;
       }
     }

Modified: hugo/trunk/lemon/graph_reader.h
==============================================================================
--- hugo/trunk/lemon/graph_reader.h	(original)
+++ hugo/trunk/lemon/graph_reader.h	Wed Oct 26 13:09:29 2005
@@ -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.
+  ///
+  /// \warning Do not forget to call the \c run() function.
   ///
-  /// Read a graph from an input stream.
   /// \param is The input stream.
   /// \param g The graph.
   template<typename Graph>
-  void readGraph(std::istream& is, Graph &g) {
-    GraphReader<Graph> reader(is, g);
-    reader.run();
+  GraphReader<Graph> graphReader(std::istream& is, Graph &g) {
+    return GraphReader<Graph>(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.
-  /// \param g The graph.
-  /// \param capacity The capacity map.
-  template<typename Graph, typename CapacityMap>
-  void readGraph(std::istream& is, Graph &g, CapacityMap& capacity) {
-    GraphReader<Graph> reader(is, g);
-    reader.readEdgeMap("capacity", capacity);
-    reader.run();
-  }
-
-  /// \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<typename Graph, typename CapacityMap>
-  void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, 
-		  typename Graph::Node &s) {
-    GraphReader<Graph> 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.
+  /// \brief Read a graph from the input.
   ///
-  /// \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<typename Graph, typename CapacityMap>
-  void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, 
-		  typename Graph::Node &s, typename Graph::Node &t) {
-    GraphReader<Graph> 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.
+  /// 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.
   ///
-  /// Read a min cost flow instance (graph+capacity on the edges+cost
-  /// function on the edges+designated source and target) from an input stream.
+  /// \warning Do not forget to call the \c run() function.
   ///
-  /// \param is The input stream.
+  /// \param fn The input 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<typename Graph, typename CapacityMap, typename CostMap>
-  void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, 
-		  typename Graph::Node &s, typename Graph::Node &t, 
-		  CostMap& cost) {
-    GraphReader<Graph> reader(is, g);
-    reader.readEdgeMap("capacity", capacity);
-    reader.readEdgeMap("cost", cost);
-    reader.readNode("source", s);
-    reader.readNode("target", t);
-    reader.run();
+  template<typename Graph>
+  GraphReader<Graph> graphReader(const std::string& fn, Graph &g) {
+    return GraphReader<Graph>(fn, g);
   }
 
-
-  /// \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<ReaderTraits> attribute_reader;
   };
 
-  /// \brief Read an undirected graph from an input stream.
+  /// \brief Read an undirected graph from the input.
+  ///
+  /// 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.
   ///
-  /// Read an undirected graph from an input stream.
   /// \param is The input stream.
   /// \param g The graph.
   template<typename Graph>
-  void readUndirGraph(std::istream& is, Graph &g) {
-    UndirGraphReader<Graph> reader(is, g);
-    reader.run();
+  UndirGraphReader<Graph> undirGraphReader(std::istream& is, Graph &g) {
+    return GraphReader<Graph>(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<typename Graph, typename CapacityMap>
-  void readUndirGraph(std::istream& is, Graph &g, CapacityMap& capacity) {
-    UndirGraphReader<Graph> reader(is, g);
-    reader.readUndirEdgeMap("capacity", capacity);
-    reader.run();
+  template<typename Graph>
+  UndirGraphReader<Graph> undirGraphReader(const std::string& fn, Graph &g) {
+    return GraphReader<Graph>(fn, g);
   }
 
-
   /// @}
 }
 

Modified: hugo/trunk/lemon/graph_writer.h
==============================================================================
--- hugo/trunk/lemon/graph_writer.h	(original)
+++ hugo/trunk/lemon/graph_writer.h	Wed Oct 26 13:09:29 2005
@@ -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<typename Graph>
-  void writeGraph(std::ostream& os, const Graph &g) {
-    GraphWriter<Graph> writer(os, g);
-    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
-    writer.writeNodeMap("id", nodeIdMap);
-    IdMap<Graph, typename Graph::Edge> 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<typename Graph, typename CapacityMap>
-  void writeGraph(std::ostream& os, const Graph &g, 
-		  const CapacityMap& capacity) {
-    GraphWriter<Graph> writer(os, g);
-    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
-    writer.writeNodeMap("id", nodeIdMap);
-    IdMap<Graph, typename Graph::Edge> 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<typename Graph, typename CapacityMap>
-  void writeGraph(std::ostream& os, const Graph &g, 
-		  const CapacityMap& capacity, const typename Graph::Node &s) {
-    GraphWriter<Graph> writer(os, g);
-    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
-    writer.writeNodeMap("id", nodeIdMap);
-    IdMap<Graph, typename Graph::Edge> 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.
+  /// \brief Write a graph 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<typename Graph, typename CapacityMap>
-  void writeGraph(std::ostream& os, const Graph &g, 
-		  const CapacityMap& capacity, const typename Graph::Node &s,
-		  const typename Graph::Node &t) {
-    GraphWriter<Graph> writer(os, g);
-    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
-    writer.writeNodeMap("id", nodeIdMap);
-    IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
-    writer.writeEdgeMap("id", edgeIdMap);
-    writer.writeEdgeMap("capacity", capacity);
-    writer.writeNode("source", s);
-    writer.writeNode("target", t);
-    writer.run();
+  template <typename Graph>
+  GraphWriter<Graph> graphWriter(std::ostream& os, const Graph &g) {
+    return GraphWriter<Graph>(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<typename Graph, typename CapacityMap, typename CostMap>
-  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<Graph> writer(os, g);
-    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
-    writer.writeNodeMap("id", nodeIdMap);
-    IdMap<Graph, typename Graph::Edge> 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 <typename Graph>
+  GraphWriter<Graph> graphWriter(const std::string& fn, const Graph &g) {
+    return GraphWriter<Graph>(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<typename Graph>
-  void writeUndirGraph(std::ostream& os, const Graph &g) {
-    UndirGraphWriter<Graph> writer(os, g);
-    writer.run();
+  template <typename Graph>
+  UndirGraphWriter<Graph> undirGraphWriter(std::ostream& os, const Graph &g) {
+    return UndirGraphWriter<Graph>(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<typename Graph, typename CapacityMap>
-  void writeUndirGraph(std::ostream& os, const Graph &g, 
-		       const CapacityMap& capacity) {
-    UndirGraphWriter<Graph> writer(os, g);
-    writer.writeUndirEdgeMap("capacity", capacity);
-    writer.run();
+  template <typename Graph>
+  UndirGraphWriter<Graph> undirGraphWriter(const std::string& fn, 
+					   const Graph &g) {
+    return UndirGraphWriter<Graph>(fn, g);
   }
 
-
   /// @}
 
 }

Modified: hugo/trunk/test/heap_test.cc
==============================================================================
--- hugo/trunk/test/heap_test.cc	(original)
+++ hugo/trunk/test/heap_test.cc	Wed Oct 26 13:09:29 2005
@@ -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<Graph>(input, graph).
+    readEdgeMap("length", length).
+    readNode("source", start).
+    run();  
  
   {
     std::cerr << "Checking Bin Heap" << std::endl;



More information about the Lemon-commits mailing list