99 virtual void set(const Item& item ,const std::string& value) { |
99 virtual void set(const Item& item ,const std::string& value) { |
100 _map.set(item, _converter(value)); |
100 _map.set(item, _converter(value)); |
101 } |
101 } |
102 }; |
102 }; |
103 |
103 |
104 template <typename _Graph, bool _dir, typename _Map, |
104 template <typename _GR, bool _dir, typename _Map, |
105 typename _Converter = DefaultConverter<typename _Map::Value> > |
105 typename _Converter = DefaultConverter<typename _Map::Value> > |
106 class GraphArcMapStorage : public MapStorageBase<typename _Graph::Edge> { |
106 class GraphArcMapStorage : public MapStorageBase<typename _GR::Edge> { |
107 public: |
107 public: |
108 typedef _Map Map; |
108 typedef _Map Map; |
109 typedef _Converter Converter; |
109 typedef _Converter Converter; |
110 typedef _Graph Graph; |
110 typedef _GR GR; |
111 typedef typename Graph::Edge Item; |
111 typedef typename GR::Edge Item; |
112 static const bool dir = _dir; |
112 static const bool dir = _dir; |
113 |
113 |
114 private: |
114 private: |
115 const Graph& _graph; |
115 const GR& _graph; |
116 Map& _map; |
116 Map& _map; |
117 Converter _converter; |
117 Converter _converter; |
118 |
118 |
119 public: |
119 public: |
120 GraphArcMapStorage(const Graph& graph, Map& map, |
120 GraphArcMapStorage(const GR& graph, Map& map, |
121 const Converter& converter = Converter()) |
121 const Converter& converter = Converter()) |
122 : _graph(graph), _map(map), _converter(converter) {} |
122 : _graph(graph), _map(map), _converter(converter) {} |
123 virtual ~GraphArcMapStorage() {} |
123 virtual ~GraphArcMapStorage() {} |
124 |
124 |
125 virtual void set(const Item& item ,const std::string& value) { |
125 virtual void set(const Item& item ,const std::string& value) { |
171 } |
171 } |
172 return it->second; |
172 return it->second; |
173 } |
173 } |
174 }; |
174 }; |
175 |
175 |
176 template <typename Graph> |
176 template <typename GR> |
177 struct GraphArcLookUpConverter { |
177 struct GraphArcLookUpConverter { |
178 const Graph& _graph; |
178 const GR& _graph; |
179 const std::map<std::string, typename Graph::Edge>& _map; |
179 const std::map<std::string, typename GR::Edge>& _map; |
180 |
180 |
181 GraphArcLookUpConverter(const Graph& graph, |
181 GraphArcLookUpConverter(const GR& graph, |
182 const std::map<std::string, |
182 const std::map<std::string, |
183 typename Graph::Edge>& map) |
183 typename GR::Edge>& map) |
184 : _graph(graph), _map(map) {} |
184 : _graph(graph), _map(map) {} |
185 |
185 |
186 typename Graph::Arc operator()(const std::string& str) { |
186 typename GR::Arc operator()(const std::string& str) { |
187 if (str.empty() || (str[0] != '+' && str[0] != '-')) { |
187 if (str.empty() || (str[0] != '+' && str[0] != '-')) { |
188 throw FormatError("Item must start with '+' or '-'"); |
188 throw FormatError("Item must start with '+' or '-'"); |
189 } |
189 } |
190 typename std::map<std::string, typename Graph::Edge> |
190 typename std::map<std::string, typename GR::Edge> |
191 ::const_iterator it = _map.find(str.substr(1)); |
191 ::const_iterator it = _map.find(str.substr(1)); |
192 if (it == _map.end()) { |
192 if (it == _map.end()) { |
193 throw FormatError("Item not found"); |
193 throw FormatError("Item not found"); |
194 } |
194 } |
195 return _graph.direct(it->second, str[0] == '+'); |
195 return _graph.direct(it->second, str[0] == '+'); |
385 } |
385 } |
386 }; |
386 }; |
387 |
387 |
388 } |
388 } |
389 |
389 |
390 template <typename Digraph> |
390 template <typename DGR> |
391 class DigraphReader; |
391 class DigraphReader; |
392 |
392 |
393 template <typename Digraph> |
393 template <typename TDGR> |
394 DigraphReader<Digraph> digraphReader(Digraph& digraph, |
394 DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is = std::cin); |
395 std::istream& is = std::cin); |
395 template <typename TDGR> |
396 template <typename Digraph> |
396 DigraphReader<TDGR> digraphReader(TDGR& digraph, const std::string& fn); |
397 DigraphReader<Digraph> digraphReader(Digraph& digraph, const std::string& fn); |
397 template <typename TDGR> |
398 template <typename Digraph> |
398 DigraphReader<TDGR> digraphReader(TDGR& digraph, const char *fn); |
399 DigraphReader<Digraph> digraphReader(Digraph& digraph, const char *fn); |
|
400 |
399 |
401 /// \ingroup lemon_io |
400 /// \ingroup lemon_io |
402 /// |
401 /// |
403 /// \brief \ref lgf-format "LGF" reader for directed graphs |
402 /// \brief \ref lgf-format "LGF" reader for directed graphs |
404 /// |
403 /// |
417 /// multiple map objects at the same time. The \c attribute(), \c |
416 /// multiple map objects at the same time. The \c attribute(), \c |
418 /// node() and \c arc() functions are used to add attribute reading |
417 /// node() and \c arc() functions are used to add attribute reading |
419 /// rules. |
418 /// rules. |
420 /// |
419 /// |
421 ///\code |
420 ///\code |
422 /// DigraphReader<Digraph>(digraph, std::cin). |
421 /// DigraphReader<DGR>(digraph, std::cin). |
423 /// nodeMap("coordinates", coord_map). |
422 /// nodeMap("coordinates", coord_map). |
424 /// arcMap("capacity", cap_map). |
423 /// arcMap("capacity", cap_map). |
425 /// node("source", src). |
424 /// node("source", src). |
426 /// node("target", trg). |
425 /// node("target", trg). |
427 /// attribute("caption", caption). |
426 /// attribute("caption", caption). |
446 /// useNodes() functions. Another application of multipass reading when |
445 /// useNodes() functions. Another application of multipass reading when |
447 /// paths are given as a node map or an arc map. |
446 /// paths are given as a node map or an arc map. |
448 /// It is impossible to read this in |
447 /// It is impossible to read this in |
449 /// a single pass, because the arcs are not constructed when the node |
448 /// a single pass, because the arcs are not constructed when the node |
450 /// maps are read. |
449 /// maps are read. |
451 template <typename GR> |
450 template <typename DGR> |
452 class DigraphReader { |
451 class DigraphReader { |
453 public: |
452 public: |
454 |
453 |
455 typedef GR Digraph; |
454 typedef DGR Digraph; |
456 |
455 |
457 private: |
456 private: |
458 |
457 |
459 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
458 TEMPLATE_DIGRAPH_TYPEDEFS(DGR); |
460 |
459 |
461 std::istream* _is; |
460 std::istream* _is; |
462 bool local_is; |
461 bool local_is; |
463 std::string _filename; |
462 std::string _filename; |
464 |
463 |
465 Digraph& _digraph; |
464 DGR& _digraph; |
466 |
465 |
467 std::string _nodes_caption; |
466 std::string _nodes_caption; |
468 std::string _arcs_caption; |
467 std::string _arcs_caption; |
469 std::string _attributes_caption; |
468 std::string _attributes_caption; |
470 |
469 |
498 |
497 |
499 /// \brief Constructor |
498 /// \brief Constructor |
500 /// |
499 /// |
501 /// Construct a directed graph reader, which reads from the given |
500 /// Construct a directed graph reader, which reads from the given |
502 /// input stream. |
501 /// input stream. |
503 DigraphReader(Digraph& digraph, std::istream& is = std::cin) |
502 DigraphReader(DGR& digraph, std::istream& is = std::cin) |
504 : _is(&is), local_is(false), _digraph(digraph), |
503 : _is(&is), local_is(false), _digraph(digraph), |
505 _use_nodes(false), _use_arcs(false), |
504 _use_nodes(false), _use_arcs(false), |
506 _skip_nodes(false), _skip_arcs(false) {} |
505 _skip_nodes(false), _skip_arcs(false) {} |
507 |
506 |
508 /// \brief Constructor |
507 /// \brief Constructor |
509 /// |
508 /// |
510 /// Construct a directed graph reader, which reads from the given |
509 /// Construct a directed graph reader, which reads from the given |
511 /// file. |
510 /// file. |
512 DigraphReader(Digraph& digraph, const std::string& fn) |
511 DigraphReader(DGR& digraph, const std::string& fn) |
513 : _is(new std::ifstream(fn.c_str())), local_is(true), |
512 : _is(new std::ifstream(fn.c_str())), local_is(true), |
514 _filename(fn), _digraph(digraph), |
513 _filename(fn), _digraph(digraph), |
515 _use_nodes(false), _use_arcs(false), |
514 _use_nodes(false), _use_arcs(false), |
516 _skip_nodes(false), _skip_arcs(false) { |
515 _skip_nodes(false), _skip_arcs(false) { |
517 if (!(*_is)) { |
516 if (!(*_is)) { |
522 |
521 |
523 /// \brief Constructor |
522 /// \brief Constructor |
524 /// |
523 /// |
525 /// Construct a directed graph reader, which reads from the given |
524 /// Construct a directed graph reader, which reads from the given |
526 /// file. |
525 /// file. |
527 DigraphReader(Digraph& digraph, const char* fn) |
526 DigraphReader(DGR& digraph, const char* fn) |
528 : _is(new std::ifstream(fn)), local_is(true), |
527 : _is(new std::ifstream(fn)), local_is(true), |
529 _filename(fn), _digraph(digraph), |
528 _filename(fn), _digraph(digraph), |
530 _use_nodes(false), _use_arcs(false), |
529 _use_nodes(false), _use_arcs(false), |
531 _skip_nodes(false), _skip_arcs(false) { |
530 _skip_nodes(false), _skip_arcs(false) { |
532 if (!(*_is)) { |
531 if (!(*_is)) { |
558 |
557 |
559 } |
558 } |
560 |
559 |
561 private: |
560 private: |
562 |
561 |
563 template <typename DGR> |
562 template <typename TDGR> |
564 friend DigraphReader<DGR> digraphReader(DGR& digraph, std::istream& is); |
563 friend DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is); |
565 template <typename DGR> |
564 template <typename TDGR> |
566 friend DigraphReader<DGR> digraphReader(DGR& digraph, |
565 friend DigraphReader<TDGR> digraphReader(TDGR& digraph, |
567 const std::string& fn); |
566 const std::string& fn); |
568 template <typename DGR> |
567 template <typename TDGR> |
569 friend DigraphReader<DGR> digraphReader(DGR& digraph, const char *fn); |
568 friend DigraphReader<TDGR> digraphReader(TDGR& digraph, const char *fn); |
570 |
569 |
571 DigraphReader(DigraphReader& other) |
570 DigraphReader(DigraphReader& other) |
572 : _is(other._is), local_is(other.local_is), _digraph(other._digraph), |
571 : _is(other._is), local_is(other.local_is), _digraph(other._digraph), |
573 _use_nodes(other._use_nodes), _use_arcs(other._use_arcs), |
572 _use_nodes(other._use_nodes), _use_arcs(other._use_arcs), |
574 _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) { |
573 _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) { |
1186 } |
1185 } |
1187 |
1186 |
1188 /// @} |
1187 /// @} |
1189 |
1188 |
1190 }; |
1189 }; |
|
1190 |
|
1191 /// \ingroup lemon_io |
|
1192 /// |
|
1193 /// \brief Return a \ref DigraphReader class |
|
1194 /// |
|
1195 /// This function just returns a \ref DigraphReader class. |
|
1196 /// |
|
1197 /// With this function a digraph can be read from an |
|
1198 /// \ref lgf-format "LGF" file or input stream with several maps and |
|
1199 /// attributes. For example, there is network flow problem on a |
|
1200 /// digraph, i.e. a digraph with a \e capacity map on the arcs and |
|
1201 /// \e source and \e target nodes. This digraph can be read with the |
|
1202 /// following code: |
|
1203 /// |
|
1204 ///\code |
|
1205 ///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 ///\endcode |
|
1214 /// |
|
1215 /// For a complete documentation, please see the \ref DigraphReader |
|
1216 /// class documentation. |
|
1217 /// \warning Don't forget to put the \ref DigraphReader::run() "run()" |
|
1218 /// to the end of the parameter list. |
|
1219 /// \relates DigraphReader |
|
1220 /// \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 } |
1191 |
1227 |
1192 /// \brief Return a \ref DigraphReader class |
1228 /// \brief Return a \ref DigraphReader class |
1193 /// |
1229 /// |
1194 /// This function just returns a \ref DigraphReader class. |
1230 /// This function just returns a \ref DigraphReader class. |
1195 /// \relates DigraphReader |
1231 /// \relates DigraphReader |
1196 template <typename Digraph> |
1232 /// \sa digraphReader(TDGR& digraph, std::istream& is) |
1197 DigraphReader<Digraph> digraphReader(Digraph& digraph, std::istream& is) { |
1233 template <typename TDGR> |
1198 DigraphReader<Digraph> tmp(digraph, is); |
1234 DigraphReader<TDGR> digraphReader(TDGR& digraph, const std::string& fn) { |
|
1235 DigraphReader<TDGR> tmp(digraph, fn); |
1199 return tmp; |
1236 return tmp; |
1200 } |
1237 } |
1201 |
1238 |
1202 /// \brief Return a \ref DigraphReader class |
1239 /// \brief Return a \ref DigraphReader class |
1203 /// |
1240 /// |
1204 /// This function just returns a \ref DigraphReader class. |
1241 /// This function just returns a \ref DigraphReader class. |
1205 /// \relates DigraphReader |
1242 /// \relates DigraphReader |
1206 template <typename Digraph> |
1243 /// \sa digraphReader(TDGR& digraph, std::istream& is) |
1207 DigraphReader<Digraph> digraphReader(Digraph& digraph, |
1244 template <typename TDGR> |
1208 const std::string& fn) { |
1245 DigraphReader<TDGR> digraphReader(TDGR& digraph, const char* fn) { |
1209 DigraphReader<Digraph> tmp(digraph, fn); |
1246 DigraphReader<TDGR> tmp(digraph, fn); |
1210 return tmp; |
1247 return tmp; |
1211 } |
1248 } |
1212 |
1249 |
1213 /// \brief Return a \ref DigraphReader class |
1250 template <typename GR> |
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> |
|
1224 class GraphReader; |
1251 class GraphReader; |
1225 |
1252 |
1226 template <typename Graph> |
1253 template <typename TGR> |
1227 GraphReader<Graph> graphReader(Graph& graph, |
1254 GraphReader<TGR> graphReader(TGR& graph, std::istream& is = std::cin); |
1228 std::istream& is = std::cin); |
1255 template <typename TGR> |
1229 template <typename Graph> |
1256 GraphReader<TGR> graphReader(TGR& graph, const std::string& fn); |
1230 GraphReader<Graph> graphReader(Graph& graph, const std::string& fn); |
1257 template <typename TGR> |
1231 template <typename Graph> |
1258 GraphReader<TGR> graphReader(TGR& graph, const char *fn); |
1232 GraphReader<Graph> graphReader(Graph& graph, const char *fn); |
|
1233 |
1259 |
1234 /// \ingroup lemon_io |
1260 /// \ingroup lemon_io |
1235 /// |
1261 /// |
1236 /// \brief \ref lgf-format "LGF" reader for undirected graphs |
1262 /// \brief \ref lgf-format "LGF" reader for undirected graphs |
1237 /// |
1263 /// |
1296 |
1322 |
1297 /// \brief Constructor |
1323 /// \brief Constructor |
1298 /// |
1324 /// |
1299 /// Construct an undirected graph reader, which reads from the given |
1325 /// Construct an undirected graph reader, which reads from the given |
1300 /// input stream. |
1326 /// input stream. |
1301 GraphReader(Graph& graph, std::istream& is = std::cin) |
1327 GraphReader(GR& graph, std::istream& is = std::cin) |
1302 : _is(&is), local_is(false), _graph(graph), |
1328 : _is(&is), local_is(false), _graph(graph), |
1303 _use_nodes(false), _use_edges(false), |
1329 _use_nodes(false), _use_edges(false), |
1304 _skip_nodes(false), _skip_edges(false) {} |
1330 _skip_nodes(false), _skip_edges(false) {} |
1305 |
1331 |
1306 /// \brief Constructor |
1332 /// \brief Constructor |
1307 /// |
1333 /// |
1308 /// Construct an undirected graph reader, which reads from the given |
1334 /// Construct an undirected graph reader, which reads from the given |
1309 /// file. |
1335 /// file. |
1310 GraphReader(Graph& graph, const std::string& fn) |
1336 GraphReader(GR& graph, const std::string& fn) |
1311 : _is(new std::ifstream(fn.c_str())), local_is(true), |
1337 : _is(new std::ifstream(fn.c_str())), local_is(true), |
1312 _filename(fn), _graph(graph), |
1338 _filename(fn), _graph(graph), |
1313 _use_nodes(false), _use_edges(false), |
1339 _use_nodes(false), _use_edges(false), |
1314 _skip_nodes(false), _skip_edges(false) { |
1340 _skip_nodes(false), _skip_edges(false) { |
1315 if (!(*_is)) { |
1341 if (!(*_is)) { |
1320 |
1346 |
1321 /// \brief Constructor |
1347 /// \brief Constructor |
1322 /// |
1348 /// |
1323 /// Construct an undirected graph reader, which reads from the given |
1349 /// Construct an undirected graph reader, which reads from the given |
1324 /// file. |
1350 /// file. |
1325 GraphReader(Graph& graph, const char* fn) |
1351 GraphReader(GR& graph, const char* fn) |
1326 : _is(new std::ifstream(fn)), local_is(true), |
1352 : _is(new std::ifstream(fn)), local_is(true), |
1327 _filename(fn), _graph(graph), |
1353 _filename(fn), _graph(graph), |
1328 _use_nodes(false), _use_edges(false), |
1354 _use_nodes(false), _use_edges(false), |
1329 _skip_nodes(false), _skip_edges(false) { |
1355 _skip_nodes(false), _skip_edges(false) { |
1330 if (!(*_is)) { |
1356 if (!(*_is)) { |
1355 } |
1381 } |
1356 |
1382 |
1357 } |
1383 } |
1358 |
1384 |
1359 private: |
1385 private: |
1360 template <typename Graph> |
1386 template <typename TGR> |
1361 friend GraphReader<Graph> graphReader(Graph& graph, std::istream& is); |
1387 friend GraphReader<TGR> graphReader(TGR& graph, std::istream& is); |
1362 template <typename Graph> |
1388 template <typename TGR> |
1363 friend GraphReader<Graph> graphReader(Graph& graph, const std::string& fn); |
1389 friend GraphReader<TGR> graphReader(TGR& graph, const std::string& fn); |
1364 template <typename Graph> |
1390 template <typename TGR> |
1365 friend GraphReader<Graph> graphReader(Graph& graph, const char *fn); |
1391 friend GraphReader<TGR> graphReader(TGR& graph, const char *fn); |
1366 |
1392 |
1367 GraphReader(GraphReader& other) |
1393 GraphReader(GraphReader& other) |
1368 : _is(other._is), local_is(other.local_is), _graph(other._graph), |
1394 : _is(other._is), local_is(other.local_is), _graph(other._graph), |
1369 _use_nodes(other._use_nodes), _use_edges(other._use_edges), |
1395 _use_nodes(other._use_nodes), _use_edges(other._use_edges), |
1370 _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { |
1396 _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { |
1452 checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>(); |
1478 checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>(); |
1453 _reader_bits::MapStorageBase<Edge>* forward_storage = |
1479 _reader_bits::MapStorageBase<Edge>* forward_storage = |
1454 new _reader_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map); |
1480 new _reader_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map); |
1455 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); |
1481 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); |
1456 _reader_bits::MapStorageBase<Edge>* backward_storage = |
1482 _reader_bits::MapStorageBase<Edge>* backward_storage = |
1457 new _reader_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map); |
1483 new _reader_bits::GraphArcMapStorage<GR, false, Map>(_graph, map); |
1458 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); |
1484 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); |
1459 return *this; |
1485 return *this; |
1460 } |
1486 } |
1461 |
1487 |
1462 /// \brief Arc map reading rule |
1488 /// \brief Arc map reading rule |
1466 template <typename Map, typename Converter> |
1492 template <typename Map, typename Converter> |
1467 GraphReader& arcMap(const std::string& caption, Map& map, |
1493 GraphReader& arcMap(const std::string& caption, Map& map, |
1468 const Converter& converter = Converter()) { |
1494 const Converter& converter = Converter()) { |
1469 checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>(); |
1495 checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>(); |
1470 _reader_bits::MapStorageBase<Edge>* forward_storage = |
1496 _reader_bits::MapStorageBase<Edge>* forward_storage = |
1471 new _reader_bits::GraphArcMapStorage<Graph, true, Map, Converter> |
1497 new _reader_bits::GraphArcMapStorage<GR, true, Map, Converter> |
1472 (_graph, map, converter); |
1498 (_graph, map, converter); |
1473 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); |
1499 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); |
1474 _reader_bits::MapStorageBase<Edge>* backward_storage = |
1500 _reader_bits::MapStorageBase<Edge>* backward_storage = |
1475 new _reader_bits::GraphArcMapStorage<Graph, false, Map, Converter> |
1501 new _reader_bits::GraphArcMapStorage<GR, false, Map, Converter> |
1476 (_graph, map, converter); |
1502 (_graph, map, converter); |
1477 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); |
1503 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); |
1478 return *this; |
1504 return *this; |
1479 } |
1505 } |
1480 |
1506 |
1528 |
1554 |
1529 /// \brief Arc reading rule |
1555 /// \brief Arc reading rule |
1530 /// |
1556 /// |
1531 /// Add an arc reading rule to reader. |
1557 /// Add an arc reading rule to reader. |
1532 GraphReader& arc(const std::string& caption, Arc& arc) { |
1558 GraphReader& arc(const std::string& caption, Arc& arc) { |
1533 typedef _reader_bits::GraphArcLookUpConverter<Graph> Converter; |
1559 typedef _reader_bits::GraphArcLookUpConverter<GR> Converter; |
1534 Converter converter(_graph, _edge_index); |
1560 Converter converter(_graph, _edge_index); |
1535 _reader_bits::ValueStorageBase* storage = |
1561 _reader_bits::ValueStorageBase* storage = |
1536 new _reader_bits::ValueStorage<Arc, Converter>(arc, converter); |
1562 new _reader_bits::ValueStorage<Arc, Converter>(arc, converter); |
1537 _attributes.insert(std::make_pair(caption, storage)); |
1563 _attributes.insert(std::make_pair(caption, storage)); |
1538 return *this; |
1564 return *this; |
2031 |
2057 |
2032 /// @} |
2058 /// @} |
2033 |
2059 |
2034 }; |
2060 }; |
2035 |
2061 |
|
2062 /// \ingroup lemon_io |
|
2063 /// |
|
2064 /// \brief Return a \ref GraphReader class |
|
2065 /// |
|
2066 /// This function just returns a \ref GraphReader class. |
|
2067 /// |
|
2068 /// With this function a graph can be read from an |
|
2069 /// \ref lgf-format "LGF" file or input stream with several maps and |
|
2070 /// attributes. For example, there is weighted matching problem on a |
|
2071 /// graph, i.e. a graph with a \e weight map on the edges. This |
|
2072 /// graph can be read with the following code: |
|
2073 /// |
|
2074 ///\code |
|
2075 ///ListGraph graph; |
|
2076 ///ListGraph::EdgeMap<int> weight(graph); |
|
2077 ///graphReader(graph, std::cin). |
|
2078 /// edgeMap("weight", weight). |
|
2079 /// run(); |
|
2080 ///\endcode |
|
2081 /// |
|
2082 /// For a complete documentation, please see the \ref GraphReader |
|
2083 /// class documentation. |
|
2084 /// \warning Don't forget to put the \ref GraphReader::run() "run()" |
|
2085 /// to the end of the parameter list. |
|
2086 /// \relates GraphReader |
|
2087 /// \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 |
2036 /// \brief Return a \ref GraphReader class |
2095 /// \brief Return a \ref GraphReader class |
2037 /// |
2096 /// |
2038 /// This function just returns a \ref GraphReader class. |
2097 /// This function just returns a \ref GraphReader class. |
2039 /// \relates GraphReader |
2098 /// \relates GraphReader |
2040 template <typename Graph> |
2099 /// \sa graphReader(TGR& graph, std::istream& is) |
2041 GraphReader<Graph> graphReader(Graph& graph, std::istream& is) { |
2100 template <typename TGR> |
2042 GraphReader<Graph> tmp(graph, is); |
2101 GraphReader<TGR> graphReader(TGR& graph, const std::string& fn) { |
|
2102 GraphReader<TGR> tmp(graph, fn); |
2043 return tmp; |
2103 return tmp; |
2044 } |
2104 } |
2045 |
2105 |
2046 /// \brief Return a \ref GraphReader class |
2106 /// \brief Return a \ref GraphReader class |
2047 /// |
2107 /// |
2048 /// This function just returns a \ref GraphReader class. |
2108 /// This function just returns a \ref GraphReader class. |
2049 /// \relates GraphReader |
2109 /// \relates GraphReader |
2050 template <typename Graph> |
2110 /// \sa graphReader(TGR& graph, std::istream& is) |
2051 GraphReader<Graph> graphReader(Graph& graph, const std::string& fn) { |
2111 template <typename TGR> |
2052 GraphReader<Graph> tmp(graph, fn); |
2112 GraphReader<TGR> graphReader(TGR& graph, const char* fn) { |
2053 return tmp; |
2113 GraphReader<TGR> tmp(graph, fn); |
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); |
|
2063 return tmp; |
2114 return tmp; |
2064 } |
2115 } |
2065 |
2116 |
2066 class SectionReader; |
2117 class SectionReader; |
2067 |
2118 |
2314 |
2365 |
2315 /// @} |
2366 /// @} |
2316 |
2367 |
2317 }; |
2368 }; |
2318 |
2369 |
|
2370 /// \ingroup lemon_io |
|
2371 /// |
2319 /// \brief Return a \ref SectionReader class |
2372 /// \brief Return a \ref SectionReader class |
2320 /// |
2373 /// |
2321 /// This function just returns a \ref SectionReader class. |
2374 /// This function just returns a \ref SectionReader class. |
|
2375 /// |
|
2376 /// Please see SectionReader documentation about the custom section |
|
2377 /// input. |
|
2378 /// |
2322 /// \relates SectionReader |
2379 /// \relates SectionReader |
|
2380 /// \sa sectionReader(const std::string& fn) |
|
2381 /// \sa sectionReader(const char *fn) |
2323 inline SectionReader sectionReader(std::istream& is) { |
2382 inline SectionReader sectionReader(std::istream& is) { |
2324 SectionReader tmp(is); |
2383 SectionReader tmp(is); |
2325 return tmp; |
2384 return tmp; |
2326 } |
2385 } |
2327 |
2386 |
2328 /// \brief Return a \ref SectionReader class |
2387 /// \brief Return a \ref SectionReader class |
2329 /// |
2388 /// |
2330 /// This function just returns a \ref SectionReader class. |
2389 /// This function just returns a \ref SectionReader class. |
2331 /// \relates SectionReader |
2390 /// \relates SectionReader |
|
2391 /// \sa sectionReader(std::istream& is) |
2332 inline SectionReader sectionReader(const std::string& fn) { |
2392 inline SectionReader sectionReader(const std::string& fn) { |
2333 SectionReader tmp(fn); |
2393 SectionReader tmp(fn); |
2334 return tmp; |
2394 return tmp; |
2335 } |
2395 } |
2336 |
2396 |
2337 /// \brief Return a \ref SectionReader class |
2397 /// \brief Return a \ref SectionReader class |
2338 /// |
2398 /// |
2339 /// This function just returns a \ref SectionReader class. |
2399 /// This function just returns a \ref SectionReader class. |
2340 /// \relates SectionReader |
2400 /// \relates SectionReader |
|
2401 /// \sa sectionReader(std::istream& is) |
2341 inline SectionReader sectionReader(const char* fn) { |
2402 inline SectionReader sectionReader(const char* fn) { |
2342 SectionReader tmp(fn); |
2403 SectionReader tmp(fn); |
2343 return tmp; |
2404 return tmp; |
2344 } |
2405 } |
2345 |
2406 |