Changeset 1901:723b2b81d900 in lemon-0.x for lemon/lemon_writer.h
- Timestamp:
- 01/24/06 17:07:38 (18 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2476
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/lemon_writer.h
r1875 r1901 47 47 48 48 template <typename Item> 49 class Item IdWriter {49 class ItemLabelWriter { 50 50 public: 51 51 52 bool is IdWriter() { return true; }53 54 void write Id(std::ostream&, const Item&) {}52 bool isLabelWriter() { return true; } 53 54 void writeLabel(std::ostream&, const Item&) {} 55 55 56 template <class _Item IdWriter>56 template <class _ItemLabelWriter> 57 57 struct Constraints { 58 58 void constraints() { 59 bool b = writer.is IdWriter();59 bool b = writer.isLabelWriter(); 60 60 ignore_unused_variable_warning(b); 61 writer.write Id(os, item);61 writer.writeLabel(os, item); 62 62 } 63 _Item IdWriter& writer;63 _ItemLabelWriter& writer; 64 64 std::ostream& os; 65 65 const Item& item; … … 226 226 227 227 template <typename _Item> 228 class IdWriterBase {228 class LabelWriterBase { 229 229 public: 230 230 typedef _Item Item; 231 virtual ~ IdWriterBase() {}231 virtual ~LabelWriterBase() {} 232 232 virtual void write(std::ostream&, const Item&) const = 0; 233 virtual bool is IdWriter() const = 0;234 }; 235 236 template <typename _Item, typename _Boxed IdWriter>237 class IdWriter : public IdWriterBase<_Item> {233 virtual bool isLabelWriter() const = 0; 234 }; 235 236 template <typename _Item, typename _BoxedLabelWriter> 237 class LabelWriter : public LabelWriterBase<_Item> { 238 238 public: 239 239 typedef _Item Item; 240 typedef _Boxed IdWriter BoxedIdWriter;241 242 const Boxed IdWriter& idWriter;243 244 IdWriter(const BoxedIdWriter& _idWriter)245 : idWriter(_idWriter) {}240 typedef _BoxedLabelWriter BoxedLabelWriter; 241 242 const BoxedLabelWriter& labelWriter; 243 244 LabelWriter(const BoxedLabelWriter& _labelWriter) 245 : labelWriter(_labelWriter) {} 246 246 247 247 virtual void write(std::ostream& os, const Item& item) const { 248 idWriter.writeId(os, item);249 } 250 251 virtual bool is IdWriter() const {252 return idWriter.isIdWriter();248 labelWriter.writeLabel(os, item); 249 } 250 251 virtual bool isLabelWriter() const { 252 return labelWriter.isLabelWriter(); 253 253 } 254 254 }; … … 375 375 /// 376 376 /// The lemon format can store multiple graph nodesets with several maps. 377 /// The nodeset section's header line is \c \@nodeset \c nodeset_ id, but the378 /// \c nodeset_idmay be empty.377 /// The nodeset section's header line is \c \@nodeset \c nodeset_name, but 378 /// the \c nodeset_name may be empty. 379 379 /// 380 380 /// The first line of the section contains the names of the maps separated … … 382 382 /// contains the mapped values for each map. 383 383 /// 384 /// If the nodeset contains an \c " id" named map then it will be regarded385 /// as idmap. This map should contain only unique values and when the386 /// \c write Id() member will be called with a node it will write it's id.387 /// Otherwise if the \c _forceIdMap constructor parameter is true then388 /// the idmap will be the id in the graph.384 /// If the nodeset contains an \c "label" named map then it will be regarded 385 /// as label map. This map should contain only unique values and when the 386 /// \c writeLabel() member will be called with a node it will write it's 387 /// label. Otherwise if the \c _forceLabelMap constructor parameter is true 388 /// then the label map will be the id in the graph. 389 389 /// 390 390 /// \relates LemonWriter … … 401 401 /// 402 402 /// Constructor for NodeSetWriter. It creates the NodeSetWriter and 403 /// attach it into the given LemonWriter. If the \c _force IdMap404 /// parameter is true then the writer will write own idmap when405 /// the user does not give " id" named map.403 /// attach it into the given LemonWriter. If the \c _forceLabelMap 404 /// parameter is true then the writer will write own label map when 405 /// the user does not give "label" named map. 406 406 NodeSetWriter(LemonWriter& _writer, const Graph& _graph, 407 const std::string& _ id= std::string(),408 bool _force IdMap = true)409 : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),410 graph(_graph), id(_id) {}407 const std::string& _name = std::string(), 408 bool _forceLabelMap = true) 409 : Parent(_writer), labelMap(0), forceLabelMap(_forceLabelMap), 410 graph(_graph), name(_name) {} 411 411 412 412 /// \brief Destructor. … … 455 455 /// It gives back the header of the section. 456 456 virtual std::string header() { 457 return "@nodeset " + id;457 return "@nodeset " + name; 458 458 } 459 459 … … 463 463 virtual void write(std::ostream& os) { 464 464 for (int i = 0; i < (int)writers.size(); ++i) { 465 if (writers[i].first == " id") {466 idMap = writers[i].second;467 force IdMap = false;465 if (writers[i].first == "label" || (writers[i].first == "id" && labelMap == 0)) { 466 labelMap = writers[i].second; 467 forceLabelMap = false; 468 468 break; 469 469 } 470 470 } 471 if (force IdMap) {472 os << " id\t";471 if (forceLabelMap) { 472 os << "label\t"; 473 473 } 474 474 for (int i = 0; i < (int)writers.size(); ++i) { … … 477 477 os << std::endl; 478 478 for (typename Graph::NodeIt it(graph); it != INVALID; ++it) { 479 if (force IdMap) {479 if (forceLabelMap) { 480 480 os << graph.id(it) << '\t'; 481 481 } … … 490 490 public: 491 491 492 /// \brief Returns true if the nodeset can write the ids of the nodes.493 /// 494 /// Returns true if the nodeset can write the ids of the nodes.495 /// It is possible only if an " id" named map was written or the496 /// \c _force IdMap constructor parameter was true.497 bool is IdWriter() const {498 return idMap != 0 || forceIdMap;499 } 500 501 /// \brief Write the idof the given node.502 /// 503 /// It writes the id of the given node. If there was written an "id"492 /// \brief Returns true if the nodeset can write the labels of the nodes. 493 /// 494 /// Returns true if the nodeset can write the labels of the nodes. 495 /// It is possible only if an "label" named map was written or the 496 /// \c _forceLabelMap constructor parameter was true. 497 bool isLabelWriter() const { 498 return labelMap != 0 || forceLabelMap; 499 } 500 501 /// \brief Write the label of the given node. 502 /// 503 /// It writes the label of the given node. If there was written an "label" 504 504 /// named map then it will write the map value belongs to the node. 505 /// Otherwise if the \c force Idparameter was true it will write506 /// its idin the graph.507 void write Id(std::ostream& os, const Node& item) const {508 if (force IdMap) {505 /// Otherwise if the \c forceLabel parameter was true it will write 506 /// its label in the graph. 507 void writeLabel(std::ostream& os, const Node& item) const { 508 if (forceLabelMap) { 509 509 os << graph.id(item); 510 510 } else { 511 idMap->write(os, item);511 labelMap->write(os, item); 512 512 } 513 513 } … … 519 519 MapWriters writers; 520 520 521 _writer_bits::MapWriterBase<Node>* idMap;522 bool force IdMap;521 _writer_bits::MapWriterBase<Node>* labelMap; 522 bool forceLabelMap; 523 523 524 524 const Graph& graph; 525 std::string id;525 std::string name; 526 526 527 527 }; … … 531 531 /// 532 532 /// The lemon format can store multiple graph edgesets with several maps. 533 /// The edgeset section's header line is \c \@edgeset \c edgeset_ id, but the534 /// \c edgeset_idmay be empty.533 /// The edgeset section's header line is \c \@edgeset \c edgeset_name, but 534 /// the \c edgeset_name may be empty. 535 535 /// 536 536 /// The first line of the section contains the names of the maps separated 537 537 /// with white spaces. Each next lines describes a edge in the edgeset. The 538 /// line contains the source and the target nodes' idand the mapped538 /// line contains the source and the target nodes' label and the mapped 539 539 /// values for each map. 540 540 /// 541 /// If the edgeset contains an \c " id" named map then it will be regarded542 /// as idmap. This map should contain only unique values and when the543 /// \c write Id() member will be called with an edge it will write it's id.544 /// Otherwise if the \c _forceIdMap constructor parameter is true then545 /// the idmap will be the id in the graph.546 /// 547 /// The edgeset writer needs a node idwriter to identify which nodes548 /// have to be connected. If a NodeSetWriter can write the nodes' id,541 /// If the edgeset contains an \c "label" named map then it will be regarded 542 /// as label map. This map should contain only unique values and when the 543 /// \c writeLabel() member will be called with an edge it will write it's 544 /// label. Otherwise if the \c _forceLabelMap constructor parameter is true 545 /// then the label map will be the id in the graph. 546 /// 547 /// The edgeset writer needs a node label writer to identify which nodes 548 /// have to be connected. If a NodeSetWriter can write the nodes' label, 549 549 /// it will be able to use with this class. 550 550 /// … … 563 563 /// 564 564 /// Constructor for EdgeSetWriter. It creates the EdgeSetWriter and 565 /// attach it into the given LemonWriter. It will write node ids by566 /// the \c _node IdWriter. If the \c _forceIdMap parameter is true567 /// then the writer will write own idmap if the user does not give568 /// " id" named map.569 template <typename Node IdWriter>565 /// attach it into the given LemonWriter. It will write node labels by 566 /// the \c _nodeLabelWriter. If the \c _forceLabelMap parameter is true 567 /// then the writer will write own label map if the user does not give 568 /// "label" named map. 569 template <typename NodeLabelWriter> 570 570 EdgeSetWriter(LemonWriter& _writer, const Graph& _graph, 571 const Node IdWriter& _nodeIdWriter,572 const std::string& _ id= std::string(),573 bool _force IdMap = true)574 : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),575 graph(_graph), id(_id) {576 checkConcept<_writer_bits::Item IdWriter<Node>, NodeIdWriter>();577 node IdWriter.reset(new _writer_bits::578 IdWriter<Node, NodeIdWriter>(_nodeIdWriter));571 const NodeLabelWriter& _nodeLabelWriter, 572 const std::string& _name = std::string(), 573 bool _forceLabelMap = true) 574 : Parent(_writer), labelMap(0), forceLabelMap(_forceLabelMap), 575 graph(_graph), name(_name) { 576 checkConcept<_writer_bits::ItemLabelWriter<Node>, NodeLabelWriter>(); 577 nodeLabelWriter.reset(new _writer_bits:: 578 LabelWriter<Node, NodeLabelWriter>(_nodeLabelWriter)); 579 579 } 580 580 … … 624 624 /// It gives back the header of the section. 625 625 virtual std::string header() { 626 return "@edgeset " + id;626 return "@edgeset " + name; 627 627 } 628 628 … … 631 631 /// Write the content of the section. 632 632 virtual void write(std::ostream& os) { 633 if (!node IdWriter->isIdWriter()) {634 throw DataFormatError("Cannot find nodeset or IDmap");633 if (!nodeLabelWriter->isLabelWriter()) { 634 throw DataFormatError("Cannot find nodeset or label map"); 635 635 } 636 636 for (int i = 0; i < (int)writers.size(); ++i) { 637 if (writers[i].first == " id") {638 idMap = writers[i].second;639 force IdMap = false;637 if (writers[i].first == "label" || (writers[i].first == "id" && labelMap == 0)) { 638 labelMap = writers[i].second; 639 forceLabelMap = false; 640 640 break; 641 641 } 642 642 } 643 643 os << "\t\t"; 644 if (force IdMap) {645 os << " id\t";644 if (forceLabelMap) { 645 os << "label\t"; 646 646 } 647 647 for (int i = 0; i < (int)writers.size(); ++i) { … … 650 650 os << std::endl; 651 651 for (typename Graph::EdgeIt it(graph); it != INVALID; ++it) { 652 node IdWriter->write(os, graph.source(it));652 nodeLabelWriter->write(os, graph.source(it)); 653 653 os << '\t'; 654 node IdWriter->write(os, graph.target(it));654 nodeLabelWriter->write(os, graph.target(it)); 655 655 os << '\t'; 656 if (force IdMap) {656 if (forceLabelMap) { 657 657 os << graph.id(it) << '\t'; 658 658 } … … 667 667 public: 668 668 669 /// \brief Returns true if the edgeset can write the ids of the edges.670 /// 671 /// Returns true if the edgeset can write the ids of the edges.672 /// It is possible only if an " id" named map was written or the673 /// \c _force IdMap constructor parameter was true.674 bool is IdWriter() const {675 return force IdMap || idMap != 0;676 } 677 678 /// \brief Write the idof the given edge.679 /// 680 /// It writes the id of the given edge. If there was written an "id"669 /// \brief Returns true if the edgeset can write the labels of the edges. 670 /// 671 /// Returns true if the edgeset can write the labels of the edges. 672 /// It is possible only if an "label" named map was written or the 673 /// \c _forceLabelMap constructor parameter was true. 674 bool isLabelWriter() const { 675 return forceLabelMap || labelMap != 0; 676 } 677 678 /// \brief Write the label of the given edge. 679 /// 680 /// It writes the label of the given edge. If there was written an "label" 681 681 /// named map then it will write the map value belongs to the edge. 682 /// Otherwise if the \c force Idparameter was true it will write683 /// its idin the graph.684 void write Id(std::ostream& os, const Edge& item) const {685 if (force IdMap) {682 /// Otherwise if the \c forceLabel parameter was true it will write 683 /// its label in the graph. 684 void writeLabel(std::ostream& os, const Edge& item) const { 685 if (forceLabelMap) { 686 686 os << graph.id(item); 687 687 } else { 688 idMap->write(os, item);688 labelMap->write(os, item); 689 689 } 690 690 } … … 696 696 MapWriters writers; 697 697 698 _writer_bits::MapWriterBase<Edge>* idMap;699 bool force IdMap;698 _writer_bits::MapWriterBase<Edge>* labelMap; 699 bool forceLabelMap; 700 700 701 701 const Graph& graph; 702 std::string id;703 704 std::auto_ptr<_writer_bits:: IdWriterBase<Node> > nodeIdWriter;702 std::string name; 703 704 std::auto_ptr<_writer_bits::LabelWriterBase<Node> > nodeLabelWriter; 705 705 }; 706 706 … … 710 710 /// The lemon format can store multiple undirected edgesets with several 711 711 /// maps. The undirected edgeset section's header line is \c \@undiredgeset 712 /// \c undiredgeset_ id, but the \c undiredgeset_idmay be empty.712 /// \c undiredgeset_name, but the \c undiredgeset_name may be empty. 713 713 /// 714 714 /// The first line of the section contains the names of the maps separated 715 715 /// with white spaces. Each next lines describes an undirected edge in the 716 /// edgeset. The line contains the two connected nodes' idand the mapped716 /// edgeset. The line contains the two connected nodes' label and the mapped 717 717 /// values for each undirected map. 718 718 /// … … 723 723 /// difference. 724 724 /// 725 /// If the edgeset contains an \c " id" named map then it will be regarded726 /// as idmap. This map should contain only unique values and when the727 /// \c write Id() member will be called with an undirected edge it will728 /// write it's id. Otherwise if the \c _forceIdMap constructor parameter729 /// is true then the idmap will be the id in the graph.730 /// 731 /// The undirected edgeset writer needs a node idwriter to identify725 /// If the edgeset contains an \c "label" named map then it will be regarded 726 /// as label map. This map should contain only unique values and when the 727 /// \c writeLabel() member will be called with an undirected edge it will 728 /// write it's label. Otherwise if the \c _forceLabelMap constructor 729 /// parameter is true then the label map will be the id in the graph. 730 /// 731 /// The undirected edgeset writer needs a node label writer to identify 732 732 /// which nodes have to be connected. If a NodeSetWriter can write the 733 /// nodes' id, it will be able to use with this class.733 /// nodes' label, it will be able to use with this class. 734 734 /// 735 735 /// \relates LemonWriter … … 748 748 /// 749 749 /// Constructor for UndirEdgeSetWriter. It creates the UndirEdgeSetWriter 750 /// and attach it into the given LemonWriter. It will write node ids by751 /// the \c _node IdWriter. If the \c _forceIdMap parameter is true752 /// then the writer will write own idmap if the user does not give753 /// " id" named map.754 template <typename Node IdWriter>750 /// and attach it into the given LemonWriter. It will write node labels by 751 /// the \c _nodeLabelWriter. If the \c _forceLabelMap parameter is true 752 /// then the writer will write own label map if the user does not give 753 /// "label" named map. 754 template <typename NodeLabelWriter> 755 755 UndirEdgeSetWriter(LemonWriter& _writer, const Graph& _graph, 756 const Node IdWriter& _nodeIdWriter,757 const std::string& _ id= std::string(),758 bool _force IdMap = true)759 : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),760 graph(_graph), id(_id) {761 checkConcept<_writer_bits::Item IdWriter<Node>, NodeIdWriter>();762 node IdWriter.reset(new _writer_bits::763 IdWriter<Node, NodeIdWriter>(_nodeIdWriter));756 const NodeLabelWriter& _nodeLabelWriter, 757 const std::string& _name = std::string(), 758 bool _forceLabelMap = true) 759 : Parent(_writer), labelMap(0), forceLabelMap(_forceLabelMap), 760 graph(_graph), name(_name) { 761 checkConcept<_writer_bits::ItemLabelWriter<Node>, NodeLabelWriter>(); 762 nodeLabelWriter.reset(new _writer_bits:: 763 LabelWriter<Node, NodeLabelWriter>(_nodeLabelWriter)); 764 764 } 765 765 … … 833 833 /// It gives back the header of the section. 834 834 virtual std::string header() { 835 return "@undiredgeset " + id;835 return "@undiredgeset " + name; 836 836 } 837 837 … … 840 840 /// Write the content of the section. 841 841 virtual void write(std::ostream& os) { 842 if (!node IdWriter->isIdWriter()) {843 throw DataFormatError("Cannot find nodeset or IDmap");842 if (!nodeLabelWriter->isLabelWriter()) { 843 throw DataFormatError("Cannot find nodeset or label map"); 844 844 } 845 845 for (int i = 0; i < (int)writers.size(); ++i) { 846 if (writers[i].first == " id") {847 idMap = writers[i].second;848 force IdMap = false;846 if (writers[i].first == "label") { 847 labelMap = writers[i].second; 848 forceLabelMap = false; 849 849 break; 850 850 } 851 851 } 852 852 os << "\t\t"; 853 if (force IdMap) {854 os << " id\t";853 if (forceLabelMap) { 854 os << "label\t"; 855 855 } 856 856 for (int i = 0; i < (int)writers.size(); ++i) { … … 859 859 os << std::endl; 860 860 for (typename Graph::UndirEdgeIt it(graph); it != INVALID; ++it) { 861 node IdWriter->write(os, graph.source(it));861 nodeLabelWriter->write(os, graph.source(it)); 862 862 os << '\t'; 863 node IdWriter->write(os, graph.target(it));863 nodeLabelWriter->write(os, graph.target(it)); 864 864 os << '\t'; 865 if (force IdMap) {865 if (forceLabelMap) { 866 866 os << graph.id(it) << '\t'; 867 867 } … … 876 876 public: 877 877 878 /// \brief Returns true if the undirected edgeset can write the ids of878 /// \brief Returns true if the undirected edgeset can write the labels of 879 879 /// the edges. 880 880 /// 881 /// Returns true if the undirected edgeset can write the ids of the882 /// undirected edges. It is possible only if an " id" named map was883 /// written or the \c _force IdMap constructor parameter was true.884 bool is IdWriter() const {885 return force IdMap || idMap != 0;886 } 887 888 /// \brief Write the idof the given undirected edge.889 /// 890 /// It writes the idof the given undirected edge. If there was written891 /// an " id" named map then it will write the map value belongs to the892 /// undirected edge. Otherwise if the \c force Idparameter was true it881 /// Returns true if the undirected edgeset can write the labels of the 882 /// undirected edges. It is possible only if an "label" named map was 883 /// written or the \c _forceLabelMap constructor parameter was true. 884 bool isLabelWriter() const { 885 return forceLabelMap || labelMap != 0; 886 } 887 888 /// \brief Write the label of the given undirected edge. 889 /// 890 /// It writes the label of the given undirected edge. If there was written 891 /// an "label" named map then it will write the map value belongs to the 892 /// undirected edge. Otherwise if the \c forceLabel parameter was true it 893 893 /// will write its id in the graph. 894 void write Id(std::ostream& os, const UndirEdge& item) const {895 if (force IdMap) {894 void writeLabel(std::ostream& os, const UndirEdge& item) const { 895 if (forceLabelMap) { 896 896 os << graph.id(item); 897 897 } else { 898 idMap->write(os, item);898 labelMap->write(os, item); 899 899 } 900 900 } 901 901 902 /// \brief Write the idof the given edge.903 /// 904 /// It writes the idof the given edge. If there was written905 /// an " id" named map then it will write the map value belongs to the906 /// edge. Otherwise if the \c force Idparameter was true it902 /// \brief Write the label of the given edge. 903 /// 904 /// It writes the label of the given edge. If there was written 905 /// an "label" named map then it will write the map value belongs to the 906 /// edge. Otherwise if the \c forceLabel parameter was true it 907 907 /// will write its id in the graph. If the edge is forward map 908 908 /// then its prefix character is \c '+' elsewhere \c '-'. 909 void write Id(std::ostream& os, const Edge& item) const {909 void writeLabel(std::ostream& os, const Edge& item) const { 910 910 if (graph.direction(item)) { 911 911 os << "+ "; … … 913 913 os << "- "; 914 914 } 915 if (force IdMap) {915 if (forceLabelMap) { 916 916 os << graph.id(item); 917 917 } else { 918 idMap->write(os, item);918 labelMap->write(os, item); 919 919 } 920 920 } … … 926 926 MapWriters writers; 927 927 928 _writer_bits::MapWriterBase<UndirEdge>* idMap;929 bool force IdMap;928 _writer_bits::MapWriterBase<UndirEdge>* labelMap; 929 bool forceLabelMap; 930 930 931 931 const Graph& graph; 932 std::string id;933 934 std::auto_ptr<_writer_bits:: IdWriterBase<Node> > nodeIdWriter;932 std::string name; 933 934 std::auto_ptr<_writer_bits::LabelWriterBase<Node> > nodeLabelWriter; 935 935 }; 936 936 937 937 /// \ingroup io_group 938 /// \brief SectionWriter for writing labeled nodes.939 /// 940 /// The nodes section's header line is \c \@nodes \c nodes_ id, but the941 /// \c nodes_ idmay be empty.942 /// 943 /// Each line in the section contains the labelof the node and944 /// then the node id.938 /// \brief SectionWriter for writing named nodes. 939 /// 940 /// The nodes section's header line is \c \@nodes \c nodes_name, but the 941 /// \c nodes_name may be empty. 942 /// 943 /// Each line in the section contains the name of the node and 944 /// then the node label. 945 945 /// 946 946 /// \relates LemonWriter … … 955 955 /// 956 956 /// Constructor for NodeWriter. It creates the NodeWriter and 957 /// attach it into the given LemonWriter. The given \c _IdWriter 958 /// will write the nodes' id what can be a nodeset writer. 959 template <typename _IdWriter> 960 NodeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, 961 const std::string& _id = std::string()) 962 : Parent(_writer), id(_id) { 963 checkConcept<_writer_bits::ItemIdWriter<Node>, _IdWriter>(); 964 idWriter.reset(new _writer_bits::IdWriter<Node, _IdWriter>(_idWriter)); 957 /// attach it into the given LemonWriter. The given \c _LabelWriter 958 /// will write the nodes' label what can be a nodeset writer. 959 template <typename _LabelWriter> 960 NodeWriter(LemonWriter& _writer, const _LabelWriter& _labelWriter, 961 const std::string& _name = std::string()) 962 : Parent(_writer), name(_name) { 963 checkConcept<_writer_bits::ItemLabelWriter<Node>, _LabelWriter>(); 964 labelWriter.reset(new _writer_bits::LabelWriter<Node, _LabelWriter> 965 (_labelWriter)); 965 966 } 966 967 … … 986 987 protected: 987 988 988 /// \brief Header checking function. 989 /// 990 /// It gives back true when the header line start with \c \@nodes, 991 /// and the header line's id and the writer's id are the same. 989 /// \brief The header of the section. 990 /// 991 /// It gives back the header of the section. 992 992 virtual std::string header() { 993 return "@nodes " + id;993 return "@nodes " + name; 994 994 } 995 995 … … 998 998 /// Write the content of the section. 999 999 virtual void write(std::ostream& os) { 1000 if (! idWriter->isIdWriter()) {1001 throw DataFormatError("Cannot find nodeset or IDmap");1000 if (!labelWriter->isLabelWriter()) { 1001 throw DataFormatError("Cannot find nodeset or label map"); 1002 1002 } 1003 1003 for (int i = 0; i < (int)writers.size(); ++i) { 1004 1004 os << writers[i].first << ' '; 1005 idWriter->write(os, *(writers[i].second));1005 labelWriter->write(os, *(writers[i].second)); 1006 1006 os << std::endl; 1007 1007 } … … 1010 1010 private: 1011 1011 1012 std::string id;1012 std::string name; 1013 1013 1014 1014 typedef std::vector<std::pair<std::string, const Node*> > NodeWriters; 1015 1015 NodeWriters writers; 1016 std::auto_ptr<_writer_bits:: IdWriterBase<Node> > idWriter;1016 std::auto_ptr<_writer_bits::LabelWriterBase<Node> > labelWriter; 1017 1017 }; 1018 1018 1019 1019 /// \ingroup io_group 1020 /// \brief SectionWriter for writing labeled edges.1021 /// 1022 /// The edges section's header line is \c \@edges \c edges_ id, but the1023 /// \c edges_ idmay be empty.1024 /// 1025 /// Each line in the section contains the labelof the edge and1026 /// then the edge id.1020 /// \brief SectionWriter for writing named edges. 1021 /// 1022 /// The edges section's header line is \c \@edges \c edges_name, but the 1023 /// \c edges_name may be empty. 1024 /// 1025 /// Each line in the section contains the name of the edge and 1026 /// then the edge label. 1027 1027 /// 1028 1028 /// \relates LemonWriter … … 1037 1037 /// 1038 1038 /// Constructor for EdgeWriter. It creates the EdgeWriter and 1039 /// attach it into the given LemonWriter. The given \c _ IdWriter1040 /// will write the edges' idwhat can be a edgeset writer.1041 template <typename _ IdWriter>1042 EdgeWriter(LemonWriter& _writer, const _ IdWriter& _idWriter,1043 const std::string& _ id= std::string())1044 : Parent(_writer), id(_id) {1045 checkConcept<_writer_bits::Item IdWriter<Edge>, _IdWriter>();1046 idWriter.reset(new _writer_bits::IdWriter<Edge, _IdWriter>(_idWriter));1039 /// attach it into the given LemonWriter. The given \c _LabelWriter 1040 /// will write the edges' label what can be a edgeset writer. 1041 template <typename _LabelWriter> 1042 EdgeWriter(LemonWriter& _writer, const _LabelWriter& _labelWriter, 1043 const std::string& _name = std::string()) 1044 : Parent(_writer), name(_name) { 1045 checkConcept<_writer_bits::ItemLabelWriter<Edge>, _LabelWriter>(); 1046 labelWriter.reset(new _writer_bits::LabelWriter<Edge, _LabelWriter>(_labelWriter)); 1047 1047 } 1048 1048 … … 1066 1066 protected: 1067 1067 1068 /// \brief Header checking function. 1069 /// 1070 /// It gives back true when the header line start with \c \@edges, 1071 /// and the header line's id and the writer's id are the same. 1068 /// \brief The header of the section. 1069 /// 1070 /// It gives back the header of the section. 1072 1071 virtual std::string header() { 1073 return "@edges " + id;1072 return "@edges " + name; 1074 1073 } 1075 1074 … … 1078 1077 /// Write the content of the section. 1079 1078 virtual void write(std::ostream& os) { 1080 if (! idWriter->isIdWriter()) {1081 throw DataFormatError("Cannot find edgeset or IDmap");1079 if (!labelWriter->isLabelWriter()) { 1080 throw DataFormatError("Cannot find edgeset or label map"); 1082 1081 } 1083 1082 for (int i = 0; i < (int)writers.size(); ++i) { 1084 1083 os << writers[i].first << ' '; 1085 idWriter->write(os, *(writers[i].second));1084 labelWriter->write(os, *(writers[i].second)); 1086 1085 os << std::endl; 1087 1086 } … … 1090 1089 private: 1091 1090 1092 std::string id;1091 std::string name; 1093 1092 1094 1093 typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters; 1095 1094 EdgeWriters writers; 1096 1095 1097 std::auto_ptr<_writer_bits:: IdWriterBase<Edge> > idWriter;1096 std::auto_ptr<_writer_bits::LabelWriterBase<Edge> > labelWriter; 1098 1097 }; 1099 1098 1100 1099 /// \ingroup io_group 1101 /// \brief SectionWriter for writing labeled undirected edges.1100 /// \brief SectionWriter for writing named undirected edges. 1102 1101 /// 1103 1102 /// The undirected edges section's header line is \c \@undiredges 1104 /// \c undiredges_ id, but the \c undiredges_idmay be empty.1105 /// 1106 /// Each line in the section contains the labelof the undirected edge and1107 /// then the undirected edge id.1103 /// \c undiredges_name, but the \c undiredges_name may be empty. 1104 /// 1105 /// Each line in the section contains the name of the undirected edge and 1106 /// then the undirected edge label. 1108 1107 /// 1109 1108 /// \relates LemonWriter … … 1120 1119 /// 1121 1120 /// Constructor for UndirEdgeWriter. It creates the UndirEdgeWriter and 1122 /// attach it into the given LemonWriter. The given \c _ IdWriter1123 /// will write the undirected edges' idwhat can be an undirected1121 /// attach it into the given LemonWriter. The given \c _LabelWriter 1122 /// will write the undirected edges' label what can be an undirected 1124 1123 /// edgeset writer. 1125 template <typename _ IdWriter>1126 UndirEdgeWriter(LemonWriter& _writer, const _ IdWriter& _idWriter,1127 const std::string& _ id= std::string())1128 : Parent(_writer), id(_id) {1129 checkConcept<_writer_bits::Item IdWriter<Edge>, _IdWriter>();1130 checkConcept<_writer_bits::Item IdWriter<UndirEdge>, _IdWriter>();1131 undirEdge IdWriter.reset(new _writer_bits::1132 IdWriter<UndirEdge, _IdWriter>(_idWriter));1133 edge IdWriter.reset(new _writer_bits::1134 IdWriter<Edge, _IdWriter>(_idWriter));1124 template <typename _LabelWriter> 1125 UndirEdgeWriter(LemonWriter& _writer, const _LabelWriter& _labelWriter, 1126 const std::string& _name = std::string()) 1127 : Parent(_writer), name(_name) { 1128 checkConcept<_writer_bits::ItemLabelWriter<Edge>, _LabelWriter>(); 1129 checkConcept<_writer_bits::ItemLabelWriter<UndirEdge>, _LabelWriter>(); 1130 undirEdgeLabelWriter.reset(new _writer_bits:: 1131 LabelWriter<UndirEdge, _LabelWriter>(_labelWriter)); 1132 edgeLabelWriter.reset(new _writer_bits:: 1133 LabelWriter<Edge, _LabelWriter>(_labelWriter)); 1135 1134 } 1136 1135 … … 1161 1160 protected: 1162 1161 1163 /// \brief Header checking function. 1164 /// 1165 /// It gives back true when the header line start with \c \@undiredges, 1166 /// and the header line's id and the writer's id are the same. 1162 /// \brief The header of the section. 1163 /// 1164 /// It gives back the header of the section. 1167 1165 virtual std::string header() { 1168 return "@undiredges " + id;1166 return "@undiredges " + name; 1169 1167 } 1170 1168 … … 1173 1171 /// Write the content of the section. 1174 1172 virtual void write(std::ostream& os) { 1175 if (!edge IdWriter->isIdWriter()) {1176 throw DataFormatError("Cannot find undirected edgeset or IDmap");1177 } 1178 if (!undirEdge IdWriter->isIdWriter()) {1179 throw DataFormatError("Cannot find undirected edgeset or IDmap");1173 if (!edgeLabelWriter->isLabelWriter()) { 1174 throw DataFormatError("Cannot find undirected edgeset or label map"); 1175 } 1176 if (!undirEdgeLabelWriter->isLabelWriter()) { 1177 throw DataFormatError("Cannot find undirected edgeset or label map"); 1180 1178 } 1181 1179 for (int i = 0; i < (int)undirEdgeWriters.size(); ++i) { 1182 1180 os << undirEdgeWriters[i].first << ' '; 1183 undirEdge IdWriter->write(os, *(undirEdgeWriters[i].second));1181 undirEdgeLabelWriter->write(os, *(undirEdgeWriters[i].second)); 1184 1182 os << std::endl; 1185 1183 } 1186 1184 for (int i = 0; i < (int)edgeWriters.size(); ++i) { 1187 1185 os << edgeWriters[i].first << ' '; 1188 edge IdWriter->write(os, *(edgeWriters[i].second));1186 edgeLabelWriter->write(os, *(edgeWriters[i].second)); 1189 1187 os << std::endl; 1190 1188 } … … 1193 1191 private: 1194 1192 1195 std::string id;1193 std::string name; 1196 1194 1197 1195 typedef std::vector<std::pair<std::string, 1198 1196 const UndirEdge*> > UndirEdgeWriters; 1199 1197 UndirEdgeWriters undirEdgeWriters; 1200 std::auto_ptr<_writer_bits:: IdWriterBase<UndirEdge> > undirEdgeIdWriter;1198 std::auto_ptr<_writer_bits::LabelWriterBase<UndirEdge> > undirEdgeLabelWriter; 1201 1199 1202 1200 typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters; 1203 1201 EdgeWriters edgeWriters; 1204 std::auto_ptr<_writer_bits:: IdWriterBase<Edge> > edgeIdWriter;1202 std::auto_ptr<_writer_bits::LabelWriterBase<Edge> > edgeLabelWriter; 1205 1203 1206 1204 }; … … 1210 1208 /// 1211 1209 /// The lemon format can store multiple attribute set. Each set has 1212 /// the header line \c \@attributes \c attributes et_id, but the1213 /// attributeset_ idmay be empty.1210 /// the header line \c \@attributes \c attributes_name, but the 1211 /// attributeset_name may be empty. 1214 1212 /// 1215 1213 /// The attributeset section contains several lines. Each of them starts … … 1227 1225 /// attach it into the given LemonWriter. 1228 1226 AttributeWriter(LemonWriter& _writer, 1229 const std::string& _ id= std::string())1230 : Parent(_writer), id(_id) {}1227 const std::string& _name = std::string()) 1228 : Parent(_writer), name(_name) {} 1231 1229 1232 1230 /// \brief Destructor. … … 1249 1247 /// Add an attribute writer command for the writer. 1250 1248 template <typename Value> 1251 AttributeWriter& writeAttribute(const std::string& id,1249 AttributeWriter& writeAttribute(const std::string& name, 1252 1250 const Value& value) { 1253 1251 return 1254 writeAttribute<typename Traits::template Writer<Value> >( id, value);1252 writeAttribute<typename Traits::template Writer<Value> >(name, value); 1255 1253 } 1256 1254 … … 1274 1272 /// It gives back the header of the section. 1275 1273 std::string header() { 1276 return "@attributes " + id;1274 return "@attributes " + name; 1277 1275 } 1278 1276 … … 1290 1288 1291 1289 private: 1292 std::string id;1290 std::string name; 1293 1291 1294 1292 typedef std::vector<std::pair<std::string,
Note: See TracChangeset
for help on using the changeset viewer.