src/lemon/graph_writer.h
changeset 1208 f486d30e4e7b
parent 1188 7e529047df1a
child 1214 39993ada11c7
equal deleted inserted replaced
3:a116e83da6d8 4:410cab1b4986
    25 #include <map>
    25 #include <map>
    26 #include <vector>
    26 #include <vector>
    27 
    27 
    28 #include <memory>
    28 #include <memory>
    29 
    29 
       
    30 #include <lemon/map_utils.h>
    30 #include <lemon/invalid.h>
    31 #include <lemon/invalid.h>
    31 #include <lemon/error.h>
    32 #include <lemon/error.h>
    32 
    33 
    33 
    34 
    34 namespace lemon {
    35 namespace lemon {
   160     /// \brief Construct a new GraphWriter.
   161     /// \brief Construct a new GraphWriter.
   161     ///
   162     ///
   162     /// Construct a new GraphWriter. It writes from the given map,
   163     /// Construct a new GraphWriter. It writes from the given map,
   163     /// it constructs the given map and it use the given writer as the
   164     /// it constructs the given map and it use the given writer as the
   164     /// default skipper.
   165     /// default skipper.
   165     GraphWriter(std::ostream& _os, Graph& _graph) : os(_os), graph(_graph) {}
   166     GraphWriter(std::ostream& _os, const Graph& _graph) 
       
   167       : os(_os), graph(_graph) {}
   166 
   168 
   167 
   169 
   168     /// \brief Destruct the graph writer.
   170     /// \brief Destruct the graph writer.
   169     ///
   171     ///
   170     /// Destruct the graph writer.
   172     /// Destruct the graph writer.
   365 
   367 
   366     typedef std::vector<std::pair<std::string, Edge> > EdgeWriters;
   368     typedef std::vector<std::pair<std::string, Edge> > EdgeWriters;
   367     EdgeWriters edge_writers;
   369     EdgeWriters edge_writers;
   368 
   370 
   369     std::ostream& os;
   371     std::ostream& os;
   370     Graph& graph;
   372     const Graph& graph;
   371 
   373 
   372   };
   374   };
   373 
   375 
       
   376   /// Ready to use writer function.  
       
   377   template<typename Graph, typename CapacityMap, typename CostMap>
       
   378   void writeGraph(std::ostream& os, const Graph &g, 
       
   379 		  const CapacityMap& capacity, const typename Graph::Node &s,
       
   380 		  const typename Graph::Node &t, const CostMap& cost) {
       
   381     GraphWriter<Graph> reader(os, g);
       
   382     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   383     reader.addNodeMap("id", nodeIdMap);
       
   384     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   385     reader.addEdgeMap("id", edgeIdMap);
       
   386     reader.addEdgeMap("capacity", capacity);
       
   387     reader.addEdgeMap("cost", cost);
       
   388     reader.addNode("source", s);
       
   389     reader.addNode("target", t);
       
   390     reader.run();
       
   391   }
       
   392 
       
   393   /// Ready to use writer function.  
       
   394   template<typename Graph, typename CapacityMap, typename CostMap>
       
   395   void writeGraph(std::ostream& os, const Graph &g, 
       
   396 		  const CapacityMap& capacity, const typename Graph::Node &s,
       
   397 		  const typename Graph::Node &t) {
       
   398     GraphWriter<Graph> reader(os, g);
       
   399     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   400     reader.addNodeMap("id", nodeIdMap);
       
   401     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   402     reader.addEdgeMap("id", edgeIdMap);
       
   403     reader.addEdgeMap("capacity", capacity);
       
   404     reader.addNode("source", s);
       
   405     reader.addNode("target", t);
       
   406     reader.run();
       
   407   }
       
   408 
       
   409   /// Ready to use writer function.  
       
   410   template<typename Graph, typename CapacityMap>
       
   411   void writeGraph(std::ostream& os, const Graph &g, 
       
   412 		  const CapacityMap& capacity, const typename Graph::Node &s) {
       
   413     GraphWriter<Graph> reader(os, g);
       
   414     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   415     reader.addNodeMap("id", nodeIdMap);
       
   416     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   417     reader.addEdgeMap("id", edgeIdMap);
       
   418     reader.addEdgeMap("capacity", capacity);
       
   419     reader.addNode("source", s);
       
   420     reader.run();
       
   421   }
       
   422   /// Ready to use writer function.  
       
   423   template<typename Graph, typename CapacityMap>
       
   424   void writeGraph(std::ostream& os, const Graph &g, 
       
   425 		  const CapacityMap& capacity) {
       
   426     GraphWriter<Graph> reader(os, g);
       
   427     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   428     reader.addNodeMap("id", nodeIdMap);
       
   429     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   430     reader.addEdgeMap("id", edgeIdMap);
       
   431     reader.addEdgeMap("capacity", capacity);
       
   432     reader.run();
       
   433   }
       
   434   /// Ready to use writer function.  
       
   435   template<typename Graph>
       
   436   void writeGraph(std::ostream& os, const Graph &g) {
       
   437     GraphWriter<Graph> reader(os, g);
       
   438     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   439     reader.addNodeMap("id", nodeIdMap);
       
   440     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   441     reader.addEdgeMap("id", edgeIdMap);
       
   442     reader.run();
       
   443   }
       
   444 
   374 
   445 
   375 }
   446 }