1.1 --- a/src/lemon/graph_writer.h Wed Mar 09 14:13:01 2005 +0000
1.2 +++ b/src/lemon/graph_writer.h Wed Mar 09 14:15:22 2005 +0000
1.3 @@ -27,6 +27,7 @@
1.4
1.5 #include <memory>
1.6
1.7 +#include <lemon/map_utils.h>
1.8 #include <lemon/invalid.h>
1.9 #include <lemon/error.h>
1.10
1.11 @@ -162,7 +163,8 @@
1.12 /// Construct a new GraphWriter. It writes from the given map,
1.13 /// it constructs the given map and it use the given writer as the
1.14 /// default skipper.
1.15 - GraphWriter(std::ostream& _os, Graph& _graph) : os(_os), graph(_graph) {}
1.16 + GraphWriter(std::ostream& _os, const Graph& _graph)
1.17 + : os(_os), graph(_graph) {}
1.18
1.19
1.20 /// \brief Destruct the graph writer.
1.21 @@ -367,9 +369,78 @@
1.22 EdgeWriters edge_writers;
1.23
1.24 std::ostream& os;
1.25 - Graph& graph;
1.26 + const Graph& graph;
1.27
1.28 };
1.29
1.30 + /// Ready to use writer function.
1.31 + template<typename Graph, typename CapacityMap, typename CostMap>
1.32 + void writeGraph(std::ostream& os, const Graph &g,
1.33 + const CapacityMap& capacity, const typename Graph::Node &s,
1.34 + const typename Graph::Node &t, const CostMap& cost) {
1.35 + GraphWriter<Graph> reader(os, g);
1.36 + IdMap<Graph, typename Graph::Node> nodeIdMap(g);
1.37 + reader.addNodeMap("id", nodeIdMap);
1.38 + IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
1.39 + reader.addEdgeMap("id", edgeIdMap);
1.40 + reader.addEdgeMap("capacity", capacity);
1.41 + reader.addEdgeMap("cost", cost);
1.42 + reader.addNode("source", s);
1.43 + reader.addNode("target", t);
1.44 + reader.run();
1.45 + }
1.46 +
1.47 + /// Ready to use writer function.
1.48 + template<typename Graph, typename CapacityMap, typename CostMap>
1.49 + void writeGraph(std::ostream& os, const Graph &g,
1.50 + const CapacityMap& capacity, const typename Graph::Node &s,
1.51 + const typename Graph::Node &t) {
1.52 + GraphWriter<Graph> reader(os, g);
1.53 + IdMap<Graph, typename Graph::Node> nodeIdMap(g);
1.54 + reader.addNodeMap("id", nodeIdMap);
1.55 + IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
1.56 + reader.addEdgeMap("id", edgeIdMap);
1.57 + reader.addEdgeMap("capacity", capacity);
1.58 + reader.addNode("source", s);
1.59 + reader.addNode("target", t);
1.60 + reader.run();
1.61 + }
1.62 +
1.63 + /// Ready to use writer function.
1.64 + template<typename Graph, typename CapacityMap>
1.65 + void writeGraph(std::ostream& os, const Graph &g,
1.66 + const CapacityMap& capacity, const typename Graph::Node &s) {
1.67 + GraphWriter<Graph> reader(os, g);
1.68 + IdMap<Graph, typename Graph::Node> nodeIdMap(g);
1.69 + reader.addNodeMap("id", nodeIdMap);
1.70 + IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
1.71 + reader.addEdgeMap("id", edgeIdMap);
1.72 + reader.addEdgeMap("capacity", capacity);
1.73 + reader.addNode("source", s);
1.74 + reader.run();
1.75 + }
1.76 + /// Ready to use writer function.
1.77 + template<typename Graph, typename CapacityMap>
1.78 + void writeGraph(std::ostream& os, const Graph &g,
1.79 + const CapacityMap& capacity) {
1.80 + GraphWriter<Graph> reader(os, g);
1.81 + IdMap<Graph, typename Graph::Node> nodeIdMap(g);
1.82 + reader.addNodeMap("id", nodeIdMap);
1.83 + IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
1.84 + reader.addEdgeMap("id", edgeIdMap);
1.85 + reader.addEdgeMap("capacity", capacity);
1.86 + reader.run();
1.87 + }
1.88 + /// Ready to use writer function.
1.89 + template<typename Graph>
1.90 + void writeGraph(std::ostream& os, const Graph &g) {
1.91 + GraphWriter<Graph> reader(os, g);
1.92 + IdMap<Graph, typename Graph::Node> nodeIdMap(g);
1.93 + reader.addNodeMap("id", nodeIdMap);
1.94 + IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
1.95 + reader.addEdgeMap("id", edgeIdMap);
1.96 + reader.run();
1.97 + }
1.98 +
1.99
1.100 }