Changeset 1476:182da222fceb in lemon-0.x
- Timestamp:
- 06/13/05 19:13:56 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1956
- Location:
- lemon
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/graph_reader.h
r1435 r1476 262 262 GraphReader& readEdge(std::string name, Edge& edge) { 263 263 edge_reader.readEdge(name, edge); 264 return *this; 264 265 } 265 266 -
lemon/lemon_reader.h
r1435 r1476 37 37 #include <lemon/bits/item_reader.h> 38 38 39 #include <lemon/concept_check.h> 40 #include <lemon/concept/maps.h> 39 41 40 42 namespace lemon { 41 43 42 44 namespace _reader_bits { 45 46 template <typename Item> 47 class ItemIdReader { 48 public: 49 50 bool isIdReader() { return true; } 51 52 Item readId(std::istream&, Item) { return Item();} 53 54 template <class _ItemIdReader> 55 struct Constraints { 56 void constraints() { 57 bool b = reader.isIdReader(); 58 ignore_unused_variable_warning(b); 59 Item item = reader.readId(is, Item()); 60 } 61 _ItemIdReader& reader; 62 std::istream& is; 63 }; 64 65 }; 43 66 44 67 template <typename T> … … 532 555 typedef _Item Item; 533 556 virtual Item read(std::istream& is) const = 0; 557 virtual bool isIdReader() const = 0; 534 558 }; 535 559 … … 547 571 virtual Item read(std::istream& is) const { 548 572 return boxedIdReader.readId(is, Item()); 573 } 574 575 virtual bool isIdReader() const { 576 return boxedIdReader.isIdReader(); 549 577 } 550 578 }; … … 818 846 const std::string& _id = std::string(), 819 847 const DefaultSkipper& _skipper = DefaultSkipper()) 820 : Parent(_reader), graph(_graph), id(_id), skipper(_skipper), 821 nodeIdReader(new IdReader<Node, NodeIdReader>(_nodeIdReader)) {} 822 848 : Parent(_reader), graph(_graph), id(_id), skipper(_skipper) { 849 checkConcept<_reader_bits::ItemIdReader<Node>, NodeIdReader>(); 850 nodeIdReader.reset(new IdReader<Node, NodeIdReader>(_nodeIdReader)); 851 } 823 852 /// \brief Destructor. 824 853 /// … … 922 951 /// It reads the content of the section. 923 952 virtual void read(std::istream& is) { 953 if (!nodeIdReader->isIdReader()) { 954 throw DataFormatError("Cannot find nodeset or ID map"); 955 } 924 956 std::vector<ReaderBase<Edge>* > index; 925 957 std::string line; … … 1034 1066 const std::string& _id = std::string(), 1035 1067 const DefaultSkipper& _skipper = DefaultSkipper()) 1036 : Parent(_reader), graph(_graph), id(_id), skipper(_skipper), 1037 nodeIdReader(new IdReader<Node, NodeIdReader>(_nodeIdReader)) {} 1038 1068 : Parent(_reader), graph(_graph), id(_id), skipper(_skipper) { 1069 checkConcept<_reader_bits::ItemIdReader<Node>, NodeIdReader>(); 1070 nodeIdReader.reset(new IdReader<Node, NodeIdReader>(_nodeIdReader)); 1071 } 1039 1072 /// \brief Destructor. 1040 1073 /// … … 1198 1231 /// It reads the content of the section. 1199 1232 virtual void read(std::istream& is) { 1233 if (!nodeIdReader->isIdReader()) { 1234 throw DataFormatError("Cannot find nodeset or ID map"); 1235 } 1200 1236 std::vector<ReaderBase<UndirEdge>* > index; 1201 1237 std::string line; … … 1303 1339 NodeReader(LemonReader& _reader, const _IdReader& _idReader, 1304 1340 const std::string& _id = std::string()) 1305 : Parent(_reader), id(_id), 1306 idReader(new IdReader<typename Graph::Node, _IdReader>(_idReader)) {} 1341 : Parent(_reader), id(_id) { 1342 checkConcept<_reader_bits::ItemIdReader<Node>, _IdReader>(); 1343 idReader.reset(new IdReader<Node, _IdReader>(_idReader)); 1344 } 1307 1345 1308 1346 /// \brief Destructor. … … 1348 1386 /// It reads the content of the section. 1349 1387 virtual void read(std::istream& is) { 1388 if (!idReader->isIdReader()) { 1389 throw DataFormatError("Cannot find nodeset or ID map"); 1390 } 1350 1391 std::string line; 1351 1392 while (getline(is, line)) { … … 1395 1436 EdgeReader(LemonReader& _reader, const _IdReader& _idReader, 1396 1437 const std::string& _id = std::string()) 1397 : Parent(_reader), id(_id), 1398 idReader(new IdReader<typename Graph::Edge, _IdReader>(_idReader)) {} 1438 : Parent(_reader), id(_id) { 1439 checkConcept<_reader_bits::ItemIdReader<Edge>, _IdReader>(); 1440 idReader.reset(new IdReader<Edge, _IdReader>(_idReader)); 1441 } 1399 1442 1400 1443 /// \brief Destructor. … … 1439 1482 /// It reads the content of the section. 1440 1483 virtual void read(std::istream& is) { 1484 if (!idReader->isIdReader()) { 1485 throw DataFormatError("Cannot find edgeset or ID map"); 1486 } 1441 1487 std::string line; 1442 1488 while (getline(is, line)) { … … 1488 1534 UndirEdgeReader(LemonReader& _reader, const _IdReader& _idReader, 1489 1535 const std::string& _id = std::string()) 1490 : Parent(_reader), id(_id), 1491 undirEdgeIdReader(new IdReader<UndirEdge, _IdReader>(_idReader)), 1492 edgeIdReader(new IdReader<Edge, _IdReader>(_idReader)) 1493 {} 1536 : Parent(_reader), id(_id) { 1537 checkConcept<_reader_bits::ItemIdReader<UndirEdge>, _IdReader>(); 1538 checkConcept<_reader_bits::ItemIdReader<Edge>, _IdReader>(); 1539 undirEdgeIdReader.reset(new IdReader<UndirEdge, _IdReader>(_idReader)); 1540 egdeIdReader.reset(new IdReader<Edge, _IdReader>(_idReader)); 1541 } 1494 1542 1495 1543 /// \brief Destructor. … … 1546 1594 /// It reads the content of the section. 1547 1595 virtual void read(std::istream& is) { 1596 if (!edgeIdReader->isIdReader()) { 1597 throw DataFormatError("Cannot find undirected edgeset or ID map"); 1598 } 1599 if (!undirEdgeIdReader->isIdReader()) { 1600 throw DataFormatError("Cannot find undirected edgeset or ID map"); 1601 } 1548 1602 std::string line; 1549 1603 while (getline(is, line)) { -
lemon/lemon_writer.h
r1435 r1476 37 37 #include <lemon/maps.h> 38 38 39 #include <lemon/concept_check.h> 40 #include <lemon/concept/maps.h> 41 39 42 40 43 namespace lemon { 44 45 namespace _writer_bits { 46 47 template <typename Item> 48 class ItemIdWriter { 49 public: 50 51 bool isIdWriter() { return true; } 52 53 void writeId(std::ostream&, const Item&) {} 54 55 template <class _ItemIdWriter> 56 struct Constraints { 57 void constraints() { 58 const Item item; 59 bool b = writer.isIdWriter(); 60 ignore_unused_variable_warning(b); 61 writer.writeId(os, item); 62 } 63 _ItemIdWriter& writer; 64 std::ostream& os; 65 }; 66 67 }; 68 69 } 41 70 42 71 /// \ingroup io_group … … 230 259 typedef _Item Item; 231 260 virtual void write(std::ostream&, const Item&) const = 0; 261 virtual bool isIdWriter() const = 0; 232 262 }; 233 263 … … 245 275 virtual void write(std::ostream& os, const Item& item) const { 246 276 idWriter.writeId(os, item); 277 } 278 279 virtual bool isIdWriter() const { 280 return idWriter.isIdWriter(); 247 281 } 248 282 }; … … 319 353 NodeSetWriter& writeNodeMap(std::string name, const Map& map, 320 354 const Writer& writer = Writer()) { 355 checkConcept<concept::WriteMap<Node, typename Map::Value>, Map>(); 321 356 writers.push_back( 322 357 make_pair(name, new MapWriter<Node, Map, Writer>(map, writer))); … … 447 482 bool _forceIdMap = true) 448 483 : Parent(_writer), idMap(0), forceIdMap(_forceIdMap), 449 graph(_graph), id(_id), 450 nodeIdWriter(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter)) {} 484 graph(_graph), id(_id) { 485 checkConcept<_writer_bits::ItemIdWriter<Node>, NodeIdWriter>(); 486 nodeIdWriter.reset(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter)); 487 } 451 488 452 489 /// \brief Destructor. … … 481 518 EdgeSetWriter& writeEdgeMap(std::string name, const Map& map, 482 519 const Writer& writer = Writer()) { 520 checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>(); 483 521 writers.push_back( 484 522 make_pair(name, new MapWriter<Edge, Map, Writer>(map, writer))); … … 499 537 /// Write the content of the section. 500 538 virtual void write(std::ostream& os) { 539 if (!nodeIdWriter->isIdWriter()) { 540 throw DataFormatError("Cannot find nodeset or ID map"); 541 } 501 542 for (int i = 0; i < (int)writers.size(); ++i) { 502 543 if (writers[i].first == "id") { … … 622 663 bool _forceIdMap = true) 623 664 : Parent(_writer), idMap(0), forceIdMap(_forceIdMap), 624 graph(_graph), id(_id), 625 nodeIdWriter(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter)) {} 665 graph(_graph), id(_id) { 666 checkConcept<_writer_bits::ItemIdWriter<Node>, NodeIdWriter>(); 667 nodeIdWriter.reset(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter)); 668 } 626 669 627 670 /// \brief Destructor. … … 656 699 UndirEdgeSetWriter& writeUndirEdgeMap(std::string name, const Map& map, 657 700 const Writer& writer = Writer()) { 701 checkConcept<concept::WriteMap<UndirEdge, typename Map::Value>, Map>(); 658 702 writers.push_back( 659 703 make_pair(name, new MapWriter<UndirEdge, Map, Writer>(map, writer))); … … 666 710 template <typename Map> 667 711 UndirEdgeSetWriter& writeEdgeMap(std::string name, const Map& map) { 712 checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>(); 668 713 writeUndirEdgeMap("+" + name, composeMap(forwardMap(graph), map)); 669 714 writeUndirEdgeMap("-" + name, composeMap(backwardMap(graph), map)); … … 677 722 UndirEdgeSetWriter& writeEdgeMap(std::string name, const Map& map, 678 723 const Writer& writer = Writer()) { 724 checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>(); 679 725 writeUndirEdge("+" + name, composeMap(forwardMap(graph), map), writer); 680 writeUndirEdge("-" + name, composeMap( forwardMap(graph), map), writer);726 writeUndirEdge("-" + name, composeMap(backwardMap(graph), map), writer); 681 727 return *this; 682 728 } … … 695 741 /// Write the content of the section. 696 742 virtual void write(std::ostream& os) { 743 if (!nodeIdWriter->isIdWriter()) { 744 throw DataFormatError("Cannot find nodeset or ID map"); 745 } 697 746 for (int i = 0; i < (int)writers.size(); ++i) { 698 747 if (writers[i].first == "id") { … … 812 861 NodeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, 813 862 const std::string& _id = std::string()) 814 : Parent(_writer), id(_id), 815 idWriter(new IdWriter<typename Graph::Node, _IdWriter>(_idWriter)) {} 863 : Parent(_writer), id(_id) { 864 checkConcept<_writer_bits::ItemIdWriter<Node>, _IdWriter>(); 865 idWriter.reset(new IdWriter<Node, _IdWriter>(_idWriter)); 866 } 867 816 868 817 869 /// \brief Destructor. … … 847 899 /// Write the content of the section. 848 900 virtual void write(std::ostream& os) { 901 if (!idWriter->isIdWriter()) { 902 throw DataFormatError("Cannot find nodeset or ID map"); 903 } 849 904 for (int i = 0; i < (int)writers.size(); ++i) { 850 905 os << writers[i].first << ' '; … … 888 943 EdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, 889 944 const std::string& _id = std::string()) 890 : Parent(_writer), id(_id), 891 idWriter(new IdWriter<typename Graph::Edge, _IdWriter>(_idWriter)) {} 945 : Parent(_writer), id(_id) { 946 checkConcept<_writer_bits::ItemIdWriter<Edge>, _IdWriter>(); 947 idWriter.reset(new IdWriter<Edge, _IdWriter>(_idWriter)); 948 } 892 949 893 950 /// \brief Destructor. … … 922 979 /// Write the content of the section. 923 980 virtual void write(std::ostream& os) { 981 if (!idWriter->isIdWriter()) { 982 throw DataFormatError("Cannot find edgeset or ID map"); 983 } 924 984 for (int i = 0; i < (int)writers.size(); ++i) { 925 985 os << writers[i].first << ' '; … … 967 1027 UndirEdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, 968 1028 const std::string& _id = std::string()) 969 : Parent(_writer), id(_id), 970 undirEdgeIdWriter(new IdWriter<UndirEdge, _IdWriter>(_idWriter)), 971 edgeIdWriter(new IdWriter<Edge, _IdWriter>(_idWriter)) {} 1029 : Parent(_writer), id(_id) { 1030 checkConcept<_writer_bits::ItemIdWriter<Edge>, _IdWriter>(); 1031 checkConcept<_writer_bits::ItemIdWriter<UndirEdge>, _IdWriter>(); 1032 undirEdgeIdWriter.reset(new IdWriter<UndirEdge, _IdWriter>(_idWriter)); 1033 edgeIdWriter.reset(new IdWriter<Edge, _IdWriter>(_idWriter)); 1034 } 972 1035 973 1036 /// \brief Destructor. … … 1009 1072 /// Write the content of the section. 1010 1073 virtual void write(std::ostream& os) { 1074 if (!edgeIdWriter->isIdWriter()) { 1075 throw DataFormatError("Cannot find undirected edgeset or ID map"); 1076 } 1077 if (!undirEdgeIdWriter->isIdWriter()) { 1078 throw DataFormatError("Cannot find undirected edgeset or ID map"); 1079 } 1011 1080 for (int i = 0; i < (int)undirEdgeWriters.size(); ++i) { 1012 1081 os << undirEdgeWriters[i].first << ' ';
Note: See TracChangeset
for help on using the changeset viewer.