Changes in / [599:f63e87b9748e:597:2ca0cdb5f366] in lemon-main
- Location:
- lemon
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/lgf_reader.h
r599 r584 102 102 }; 103 103 104 template <typename _G R, bool _dir, typename _Map,104 template <typename _Graph, bool _dir, typename _Map, 105 105 typename _Converter = DefaultConverter<typename _Map::Value> > 106 class GraphArcMapStorage : public MapStorageBase<typename _G R::Edge> {106 class GraphArcMapStorage : public MapStorageBase<typename _Graph::Edge> { 107 107 public: 108 108 typedef _Map Map; 109 109 typedef _Converter Converter; 110 typedef _G R GR;111 typedef typename G R::Edge Item;110 typedef _Graph Graph; 111 typedef typename Graph::Edge Item; 112 112 static const bool dir = _dir; 113 113 114 114 private: 115 const G R& _graph;115 const Graph& _graph; 116 116 Map& _map; 117 117 Converter _converter; 118 118 119 119 public: 120 GraphArcMapStorage(const G R& graph, Map& map,120 GraphArcMapStorage(const Graph& graph, Map& map, 121 121 const Converter& converter = Converter()) 122 122 : _graph(graph), _map(map), _converter(converter) {} … … 174 174 }; 175 175 176 template <typename G R>176 template <typename Graph> 177 177 struct GraphArcLookUpConverter { 178 const G R& _graph;179 const std::map<std::string, typename G R::Edge>& _map;180 181 GraphArcLookUpConverter(const G R& graph,178 const Graph& _graph; 179 const std::map<std::string, typename Graph::Edge>& _map; 180 181 GraphArcLookUpConverter(const Graph& graph, 182 182 const std::map<std::string, 183 typename G R::Edge>& map)183 typename Graph::Edge>& map) 184 184 : _graph(graph), _map(map) {} 185 185 186 typename G R::Arc operator()(const std::string& str) {186 typename Graph::Arc operator()(const std::string& str) { 187 187 if (str.empty() || (str[0] != '+' && str[0] != '-')) { 188 188 throw FormatError("Item must start with '+' or '-'"); 189 189 } 190 typename std::map<std::string, typename G R::Edge>190 typename std::map<std::string, typename Graph::Edge> 191 191 ::const_iterator it = _map.find(str.substr(1)); 192 192 if (it == _map.end()) { … … 388 388 } 389 389 390 template <typename D GR>390 template <typename Digraph> 391 391 class DigraphReader; 392 392 393 template <typename TDGR> 394 DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is = std::cin); 395 template <typename TDGR> 396 DigraphReader<TDGR> digraphReader(TDGR& digraph, const std::string& fn); 397 template <typename TDGR> 398 DigraphReader<TDGR> digraphReader(TDGR& digraph, const char *fn); 393 template <typename Digraph> 394 DigraphReader<Digraph> digraphReader(Digraph& digraph, 395 std::istream& is = std::cin); 396 template <typename Digraph> 397 DigraphReader<Digraph> digraphReader(Digraph& digraph, const std::string& fn); 398 template <typename Digraph> 399 DigraphReader<Digraph> digraphReader(Digraph& digraph, const char *fn); 399 400 400 401 /// \ingroup lemon_io … … 419 420 /// 420 421 ///\code 421 /// DigraphReader<D GR>(digraph, std::cin).422 /// DigraphReader<Digraph>(digraph, std::cin). 422 423 /// nodeMap("coordinates", coord_map). 423 424 /// arcMap("capacity", cap_map). … … 448 449 /// a single pass, because the arcs are not constructed when the node 449 450 /// maps are read. 450 template <typename DGR>451 template <typename GR> 451 452 class DigraphReader { 452 453 public: 453 454 454 typedef DGR Digraph;455 typedef GR Digraph; 455 456 456 457 private: 457 458 458 TEMPLATE_DIGRAPH_TYPEDEFS(D GR);459 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); 459 460 460 461 std::istream* _is; … … 462 463 std::string _filename; 463 464 464 D GR& _digraph;465 Digraph& _digraph; 465 466 466 467 std::string _nodes_caption; … … 500 501 /// Construct a directed graph reader, which reads from the given 501 502 /// input stream. 502 DigraphReader(D GR& digraph, std::istream& is = std::cin)503 DigraphReader(Digraph& digraph, std::istream& is = std::cin) 503 504 : _is(&is), local_is(false), _digraph(digraph), 504 505 _use_nodes(false), _use_arcs(false), … … 509 510 /// Construct a directed graph reader, which reads from the given 510 511 /// file. 511 DigraphReader(D GR& digraph, const std::string& fn)512 DigraphReader(Digraph& digraph, const std::string& fn) 512 513 : _is(new std::ifstream(fn.c_str())), local_is(true), 513 514 _filename(fn), _digraph(digraph), … … 524 525 /// Construct a directed graph reader, which reads from the given 525 526 /// file. 526 DigraphReader(D GR& digraph, const char* fn)527 DigraphReader(Digraph& digraph, const char* fn) 527 528 : _is(new std::ifstream(fn)), local_is(true), 528 529 _filename(fn), _digraph(digraph), … … 560 561 private: 561 562 562 template <typename TDGR>563 friend DigraphReader< TDGR> digraphReader(TDGR& digraph, std::istream& is);564 template <typename TDGR>565 friend DigraphReader< TDGR> digraphReader(TDGR& digraph,566 567 template <typename TDGR>568 friend DigraphReader< TDGR> digraphReader(TDGR& digraph, const char *fn);563 template <typename DGR> 564 friend DigraphReader<DGR> digraphReader(DGR& digraph, std::istream& is); 565 template <typename DGR> 566 friend DigraphReader<DGR> digraphReader(DGR& digraph, 567 const std::string& fn); 568 template <typename DGR> 569 friend DigraphReader<DGR> digraphReader(DGR& digraph, const char *fn); 569 570 570 571 DigraphReader(DigraphReader& other) … … 1188 1189 1189 1190 }; 1190 1191 /// \ingroup lemon_io1192 ///1193 /// \brief Return a \ref DigraphReader class1194 ///1195 /// This function just returns a \ref DigraphReader class.1196 ///1197 /// With this function a digraph can be read from an1198 /// \ref lgf-format "LGF" file or input stream with several maps and1199 /// attributes. For example, there is network flow problem on a1200 /// digraph, i.e. a digraph with a \e capacity map on the arcs and1201 /// \e source and \e target nodes. This digraph can be read with the1202 /// following code:1203 ///1204 ///\code1205 ///ListDigraph digraph;1206 ///ListDigraph::ArcMap<int> cm(digraph);1207 ///ListDigraph::Node src, trg;1208 ///digraphReader(digraph, std::cin).1209 /// arcMap("capacity", cap).1210 /// node("source", src).1211 /// node("target", trg).1212 /// run();1213 ///\endcode1214 ///1215 /// For a complete documentation, please see the \ref DigraphReader1216 /// class documentation.1217 /// \warning Don't forget to put the \ref DigraphReader::run() "run()"1218 /// to the end of the parameter list.1219 /// \relates DigraphReader1220 /// \sa digraphReader(TDGR& digraph, const std::string& fn)1221 /// \sa digraphReader(TDGR& digraph, const char* fn)1222 template <typename TDGR>1223 DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is) {1224 DigraphReader<TDGR> tmp(digraph, is);1225 return tmp;1226 }1227 1191 1228 1192 /// \brief Return a \ref DigraphReader class … … 1230 1194 /// This function just returns a \ref DigraphReader class. 1231 1195 /// \relates DigraphReader 1232 /// \sa digraphReader(TDGR& digraph, std::istream& is) 1233 template <typename TDGR> 1234 DigraphReader<TDGR> digraphReader(TDGR& digraph, const std::string& fn) { 1235 DigraphReader<TDGR> tmp(digraph, fn); 1196 template <typename Digraph> 1197 DigraphReader<Digraph> digraphReader(Digraph& digraph, std::istream& is) { 1198 DigraphReader<Digraph> tmp(digraph, is); 1236 1199 return tmp; 1237 1200 } … … 1241 1204 /// This function just returns a \ref DigraphReader class. 1242 1205 /// \relates DigraphReader 1243 /// \sa digraphReader(TDGR& digraph, std::istream& is)1244 template <typename TDGR>1245 DigraphReader<TDGR> digraphReader(TDGR& digraph, const char*fn) {1246 DigraphReader< TDGR> tmp(digraph, fn);1206 template <typename Digraph> 1207 DigraphReader<Digraph> digraphReader(Digraph& digraph, 1208 const std::string& fn) { 1209 DigraphReader<Digraph> tmp(digraph, fn); 1247 1210 return tmp; 1248 1211 } 1249 1212 1250 template <typename GR> 1213 /// \brief Return a \ref DigraphReader class 1214 /// 1215 /// This function just returns a \ref DigraphReader class. 1216 /// \relates DigraphReader 1217 template <typename Digraph> 1218 DigraphReader<Digraph> digraphReader(Digraph& digraph, const char* fn) { 1219 DigraphReader<Digraph> tmp(digraph, fn); 1220 return tmp; 1221 } 1222 1223 template <typename Graph> 1251 1224 class GraphReader; 1252 1225 1253 template <typename TGR> 1254 GraphReader<TGR> graphReader(TGR& graph, std::istream& is = std::cin); 1255 template <typename TGR> 1256 GraphReader<TGR> graphReader(TGR& graph, const std::string& fn); 1257 template <typename TGR> 1258 GraphReader<TGR> graphReader(TGR& graph, const char *fn); 1226 template <typename Graph> 1227 GraphReader<Graph> graphReader(Graph& graph, 1228 std::istream& is = std::cin); 1229 template <typename Graph> 1230 GraphReader<Graph> graphReader(Graph& graph, const std::string& fn); 1231 template <typename Graph> 1232 GraphReader<Graph> graphReader(Graph& graph, const char *fn); 1259 1233 1260 1234 /// \ingroup lemon_io … … 1281 1255 private: 1282 1256 1283 TEMPLATE_GRAPH_TYPEDEFS(G R);1257 TEMPLATE_GRAPH_TYPEDEFS(Graph); 1284 1258 1285 1259 std::istream* _is; … … 1287 1261 std::string _filename; 1288 1262 1289 G R& _graph;1263 Graph& _graph; 1290 1264 1291 1265 std::string _nodes_caption; … … 1325 1299 /// Construct an undirected graph reader, which reads from the given 1326 1300 /// input stream. 1327 GraphReader(G R& graph, std::istream& is = std::cin)1301 GraphReader(Graph& graph, std::istream& is = std::cin) 1328 1302 : _is(&is), local_is(false), _graph(graph), 1329 1303 _use_nodes(false), _use_edges(false), … … 1334 1308 /// Construct an undirected graph reader, which reads from the given 1335 1309 /// file. 1336 GraphReader(G R& graph, const std::string& fn)1310 GraphReader(Graph& graph, const std::string& fn) 1337 1311 : _is(new std::ifstream(fn.c_str())), local_is(true), 1338 1312 _filename(fn), _graph(graph), … … 1349 1323 /// Construct an undirected graph reader, which reads from the given 1350 1324 /// file. 1351 GraphReader(G R& graph, const char* fn)1325 GraphReader(Graph& graph, const char* fn) 1352 1326 : _is(new std::ifstream(fn)), local_is(true), 1353 1327 _filename(fn), _graph(graph), … … 1384 1358 1385 1359 private: 1386 template <typename TGR>1387 friend GraphReader< TGR> graphReader(TGR& graph, std::istream& is);1388 template <typename TGR>1389 friend GraphReader< TGR> graphReader(TGR& graph, const std::string& fn);1390 template <typename TGR>1391 friend GraphReader< TGR> graphReader(TGR& graph, const char *fn);1360 template <typename Graph> 1361 friend GraphReader<Graph> graphReader(Graph& graph, std::istream& is); 1362 template <typename Graph> 1363 friend GraphReader<Graph> graphReader(Graph& graph, const std::string& fn); 1364 template <typename Graph> 1365 friend GraphReader<Graph> graphReader(Graph& graph, const char *fn); 1392 1366 1393 1367 GraphReader(GraphReader& other) … … 1481 1455 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); 1482 1456 _reader_bits::MapStorageBase<Edge>* backward_storage = 1483 new _reader_bits::GraphArcMapStorage<G R, false, Map>(_graph, map);1457 new _reader_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map); 1484 1458 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); 1485 1459 return *this; … … 1495 1469 checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>(); 1496 1470 _reader_bits::MapStorageBase<Edge>* forward_storage = 1497 new _reader_bits::GraphArcMapStorage<G R, true, Map, Converter>1471 new _reader_bits::GraphArcMapStorage<Graph, true, Map, Converter> 1498 1472 (_graph, map, converter); 1499 1473 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); 1500 1474 _reader_bits::MapStorageBase<Edge>* backward_storage = 1501 new _reader_bits::GraphArcMapStorage<G R, false, Map, Converter>1475 new _reader_bits::GraphArcMapStorage<Graph, false, Map, Converter> 1502 1476 (_graph, map, converter); 1503 1477 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); … … 1557 1531 /// Add an arc reading rule to reader. 1558 1532 GraphReader& arc(const std::string& caption, Arc& arc) { 1559 typedef _reader_bits::GraphArcLookUpConverter<G R> Converter;1533 typedef _reader_bits::GraphArcLookUpConverter<Graph> Converter; 1560 1534 Converter converter(_graph, _edge_index); 1561 1535 _reader_bits::ValueStorageBase* storage = … … 2060 2034 }; 2061 2035 2062 /// \ingroup lemon_io2063 ///2064 /// \brief Return a \ref GraphReader class2065 ///2066 /// This function just returns a \ref GraphReader class.2067 ///2068 /// With this function a graph can be read from an2069 /// \ref lgf-format "LGF" file or input stream with several maps and2070 /// attributes. For example, there is weighted matching problem on a2071 /// graph, i.e. a graph with a \e weight map on the edges. This2072 /// graph can be read with the following code:2073 ///2074 ///\code2075 ///ListGraph graph;2076 ///ListGraph::EdgeMap<int> weight(graph);2077 ///graphReader(graph, std::cin).2078 /// edgeMap("weight", weight).2079 /// run();2080 ///\endcode2081 ///2082 /// For a complete documentation, please see the \ref GraphReader2083 /// class documentation.2084 /// \warning Don't forget to put the \ref GraphReader::run() "run()"2085 /// to the end of the parameter list.2086 /// \relates GraphReader2087 /// \sa graphReader(TGR& graph, const std::string& fn)2088 /// \sa graphReader(TGR& graph, const char* fn)2089 template <typename TGR>2090 GraphReader<TGR> graphReader(TGR& graph, std::istream& is) {2091 GraphReader<TGR> tmp(graph, is);2092 return tmp;2093 }2094 2095 2036 /// \brief Return a \ref GraphReader class 2096 2037 /// 2097 2038 /// This function just returns a \ref GraphReader class. 2098 2039 /// \relates GraphReader 2099 /// \sa graphReader(TGR& graph, std::istream& is) 2100 template <typename TGR> 2101 GraphReader<TGR> graphReader(TGR& graph, const std::string& fn) { 2102 GraphReader<TGR> tmp(graph, fn); 2040 template <typename Graph> 2041 GraphReader<Graph> graphReader(Graph& graph, std::istream& is) { 2042 GraphReader<Graph> tmp(graph, is); 2103 2043 return tmp; 2104 2044 } … … 2108 2048 /// This function just returns a \ref GraphReader class. 2109 2049 /// \relates GraphReader 2110 /// \sa graphReader(TGR& graph, std::istream& is) 2111 template <typename TGR> 2112 GraphReader<TGR> graphReader(TGR& graph, const char* fn) { 2113 GraphReader<TGR> tmp(graph, fn); 2050 template <typename Graph> 2051 GraphReader<Graph> graphReader(Graph& graph, const std::string& fn) { 2052 GraphReader<Graph> tmp(graph, fn); 2053 return tmp; 2054 } 2055 2056 /// \brief Return a \ref GraphReader class 2057 /// 2058 /// This function just returns a \ref GraphReader class. 2059 /// \relates GraphReader 2060 template <typename Graph> 2061 GraphReader<Graph> graphReader(Graph& graph, const char* fn) { 2062 GraphReader<Graph> tmp(graph, fn); 2114 2063 return tmp; 2115 2064 } … … 2368 2317 }; 2369 2318 2370 /// \ingroup lemon_io2371 ///2372 2319 /// \brief Return a \ref SectionReader class 2373 2320 /// 2374 2321 /// This function just returns a \ref SectionReader class. 2375 ///2376 /// Please see SectionReader documentation about the custom section2377 /// input.2378 ///2379 2322 /// \relates SectionReader 2380 /// \sa sectionReader(const std::string& fn)2381 /// \sa sectionReader(const char *fn)2382 2323 inline SectionReader sectionReader(std::istream& is) { 2383 2324 SectionReader tmp(is); … … 2389 2330 /// This function just returns a \ref SectionReader class. 2390 2331 /// \relates SectionReader 2391 /// \sa sectionReader(std::istream& is)2392 2332 inline SectionReader sectionReader(const std::string& fn) { 2393 2333 SectionReader tmp(fn); … … 2399 2339 /// This function just returns a \ref SectionReader class. 2400 2340 /// \relates SectionReader 2401 /// \sa sectionReader(std::istream& is)2402 2341 inline SectionReader sectionReader(const char* fn) { 2403 2342 SectionReader tmp(fn); -
lemon/lgf_writer.h
r599 r584 348 348 } 349 349 350 template <typename D GR>350 template <typename Digraph> 351 351 class DigraphWriter; 352 352 353 template <typename TDGR> 354 DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, 355 std::ostream& os = std::cout); 356 template <typename TDGR> 357 DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, const std::string& fn); 358 359 template <typename TDGR> 360 DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, const char* fn); 353 template <typename Digraph> 354 DigraphWriter<Digraph> digraphWriter(const Digraph& digraph, 355 std::ostream& os = std::cout); 356 template <typename Digraph> 357 DigraphWriter<Digraph> digraphWriter(const Digraph& digraph, 358 const std::string& fn); 359 360 template <typename Digraph> 361 DigraphWriter<Digraph> digraphWriter(const Digraph& digraph, 362 const char* fn); 361 363 362 364 … … 380 382 /// 381 383 ///\code 382 /// DigraphWriter<D GR>(digraph, std::cout).384 /// DigraphWriter<Digraph>(digraph, std::cout). 383 385 /// nodeMap("coordinates", coord_map). 384 386 /// nodeMap("size", size). … … 405 407 /// the \c ostream() function, hence the second pass can append its 406 408 /// output to the output of the first pass. 407 template <typename DGR>409 template <typename GR> 408 410 class DigraphWriter { 409 411 public: 410 412 411 typedef DGR Digraph;412 TEMPLATE_DIGRAPH_TYPEDEFS(D GR);413 typedef GR Digraph; 414 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); 413 415 414 416 private: … … 418 420 bool local_os; 419 421 420 const D GR& _digraph;422 const Digraph& _digraph; 421 423 422 424 std::string _nodes_caption; … … 450 452 /// Construct a directed graph writer, which writes to the given 451 453 /// output stream. 452 DigraphWriter(const D GR& digraph, std::ostream& os = std::cout)454 DigraphWriter(const Digraph& digraph, std::ostream& os = std::cout) 453 455 : _os(&os), local_os(false), _digraph(digraph), 454 456 _skip_nodes(false), _skip_arcs(false) {} … … 458 460 /// Construct a directed graph writer, which writes to the given 459 461 /// output file. 460 DigraphWriter(const D GR& digraph, const std::string& fn)462 DigraphWriter(const Digraph& digraph, const std::string& fn) 461 463 : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph), 462 464 _skip_nodes(false), _skip_arcs(false) { … … 471 473 /// Construct a directed graph writer, which writes to the given 472 474 /// output file. 473 DigraphWriter(const D GR& digraph, const char* fn)475 DigraphWriter(const Digraph& digraph, const char* fn) 474 476 : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph), 475 477 _skip_nodes(false), _skip_arcs(false) { … … 504 506 private: 505 507 506 template <typename TDGR>507 friend DigraphWriter< TDGR> digraphWriter(const TDGR& digraph,508 509 template <typename TDGR>510 friend DigraphWriter< TDGR> digraphWriter(const TDGR& digraph,511 512 template <typename TDGR>513 friend DigraphWriter< TDGR> digraphWriter(const TDGR& digraph,514 508 template <typename DGR> 509 friend DigraphWriter<DGR> digraphWriter(const DGR& digraph, 510 std::ostream& os); 511 template <typename DGR> 512 friend DigraphWriter<DGR> digraphWriter(const DGR& digraph, 513 const std::string& fn); 514 template <typename DGR> 515 friend DigraphWriter<DGR> digraphWriter(const DGR& digraph, 516 const char *fn); 515 517 516 518 DigraphWriter(DigraphWriter& other) … … 723 725 724 726 if (label == 0) { 725 IdMap<D GR, Node> id_map(_digraph);726 _writer_bits::MapLess<IdMap<D GR, Node> > id_less(id_map);727 IdMap<Digraph, Node> id_map(_digraph); 728 _writer_bits::MapLess<IdMap<Digraph, Node> > id_less(id_map); 727 729 std::sort(nodes.begin(), nodes.end(), id_less); 728 730 } else { … … 808 810 809 811 if (label == 0) { 810 IdMap<D GR, Arc> id_map(_digraph);811 _writer_bits::MapLess<IdMap<D GR, Arc> > id_less(id_map);812 IdMap<Digraph, Arc> id_map(_digraph); 813 _writer_bits::MapLess<IdMap<Digraph, Arc> > id_less(id_map); 812 814 std::sort(arcs.begin(), arcs.end(), id_less); 813 815 } else { … … 914 916 }; 915 917 916 /// \ingroup lemon_io917 ///918 918 /// \brief Return a \ref DigraphWriter class 919 919 /// 920 /// This function just returns a \ref DigraphWriter class. 921 /// 922 /// With this function a digraph can be write to a file or output 923 /// stream in \ref lgf-format "LGF" format with several maps and 924 /// attributes. For example, with the following code a network flow 925 /// problem can be written to the standard output, i.e. a digraph 926 /// with a \e capacity map on the arcs and \e source and \e target 927 /// nodes: 928 /// 929 ///\code 930 ///ListDigraph digraph; 931 ///ListDigraph::ArcMap<int> cap(digraph); 932 ///ListDigraph::Node src, trg; 933 /// // Setting the capacity map and source and target nodes 934 ///digraphWriter(digraph, std::cout). 935 /// arcMap("capacity", cap). 936 /// node("source", src). 937 /// node("target", trg). 938 /// run(); 939 ///\endcode 940 /// 941 /// For a complete documentation, please see the \ref DigraphWriter 942 /// class documentation. 943 /// \warning Don't forget to put the \ref DigraphWriter::run() "run()" 944 /// to the end of the parameter list. 920 /// This function just returns a \ref DigraphWriter class. 945 921 /// \relates DigraphWriter 946 /// \sa digraphWriter(const TDGR& digraph, const std::string& fn) 947 /// \sa digraphWriter(const TDGR& digraph, const char* fn) 948 template <typename TDGR> 949 DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, std::ostream& os) { 950 DigraphWriter<TDGR> tmp(digraph, os); 922 template <typename Digraph> 923 DigraphWriter<Digraph> digraphWriter(const Digraph& digraph, 924 std::ostream& os) { 925 DigraphWriter<Digraph> tmp(digraph, os); 951 926 return tmp; 952 927 } … … 956 931 /// This function just returns a \ref DigraphWriter class. 957 932 /// \relates DigraphWriter 958 /// \sa digraphWriter(const TDGR& digraph, std::ostream& os) 959 template <typename TDGR> 960 DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, 961 const std::string& fn) { 962 DigraphWriter<TDGR> tmp(digraph, fn); 933 template <typename Digraph> 934 DigraphWriter<Digraph> digraphWriter(const Digraph& digraph, 935 const std::string& fn) { 936 DigraphWriter<Digraph> tmp(digraph, fn); 963 937 return tmp; 964 938 } … … 968 942 /// This function just returns a \ref DigraphWriter class. 969 943 /// \relates DigraphWriter 970 /// \sa digraphWriter(const TDGR& digraph, std::ostream& os)971 template <typename TDGR>972 DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,const char* fn) {973 DigraphWriter< TDGR> tmp(digraph, fn);944 template <typename Digraph> 945 DigraphWriter<Digraph> digraphWriter(const Digraph& digraph, 946 const char* fn) { 947 DigraphWriter<Digraph> tmp(digraph, fn); 974 948 return tmp; 975 949 } 976 950 977 template <typename G R>951 template <typename Graph> 978 952 class GraphWriter; 979 953 980 template <typename TGR> 981 GraphWriter<TGR> graphWriter(const TGR& graph, std::ostream& os = std::cout); 982 template <typename TGR> 983 GraphWriter<TGR> graphWriter(const TGR& graph, const std::string& fn); 984 template <typename TGR> 985 GraphWriter<TGR> graphWriter(const TGR& graph, const char* fn); 954 template <typename Graph> 955 GraphWriter<Graph> graphWriter(const Graph& graph, 956 std::ostream& os = std::cout); 957 template <typename Graph> 958 GraphWriter<Graph> graphWriter(const Graph& graph, const std::string& fn); 959 template <typename Graph> 960 GraphWriter<Graph> graphWriter(const Graph& graph, const char* fn); 986 961 987 962 /// \ingroup lemon_io … … 1005 980 1006 981 typedef GR Graph; 1007 TEMPLATE_GRAPH_TYPEDEFS(G R);982 TEMPLATE_GRAPH_TYPEDEFS(Graph); 1008 983 1009 984 private: … … 1013 988 bool local_os; 1014 989 1015 const G R& _graph;990 const Graph& _graph; 1016 991 1017 992 std::string _nodes_caption; … … 1045 1020 /// Construct a directed graph writer, which writes to the given 1046 1021 /// output stream. 1047 GraphWriter(const G R& graph, std::ostream& os = std::cout)1022 GraphWriter(const Graph& graph, std::ostream& os = std::cout) 1048 1023 : _os(&os), local_os(false), _graph(graph), 1049 1024 _skip_nodes(false), _skip_edges(false) {} … … 1053 1028 /// Construct a directed graph writer, which writes to the given 1054 1029 /// output file. 1055 GraphWriter(const G R& graph, const std::string& fn)1030 GraphWriter(const Graph& graph, const std::string& fn) 1056 1031 : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph), 1057 1032 _skip_nodes(false), _skip_edges(false) { … … 1066 1041 /// Construct a directed graph writer, which writes to the given 1067 1042 /// output file. 1068 GraphWriter(const G R& graph, const char* fn)1043 GraphWriter(const Graph& graph, const char* fn) 1069 1044 : _os(new std::ofstream(fn)), local_os(true), _graph(graph), 1070 1045 _skip_nodes(false), _skip_edges(false) { … … 1099 1074 private: 1100 1075 1101 template <typename TGR> 1102 friend GraphWriter<TGR> graphWriter(const TGR& graph, std::ostream& os); 1103 template <typename TGR> 1104 friend GraphWriter<TGR> graphWriter(const TGR& graph, 1105 const std::string& fn); 1106 template <typename TGR> 1107 friend GraphWriter<TGR> graphWriter(const TGR& graph, const char *fn); 1076 template <typename Graph> 1077 friend GraphWriter<Graph> graphWriter(const Graph& graph, 1078 std::ostream& os); 1079 template <typename Graph> 1080 friend GraphWriter<Graph> graphWriter(const Graph& graph, 1081 const std::string& fn); 1082 template <typename Graph> 1083 friend GraphWriter<Graph> graphWriter(const Graph& graph, 1084 const char *fn); 1108 1085 1109 1086 GraphWriter(GraphWriter& other) … … 1192 1169 checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>(); 1193 1170 _writer_bits::MapStorageBase<Edge>* forward_storage = 1194 new _writer_bits::GraphArcMapStorage<G R, true, Map>(_graph, map);1171 new _writer_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map); 1195 1172 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); 1196 1173 _writer_bits::MapStorageBase<Edge>* backward_storage = 1197 new _writer_bits::GraphArcMapStorage<G R, false, Map>(_graph, map);1174 new _writer_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map); 1198 1175 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); 1199 1176 return *this; … … 1209 1186 checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>(); 1210 1187 _writer_bits::MapStorageBase<Edge>* forward_storage = 1211 new _writer_bits::GraphArcMapStorage<G R, true, Map, Converter>1188 new _writer_bits::GraphArcMapStorage<Graph, true, Map, Converter> 1212 1189 (_graph, map, converter); 1213 1190 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); 1214 1191 _writer_bits::MapStorageBase<Edge>* backward_storage = 1215 new _writer_bits::GraphArcMapStorage<G R, false, Map, Converter>1192 new _writer_bits::GraphArcMapStorage<Graph, false, Map, Converter> 1216 1193 (_graph, map, converter); 1217 1194 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); … … 1271 1248 /// Add an arc writing rule to writer. 1272 1249 GraphWriter& arc(const std::string& caption, const Arc& arc) { 1273 typedef _writer_bits::GraphArcLookUpConverter<G R> Converter;1250 typedef _writer_bits::GraphArcLookUpConverter<Graph> Converter; 1274 1251 Converter converter(_graph, _edge_index); 1275 1252 _writer_bits::ValueStorageBase* storage = … … 1362 1339 1363 1340 if (label == 0) { 1364 IdMap<G R, Node> id_map(_graph);1365 _writer_bits::MapLess<IdMap<G R, Node> > id_less(id_map);1341 IdMap<Graph, Node> id_map(_graph); 1342 _writer_bits::MapLess<IdMap<Graph, Node> > id_less(id_map); 1366 1343 std::sort(nodes.begin(), nodes.end(), id_less); 1367 1344 } else { … … 1447 1424 1448 1425 if (label == 0) { 1449 IdMap<G R, Edge> id_map(_graph);1450 _writer_bits::MapLess<IdMap<G R, Edge> > id_less(id_map);1426 IdMap<Graph, Edge> id_map(_graph); 1427 _writer_bits::MapLess<IdMap<Graph, Edge> > id_less(id_map); 1451 1428 std::sort(edges.begin(), edges.end(), id_less); 1452 1429 } else { … … 1553 1530 }; 1554 1531 1555 /// \ingroup lemon_io1556 ///1557 1532 /// \brief Return a \ref GraphWriter class 1558 1533 /// 1559 /// This function just returns a \ref GraphWriter class. 1560 /// 1561 /// With this function a graph can be write to a file or output 1562 /// stream in \ref lgf-format "LGF" format with several maps and 1563 /// attributes. For example, with the following code a weighted 1564 /// matching problem can be written to the standard output, i.e. a 1565 /// graph with a \e weight map on the edges: 1566 /// 1567 ///\code 1568 ///ListGraph graph; 1569 ///ListGraph::EdgeMap<int> weight(graph); 1570 /// // Setting the weight map 1571 ///graphWriter(graph, std::cout). 1572 /// edgeMap("weight", weight). 1573 /// run(); 1574 ///\endcode 1575 /// 1576 /// For a complete documentation, please see the \ref GraphWriter 1577 /// class documentation. 1578 /// \warning Don't forget to put the \ref GraphWriter::run() "run()" 1579 /// to the end of the parameter list. 1534 /// This function just returns a \ref GraphWriter class. 1580 1535 /// \relates GraphWriter 1581 /// \sa graphWriter(const TGR& graph, const std::string& fn) 1582 /// \sa graphWriter(const TGR& graph, const char* fn) 1583 template <typename TGR> 1584 GraphWriter<TGR> graphWriter(const TGR& graph, std::ostream& os) { 1585 GraphWriter<TGR> tmp(graph, os); 1536 template <typename Graph> 1537 GraphWriter<Graph> graphWriter(const Graph& graph, 1538 std::ostream& os) { 1539 GraphWriter<Graph> tmp(graph, os); 1586 1540 return tmp; 1587 1541 } … … 1591 1545 /// This function just returns a \ref GraphWriter class. 1592 1546 /// \relates GraphWriter 1593 /// \sa graphWriter(const TGR& graph, std::ostream& os) 1594 template <typename TGR> 1595 GraphWriter<TGR> graphWriter(const TGR& graph, const std::string& fn) { 1596 GraphWriter<TGR> tmp(graph, fn); 1547 template <typename Graph> 1548 GraphWriter<Graph> graphWriter(const Graph& graph, const std::string& fn) { 1549 GraphWriter<Graph> tmp(graph, fn); 1597 1550 return tmp; 1598 1551 } … … 1602 1555 /// This function just returns a \ref GraphWriter class. 1603 1556 /// \relates GraphWriter 1604 /// \sa graphWriter(const TGR& graph, std::ostream& os) 1605 template <typename TGR> 1606 GraphWriter<TGR> graphWriter(const TGR& graph, const char* fn) { 1607 GraphWriter<TGR> tmp(graph, fn); 1557 template <typename Graph> 1558 GraphWriter<Graph> graphWriter(const Graph& graph, const char* fn) { 1559 GraphWriter<Graph> tmp(graph, fn); 1608 1560 return tmp; 1609 1561 } … … 1795 1747 }; 1796 1748 1797 /// \ingroup lemon_io1798 ///1799 1749 /// \brief Return a \ref SectionWriter class 1800 1750 /// 1801 1751 /// This function just returns a \ref SectionWriter class. 1802 ///1803 /// Please see SectionWriter documentation about the custom section1804 /// output.1805 ///1806 1752 /// \relates SectionWriter 1807 /// \sa sectionWriter(const std::string& fn)1808 /// \sa sectionWriter(const char *fn)1809 1753 inline SectionWriter sectionWriter(std::ostream& os) { 1810 1754 SectionWriter tmp(os); … … 1816 1760 /// This function just returns a \ref SectionWriter class. 1817 1761 /// \relates SectionWriter 1818 /// \sa sectionWriter(std::ostream& os)1819 1762 inline SectionWriter sectionWriter(const std::string& fn) { 1820 1763 SectionWriter tmp(fn); … … 1826 1769 /// This function just returns a \ref SectionWriter class. 1827 1770 /// \relates SectionWriter 1828 /// \sa sectionWriter(std::ostream& os)1829 1771 inline SectionWriter sectionWriter(const char* fn) { 1830 1772 SectionWriter tmp(fn);
Note: See TracChangeset
for help on using the changeset viewer.