Changeset 1429:4283998fb2be in lemon-0.x for src/lemon/lemon_writer.h
- Timestamp:
- 05/19/05 13:49:42 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1903
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/lemon/lemon_writer.h
r1421 r1429 244 244 245 245 virtual void write(std::ostream& os, const Item& item) const { 246 returnidWriter.writeId(os, item);246 idWriter.writeId(os, item); 247 247 } 248 248 }; … … 274 274 typedef _Graph Graph; 275 275 typedef _Traits Traits; 276 typedef typename Graph::Node Item;276 typedef typename Graph::Node Node; 277 277 278 278 /// \brief Constructor. … … 320 320 const Writer& writer = Writer()) { 321 321 writers.push_back( 322 make_pair(name, new MapWriter< Item, Map, Writer>(map, writer)));322 make_pair(name, new MapWriter<Node, Map, Writer>(map, writer))); 323 323 return *this; 324 324 } … … 380 380 /// Otherwise if the \c forceId parameter was true it will write 381 381 /// its id in the graph. 382 void writeId(std::ostream& os, const Item& item) const {382 void writeId(std::ostream& os, const Node& item) const { 383 383 if (forceIdMap) { 384 384 os << graph.id(item); … … 390 390 private: 391 391 392 typedef std::vector<std::pair<std::string, WriterBase< Item>*> > MapWriters;392 typedef std::vector<std::pair<std::string, WriterBase<Node>*> > MapWriters; 393 393 MapWriters writers; 394 394 395 WriterBase< Item>* idMap;395 WriterBase<Node>* idMap; 396 396 bool forceIdMap; 397 397 … … 431 431 typedef _Graph Graph; 432 432 typedef _Traits Traits; 433 typedef typename Graph::Edge Item; 433 typedef typename Graph::Node Node; 434 typedef typename Graph::Edge Edge; 434 435 435 436 /// \brief Constructor. … … 447 448 : Parent(_writer), idMap(0), forceIdMap(_forceIdMap), 448 449 graph(_graph), id(_id), 449 nodeIdWriter(new IdWriter<typename Graph::Node, NodeIdWriter> 450 (_nodeIdWriter)) {} 450 nodeIdWriter(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter)) {} 451 451 452 452 /// \brief Destructor. … … 482 482 const Writer& writer = Writer()) { 483 483 writers.push_back( 484 make_pair(name, new MapWriter< Item, Map, Writer>(map, writer)));484 make_pair(name, new MapWriter<Edge, Map, Writer>(map, writer))); 485 485 return *this; 486 486 } … … 547 547 /// Otherwise if the \c forceId parameter was true it will write 548 548 /// its id in the graph. 549 void writeId(std::ostream& os, const Item& item) const {549 void writeId(std::ostream& os, const Edge& item) const { 550 550 if (forceIdMap) { 551 551 os << graph.id(item); … … 557 557 private: 558 558 559 typedef std::vector<std::pair<std::string, WriterBase< Item>*> > MapWriters;559 typedef std::vector<std::pair<std::string, WriterBase<Edge>*> > MapWriters; 560 560 MapWriters writers; 561 561 562 WriterBase< Item>* idMap;562 WriterBase<Edge>* idMap; 563 563 bool forceIdMap; 564 564 … … 566 566 std::string id; 567 567 568 std::auto_ptr<IdWriterBase< typename Graph::Node> > nodeIdWriter;568 std::auto_ptr<IdWriterBase<Node> > nodeIdWriter; 569 569 }; 570 570 … … 605 605 typedef _Graph Graph; 606 606 typedef _Traits Traits; 607 typedef typename Graph::UndirEdge Item; 607 typedef typename Graph::Node Node; 608 typedef typename Graph::Edge Edge; 609 typedef typename Graph::UndirEdge UndirEdge; 608 610 609 611 /// \brief Constructor. … … 621 623 : Parent(_writer), idMap(0), forceIdMap(_forceIdMap), 622 624 graph(_graph), id(_id), 623 nodeIdWriter(new IdWriter<typename Graph::Node, NodeIdWriter> 624 (_nodeIdWriter)) {} 625 nodeIdWriter(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter)) {} 625 626 626 627 /// \brief Destructor. … … 656 657 const Writer& writer = Writer()) { 657 658 writers.push_back( 658 make_pair(name, new MapWriter< Item, Map, Writer>(map, writer)));659 make_pair(name, new MapWriter<UndirEdge, Map, Writer>(map, writer))); 659 660 return *this; 660 661 } … … 743 744 /// undirected edge. Otherwise if the \c forceId parameter was true it 744 745 /// will write its id in the graph. 745 void writeId(std::ostream& os, const Item& item) const {746 void writeId(std::ostream& os, const UndirEdge& item) const { 746 747 if (forceIdMap) { 747 748 os << graph.id(item); … … 751 752 } 752 753 753 private: 754 755 typedef std::vector<std::pair<std::string, WriterBase<Item>*> > MapWriters; 754 /// \brief Write the id of the given edge. 755 /// 756 /// It writes the id of the given edge. If there was written 757 /// an "id" named map then it will write the map value belongs to the 758 /// edge. Otherwise if the \c forceId parameter was true it 759 /// will write its id in the graph. If the edge is forward map 760 /// then its prefix character is \c '+' elsewhere \c '-'. 761 void writeId(std::ostream& os, const Edge& item) const { 762 if (graph.forward(item)) { 763 os << "+ "; 764 } else { 765 os << "- "; 766 } 767 if (forceIdMap) { 768 os << graph.id(item); 769 } else { 770 idMap->write(os, item); 771 } 772 } 773 774 private: 775 776 typedef std::vector<std::pair<std::string, 777 WriterBase<UndirEdge>*> > MapWriters; 756 778 MapWriters writers; 757 779 758 WriterBase< Item>* idMap;780 WriterBase<UndirEdge>* idMap; 759 781 bool forceIdMap; 760 782 … … 762 784 std::string id; 763 785 764 std::auto_ptr<IdWriterBase< typename Graph::Node> > nodeIdWriter;786 std::auto_ptr<IdWriterBase<Node> > nodeIdWriter; 765 787 }; 766 788 … … 779 801 typedef CommonSectionWriterBase Parent; 780 802 typedef _Graph Graph; 781 typedef typename Graph::Node Item;803 typedef typename Graph::Node Node; 782 804 public: 783 805 … … 807 829 /// 808 830 /// Add a node writer command for the NodeWriter. 809 void writeNode(const std::string& name, const Item& item) {831 void writeNode(const std::string& name, const Node& item) { 810 832 writers.push_back(make_pair(name, &item)); 811 833 } … … 836 858 std::string id; 837 859 838 typedef std::vector<std::pair<std::string, const Item*> > ItemWriters;839 ItemWriters writers;840 std::auto_ptr<IdWriterBase< Item> > idWriter;860 typedef std::vector<std::pair<std::string, const Node*> > NodeWriters; 861 NodeWriters writers; 862 std::auto_ptr<IdWriterBase<Node> > idWriter; 841 863 }; 842 864 … … 855 877 typedef CommonSectionWriterBase Parent; 856 878 typedef _Graph Graph; 857 typedef typename Graph::Edge Item;879 typedef typename Graph::Edge Edge; 858 880 public: 859 881 … … 882 904 /// 883 905 /// Add an edge writer command for the EdgeWriter. 884 void writeEdge(const std::string& name, const Item& item) {906 void writeEdge(const std::string& name, const Edge& item) { 885 907 writers.push_back(make_pair(name, &item)); 886 908 } … … 911 933 std::string id; 912 934 913 typedef std::vector<std::pair<std::string, const Item*> > ItemWriters;914 ItemWriters writers;915 916 std::auto_ptr<IdWriterBase< Item> > idWriter;935 typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters; 936 EdgeWriters writers; 937 938 std::auto_ptr<IdWriterBase<Edge> > idWriter; 917 939 }; 918 940 … … 931 953 typedef CommonSectionWriterBase Parent; 932 954 typedef _Graph Graph; 933 typedef typename Graph::UndirEdge Item; 955 typedef typename Graph::Node Node; 956 typedef typename Graph::Edge Edge; 957 typedef typename Graph::UndirEdge UndirEdge; 934 958 public: 935 959 … … 944 968 const std::string& _id = std::string()) 945 969 : Parent(_writer), id(_id), 946 idWriter(new IdWriter<typename Graph::UndirEdge, _IdWriter>947 (_idWriter)) {}970 undirEdgeIdWriter(new IdWriter<UndirEdge, _IdWriter>(_idWriter)), 971 edgeIdWriter(new IdWriter<Edge, _IdWriter>(_idWriter)) {} 948 972 949 973 /// \brief Destructor. … … 957 981 public: 958 982 983 /// \brief Add an edge writer command for the UndirEdgeWriter. 984 /// 985 /// Add an edge writer command for the UndirEdgeWriter. 986 void writeEdge(const std::string& name, const Edge& item) { 987 edgeWriters.push_back(make_pair(name, &item)); 988 } 989 959 990 /// \brief Add an undirected edge writer command for the UndirEdgeWriter. 960 991 /// 961 /// Add an edge writer command for the UndirEdgeWriter.962 void writeUndirEdge(const std::string& name, const Item& item) {963 writers.push_back(make_pair(name, &item));992 /// Add an undirected edge writer command for the UndirEdgeWriter. 993 void writeUndirEdge(const std::string& name, const UndirEdge& item) { 994 undirEdgeWriters.push_back(make_pair(name, &item)); 964 995 } 965 996 … … 971 1002 /// and the header line's id and the writer's id are the same. 972 1003 virtual std::string header() { 973 return "@ edges " + id;1004 return "@undiredges " + id; 974 1005 } 975 1006 … … 978 1009 /// Write the content of the section. 979 1010 virtual void write(std::ostream& os) { 980 for (int i = 0; i < (int) writers.size(); ++i) {981 os << writers[i].first << ' ';982 idWriter->write(os, *(writers[i].second));1011 for (int i = 0; i < (int)undirEdgeWriters.size(); ++i) { 1012 os << undirEdgeWriters[i].first << ' '; 1013 undirEdgeIdWriter->write(os, *(undirEdgeWriters[i].second)); 983 1014 os << std::endl; 984 1015 } 1016 for (int i = 0; i < (int)edgeWriters.size(); ++i) { 1017 os << edgeWriters[i].first << ' '; 1018 edgeIdWriter->write(os, *(edgeWriters[i].second)); 1019 os << std::endl; 1020 } 985 1021 } 986 1022 … … 989 1025 std::string id; 990 1026 991 typedef std::vector<std::pair<std::string, const Item*> > ItemWriters; 992 ItemWriters writers; 993 994 std::auto_ptr<IdWriterBase<Item> > idWriter; 1027 typedef std::vector<std::pair<std::string, 1028 const UndirEdge*> > UndirEdgeWriters; 1029 UndirEdgeWriters undirEdgeWriters; 1030 std::auto_ptr<IdWriterBase<UndirEdge> > undirEdgeIdWriter; 1031 1032 typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters; 1033 EdgeWriters edgeWriters; 1034 std::auto_ptr<IdWriterBase<Edge> > edgeIdWriter; 1035 995 1036 }; 996 1037
Note: See TracChangeset
for help on using the changeset viewer.