diff -r b16ca599472f -r 723b2b81d900 lemon/lemon_writer.h --- a/lemon/lemon_writer.h Thu Jan 19 16:56:39 2006 +0000 +++ b/lemon/lemon_writer.h Tue Jan 24 16:07:38 2006 +0000 @@ -46,21 +46,21 @@ namespace _writer_bits { template - class ItemIdWriter { + class ItemLabelWriter { public: - bool isIdWriter() { return true; } + bool isLabelWriter() { return true; } - void writeId(std::ostream&, const Item&) {} + void writeLabel(std::ostream&, const Item&) {} - template + template struct Constraints { void constraints() { - bool b = writer.isIdWriter(); + bool b = writer.isLabelWriter(); ignore_unused_variable_warning(b); - writer.writeId(os, item); + writer.writeLabel(os, item); } - _ItemIdWriter& writer; + _ItemLabelWriter& writer; std::ostream& os; const Item& item; }; @@ -225,31 +225,31 @@ template - class IdWriterBase { + class LabelWriterBase { public: typedef _Item Item; - virtual ~IdWriterBase() {} + virtual ~LabelWriterBase() {} virtual void write(std::ostream&, const Item&) const = 0; - virtual bool isIdWriter() const = 0; + virtual bool isLabelWriter() const = 0; }; - template - class IdWriter : public IdWriterBase<_Item> { + template + class LabelWriter : public LabelWriterBase<_Item> { public: typedef _Item Item; - typedef _BoxedIdWriter BoxedIdWriter; + typedef _BoxedLabelWriter BoxedLabelWriter; - const BoxedIdWriter& idWriter; + const BoxedLabelWriter& labelWriter; - IdWriter(const BoxedIdWriter& _idWriter) - : idWriter(_idWriter) {} + LabelWriter(const BoxedLabelWriter& _labelWriter) + : labelWriter(_labelWriter) {} virtual void write(std::ostream& os, const Item& item) const { - idWriter.writeId(os, item); + labelWriter.writeLabel(os, item); } - virtual bool isIdWriter() const { - return idWriter.isIdWriter(); + virtual bool isLabelWriter() const { + return labelWriter.isLabelWriter(); } }; @@ -374,18 +374,18 @@ /// \brief SectionWriter for writing a graph's nodeset. /// /// The lemon format can store multiple graph nodesets with several maps. - /// The nodeset section's header line is \c \@nodeset \c nodeset_id, but the - /// \c nodeset_id may be empty. + /// The nodeset section's header line is \c \@nodeset \c nodeset_name, but + /// the \c nodeset_name may be empty. /// /// The first line of the section contains the names of the maps separated /// with white spaces. Each next lines describes a node in the nodeset, and /// contains the mapped values for each map. /// - /// If the nodeset contains an \c "id" named map then it will be regarded - /// as id map. This map should contain only unique values and when the - /// \c writeId() member will be called with a node it will write it's id. - /// Otherwise if the \c _forceIdMap constructor parameter is true then - /// the id map will be the id in the graph. + /// If the nodeset contains an \c "label" named map then it will be regarded + /// as label map. This map should contain only unique values and when the + /// \c writeLabel() member will be called with a node it will write it's + /// label. Otherwise if the \c _forceLabelMap constructor parameter is true + /// then the label map will be the id in the graph. /// /// \relates LemonWriter template @@ -400,14 +400,14 @@ /// \brief Constructor. /// /// Constructor for NodeSetWriter. It creates the NodeSetWriter and - /// attach it into the given LemonWriter. If the \c _forceIdMap - /// parameter is true then the writer will write own id map when - /// the user does not give "id" named map. + /// attach it into the given LemonWriter. If the \c _forceLabelMap + /// parameter is true then the writer will write own label map when + /// the user does not give "label" named map. NodeSetWriter(LemonWriter& _writer, const Graph& _graph, - const std::string& _id = std::string(), - bool _forceIdMap = true) - : Parent(_writer), idMap(0), forceIdMap(_forceIdMap), - graph(_graph), id(_id) {} + const std::string& _name = std::string(), + bool _forceLabelMap = true) + : Parent(_writer), labelMap(0), forceLabelMap(_forceLabelMap), + graph(_graph), name(_name) {} /// \brief Destructor. /// @@ -454,7 +454,7 @@ /// /// It gives back the header of the section. virtual std::string header() { - return "@nodeset " + id; + return "@nodeset " + name; } /// \brief Writer function of the section. @@ -462,21 +462,21 @@ /// Write the content of the section. virtual void write(std::ostream& os) { for (int i = 0; i < (int)writers.size(); ++i) { - if (writers[i].first == "id") { - idMap = writers[i].second; - forceIdMap = false; + if (writers[i].first == "label" || (writers[i].first == "id" && labelMap == 0)) { + labelMap = writers[i].second; + forceLabelMap = false; break; } } - if (forceIdMap) { - os << "id\t"; + if (forceLabelMap) { + os << "label\t"; } for (int i = 0; i < (int)writers.size(); ++i) { os << writers[i].first << '\t'; } os << std::endl; for (typename Graph::NodeIt it(graph); it != INVALID; ++it) { - if (forceIdMap) { + if (forceLabelMap) { os << graph.id(it) << '\t'; } for (int i = 0; i < (int)writers.size(); ++i) { @@ -489,26 +489,26 @@ public: - /// \brief Returns true if the nodeset can write the ids of the nodes. + /// \brief Returns true if the nodeset can write the labels of the nodes. /// - /// Returns true if the nodeset can write the ids of the nodes. - /// It is possible only if an "id" named map was written or the - /// \c _forceIdMap constructor parameter was true. - bool isIdWriter() const { - return idMap != 0 || forceIdMap; + /// Returns true if the nodeset can write the labels of the nodes. + /// It is possible only if an "label" named map was written or the + /// \c _forceLabelMap constructor parameter was true. + bool isLabelWriter() const { + return labelMap != 0 || forceLabelMap; } - /// \brief Write the id of the given node. + /// \brief Write the label of the given node. /// - /// It writes the id of the given node. If there was written an "id" + /// It writes the label of the given node. If there was written an "label" /// named map then it will write the map value belongs to the node. - /// Otherwise if the \c forceId parameter was true it will write - /// its id in the graph. - void writeId(std::ostream& os, const Node& item) const { - if (forceIdMap) { + /// Otherwise if the \c forceLabel parameter was true it will write + /// its label in the graph. + void writeLabel(std::ostream& os, const Node& item) const { + if (forceLabelMap) { os << graph.id(item); } else { - idMap->write(os, item); + labelMap->write(os, item); } } @@ -518,11 +518,11 @@ MapWriterBase*> > MapWriters; MapWriters writers; - _writer_bits::MapWriterBase* idMap; - bool forceIdMap; + _writer_bits::MapWriterBase* labelMap; + bool forceLabelMap; const Graph& graph; - std::string id; + std::string name; }; @@ -530,22 +530,22 @@ /// \brief SectionWriter for writing a graph's edgesets. /// /// The lemon format can store multiple graph edgesets with several maps. - /// The edgeset section's header line is \c \@edgeset \c edgeset_id, but the - /// \c edgeset_id may be empty. + /// The edgeset section's header line is \c \@edgeset \c edgeset_name, but + /// the \c edgeset_name may be empty. /// /// The first line of the section contains the names of the maps separated /// with white spaces. Each next lines describes a edge in the edgeset. The - /// line contains the source and the target nodes' id and the mapped + /// line contains the source and the target nodes' label and the mapped /// values for each map. /// - /// If the edgeset contains an \c "id" named map then it will be regarded - /// as id map. This map should contain only unique values and when the - /// \c writeId() member will be called with an edge it will write it's id. - /// Otherwise if the \c _forceIdMap constructor parameter is true then - /// the id map will be the id in the graph. + /// If the edgeset contains an \c "label" named map then it will be regarded + /// as label map. This map should contain only unique values and when the + /// \c writeLabel() member will be called with an edge it will write it's + /// label. Otherwise if the \c _forceLabelMap constructor parameter is true + /// then the label map will be the id in the graph. /// - /// The edgeset writer needs a node id writer to identify which nodes - /// have to be connected. If a NodeSetWriter can write the nodes' id, + /// The edgeset writer needs a node label writer to identify which nodes + /// have to be connected. If a NodeSetWriter can write the nodes' label, /// it will be able to use with this class. /// /// \relates LemonWriter @@ -562,20 +562,20 @@ /// \brief Constructor. /// /// Constructor for EdgeSetWriter. It creates the EdgeSetWriter and - /// attach it into the given LemonWriter. It will write node ids by - /// the \c _nodeIdWriter. If the \c _forceIdMap parameter is true - /// then the writer will write own id map if the user does not give - /// "id" named map. - template + /// attach it into the given LemonWriter. It will write node labels by + /// the \c _nodeLabelWriter. If the \c _forceLabelMap parameter is true + /// then the writer will write own label map if the user does not give + /// "label" named map. + template EdgeSetWriter(LemonWriter& _writer, const Graph& _graph, - const NodeIdWriter& _nodeIdWriter, - const std::string& _id = std::string(), - bool _forceIdMap = true) - : Parent(_writer), idMap(0), forceIdMap(_forceIdMap), - graph(_graph), id(_id) { - checkConcept<_writer_bits::ItemIdWriter, NodeIdWriter>(); - nodeIdWriter.reset(new _writer_bits:: - IdWriter(_nodeIdWriter)); + const NodeLabelWriter& _nodeLabelWriter, + const std::string& _name = std::string(), + bool _forceLabelMap = true) + : Parent(_writer), labelMap(0), forceLabelMap(_forceLabelMap), + graph(_graph), name(_name) { + checkConcept<_writer_bits::ItemLabelWriter, NodeLabelWriter>(); + nodeLabelWriter.reset(new _writer_bits:: + LabelWriter(_nodeLabelWriter)); } /// \brief Destructor. @@ -623,37 +623,37 @@ /// /// It gives back the header of the section. virtual std::string header() { - return "@edgeset " + id; + return "@edgeset " + name; } /// \brief Writer function of the section. /// /// Write the content of the section. virtual void write(std::ostream& os) { - if (!nodeIdWriter->isIdWriter()) { - throw DataFormatError("Cannot find nodeset or ID map"); + if (!nodeLabelWriter->isLabelWriter()) { + throw DataFormatError("Cannot find nodeset or label map"); } for (int i = 0; i < (int)writers.size(); ++i) { - if (writers[i].first == "id") { - idMap = writers[i].second; - forceIdMap = false; + if (writers[i].first == "label" || (writers[i].first == "id" && labelMap == 0)) { + labelMap = writers[i].second; + forceLabelMap = false; break; } } os << "\t\t"; - if (forceIdMap) { - os << "id\t"; + if (forceLabelMap) { + os << "label\t"; } for (int i = 0; i < (int)writers.size(); ++i) { os << writers[i].first << '\t'; } os << std::endl; for (typename Graph::EdgeIt it(graph); it != INVALID; ++it) { - nodeIdWriter->write(os, graph.source(it)); + nodeLabelWriter->write(os, graph.source(it)); os << '\t'; - nodeIdWriter->write(os, graph.target(it)); + nodeLabelWriter->write(os, graph.target(it)); os << '\t'; - if (forceIdMap) { + if (forceLabelMap) { os << graph.id(it) << '\t'; } for (int i = 0; i < (int)writers.size(); ++i) { @@ -666,26 +666,26 @@ public: - /// \brief Returns true if the edgeset can write the ids of the edges. + /// \brief Returns true if the edgeset can write the labels of the edges. /// - /// Returns true if the edgeset can write the ids of the edges. - /// It is possible only if an "id" named map was written or the - /// \c _forceIdMap constructor parameter was true. - bool isIdWriter() const { - return forceIdMap || idMap != 0; + /// Returns true if the edgeset can write the labels of the edges. + /// It is possible only if an "label" named map was written or the + /// \c _forceLabelMap constructor parameter was true. + bool isLabelWriter() const { + return forceLabelMap || labelMap != 0; } - /// \brief Write the id of the given edge. + /// \brief Write the label of the given edge. /// - /// It writes the id of the given edge. If there was written an "id" + /// It writes the label of the given edge. If there was written an "label" /// named map then it will write the map value belongs to the edge. - /// Otherwise if the \c forceId parameter was true it will write - /// its id in the graph. - void writeId(std::ostream& os, const Edge& item) const { - if (forceIdMap) { + /// Otherwise if the \c forceLabel parameter was true it will write + /// its label in the graph. + void writeLabel(std::ostream& os, const Edge& item) const { + if (forceLabelMap) { os << graph.id(item); } else { - idMap->write(os, item); + labelMap->write(os, item); } } @@ -695,13 +695,13 @@ MapWriterBase*> > MapWriters; MapWriters writers; - _writer_bits::MapWriterBase* idMap; - bool forceIdMap; + _writer_bits::MapWriterBase* labelMap; + bool forceLabelMap; const Graph& graph; - std::string id; + std::string name; - std::auto_ptr<_writer_bits::IdWriterBase > nodeIdWriter; + std::auto_ptr<_writer_bits::LabelWriterBase > nodeLabelWriter; }; /// \ingroup io_group @@ -709,11 +709,11 @@ /// /// The lemon format can store multiple undirected edgesets with several /// maps. The undirected edgeset section's header line is \c \@undiredgeset - /// \c undiredgeset_id, but the \c undiredgeset_id may be empty. + /// \c undiredgeset_name, but the \c undiredgeset_name may be empty. /// /// The first line of the section contains the names of the maps separated /// with white spaces. Each next lines describes an undirected edge in the - /// edgeset. The line contains the two connected nodes' id and the mapped + /// edgeset. The line contains the two connected nodes' label and the mapped /// values for each undirected map. /// /// The section can handle the directed as a syntactical sugar. Two @@ -722,15 +722,15 @@ /// is near the same just with a prefix \c '+' or \c '-' character /// difference. /// - /// If the edgeset contains an \c "id" named map then it will be regarded - /// as id map. This map should contain only unique values and when the - /// \c writeId() member will be called with an undirected edge it will - /// write it's id. Otherwise if the \c _forceIdMap constructor parameter - /// is true then the id map will be the id in the graph. + /// If the edgeset contains an \c "label" named map then it will be regarded + /// as label map. This map should contain only unique values and when the + /// \c writeLabel() member will be called with an undirected edge it will + /// write it's label. Otherwise if the \c _forceLabelMap constructor + /// parameter is true then the label map will be the id in the graph. /// - /// The undirected edgeset writer needs a node id writer to identify + /// The undirected edgeset writer needs a node label writer to identify /// which nodes have to be connected. If a NodeSetWriter can write the - /// nodes' id, it will be able to use with this class. + /// nodes' label, it will be able to use with this class. /// /// \relates LemonWriter template @@ -747,20 +747,20 @@ /// \brief Constructor. /// /// Constructor for UndirEdgeSetWriter. It creates the UndirEdgeSetWriter - /// and attach it into the given LemonWriter. It will write node ids by - /// the \c _nodeIdWriter. If the \c _forceIdMap parameter is true - /// then the writer will write own id map if the user does not give - /// "id" named map. - template + /// and attach it into the given LemonWriter. It will write node labels by + /// the \c _nodeLabelWriter. If the \c _forceLabelMap parameter is true + /// then the writer will write own label map if the user does not give + /// "label" named map. + template UndirEdgeSetWriter(LemonWriter& _writer, const Graph& _graph, - const NodeIdWriter& _nodeIdWriter, - const std::string& _id = std::string(), - bool _forceIdMap = true) - : Parent(_writer), idMap(0), forceIdMap(_forceIdMap), - graph(_graph), id(_id) { - checkConcept<_writer_bits::ItemIdWriter, NodeIdWriter>(); - nodeIdWriter.reset(new _writer_bits:: - IdWriter(_nodeIdWriter)); + const NodeLabelWriter& _nodeLabelWriter, + const std::string& _name = std::string(), + bool _forceLabelMap = true) + : Parent(_writer), labelMap(0), forceLabelMap(_forceLabelMap), + graph(_graph), name(_name) { + checkConcept<_writer_bits::ItemLabelWriter, NodeLabelWriter>(); + nodeLabelWriter.reset(new _writer_bits:: + LabelWriter(_nodeLabelWriter)); } /// \brief Destructor. @@ -832,37 +832,37 @@ /// /// It gives back the header of the section. virtual std::string header() { - return "@undiredgeset " + id; + return "@undiredgeset " + name; } /// \brief Writer function of the section. /// /// Write the content of the section. virtual void write(std::ostream& os) { - if (!nodeIdWriter->isIdWriter()) { - throw DataFormatError("Cannot find nodeset or ID map"); + if (!nodeLabelWriter->isLabelWriter()) { + throw DataFormatError("Cannot find nodeset or label map"); } for (int i = 0; i < (int)writers.size(); ++i) { - if (writers[i].first == "id") { - idMap = writers[i].second; - forceIdMap = false; + if (writers[i].first == "label") { + labelMap = writers[i].second; + forceLabelMap = false; break; } } os << "\t\t"; - if (forceIdMap) { - os << "id\t"; + if (forceLabelMap) { + os << "label\t"; } for (int i = 0; i < (int)writers.size(); ++i) { os << writers[i].first << '\t'; } os << std::endl; for (typename Graph::UndirEdgeIt it(graph); it != INVALID; ++it) { - nodeIdWriter->write(os, graph.source(it)); + nodeLabelWriter->write(os, graph.source(it)); os << '\t'; - nodeIdWriter->write(os, graph.target(it)); + nodeLabelWriter->write(os, graph.target(it)); os << '\t'; - if (forceIdMap) { + if (forceLabelMap) { os << graph.id(it) << '\t'; } for (int i = 0; i < (int)writers.size(); ++i) { @@ -875,47 +875,47 @@ public: - /// \brief Returns true if the undirected edgeset can write the ids of + /// \brief Returns true if the undirected edgeset can write the labels of /// the edges. /// - /// Returns true if the undirected edgeset can write the ids of the - /// undirected edges. It is possible only if an "id" named map was - /// written or the \c _forceIdMap constructor parameter was true. - bool isIdWriter() const { - return forceIdMap || idMap != 0; + /// Returns true if the undirected edgeset can write the labels of the + /// undirected edges. It is possible only if an "label" named map was + /// written or the \c _forceLabelMap constructor parameter was true. + bool isLabelWriter() const { + return forceLabelMap || labelMap != 0; } - /// \brief Write the id of the given undirected edge. + /// \brief Write the label of the given undirected edge. /// - /// It writes the id of the given undirected edge. If there was written - /// an "id" named map then it will write the map value belongs to the - /// undirected edge. Otherwise if the \c forceId parameter was true it + /// It writes the label of the given undirected edge. If there was written + /// an "label" named map then it will write the map value belongs to the + /// undirected edge. Otherwise if the \c forceLabel parameter was true it /// will write its id in the graph. - void writeId(std::ostream& os, const UndirEdge& item) const { - if (forceIdMap) { + void writeLabel(std::ostream& os, const UndirEdge& item) const { + if (forceLabelMap) { os << graph.id(item); } else { - idMap->write(os, item); + labelMap->write(os, item); } } - /// \brief Write the id of the given edge. + /// \brief Write the label of the given edge. /// - /// It writes the id of the given edge. If there was written - /// an "id" named map then it will write the map value belongs to the - /// edge. Otherwise if the \c forceId parameter was true it + /// It writes the label of the given edge. If there was written + /// an "label" named map then it will write the map value belongs to the + /// edge. Otherwise if the \c forceLabel parameter was true it /// will write its id in the graph. If the edge is forward map /// then its prefix character is \c '+' elsewhere \c '-'. - void writeId(std::ostream& os, const Edge& item) const { + void writeLabel(std::ostream& os, const Edge& item) const { if (graph.direction(item)) { os << "+ "; } else { os << "- "; } - if (forceIdMap) { + if (forceLabelMap) { os << graph.id(item); } else { - idMap->write(os, item); + labelMap->write(os, item); } } @@ -925,23 +925,23 @@ MapWriterBase*> > MapWriters; MapWriters writers; - _writer_bits::MapWriterBase* idMap; - bool forceIdMap; + _writer_bits::MapWriterBase* labelMap; + bool forceLabelMap; const Graph& graph; - std::string id; + std::string name; - std::auto_ptr<_writer_bits::IdWriterBase > nodeIdWriter; + std::auto_ptr<_writer_bits::LabelWriterBase > nodeLabelWriter; }; /// \ingroup io_group - /// \brief SectionWriter for writing labeled nodes. + /// \brief SectionWriter for writing named nodes. /// - /// The nodes section's header line is \c \@nodes \c nodes_id, but the - /// \c nodes_id may be empty. + /// The nodes section's header line is \c \@nodes \c nodes_name, but the + /// \c nodes_name may be empty. /// - /// Each line in the section contains the label of the node and - /// then the node id. + /// Each line in the section contains the name of the node and + /// then the node label. /// /// \relates LemonWriter template @@ -954,14 +954,15 @@ /// \brief Constructor. /// /// Constructor for NodeWriter. It creates the NodeWriter and - /// attach it into the given LemonWriter. The given \c _IdWriter - /// will write the nodes' id what can be a nodeset writer. - template - NodeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, - const std::string& _id = std::string()) - : Parent(_writer), id(_id) { - checkConcept<_writer_bits::ItemIdWriter, _IdWriter>(); - idWriter.reset(new _writer_bits::IdWriter(_idWriter)); + /// attach it into the given LemonWriter. The given \c _LabelWriter + /// will write the nodes' label what can be a nodeset writer. + template + NodeWriter(LemonWriter& _writer, const _LabelWriter& _labelWriter, + const std::string& _name = std::string()) + : Parent(_writer), name(_name) { + checkConcept<_writer_bits::ItemLabelWriter, _LabelWriter>(); + labelWriter.reset(new _writer_bits::LabelWriter + (_labelWriter)); } @@ -985,45 +986,44 @@ protected: - /// \brief Header checking function. + /// \brief The header of the section. /// - /// It gives back true when the header line start with \c \@nodes, - /// and the header line's id and the writer's id are the same. + /// It gives back the header of the section. virtual std::string header() { - return "@nodes " + id; + return "@nodes " + name; } /// \brief Writer function of the section. /// /// Write the content of the section. virtual void write(std::ostream& os) { - if (!idWriter->isIdWriter()) { - throw DataFormatError("Cannot find nodeset or ID map"); + if (!labelWriter->isLabelWriter()) { + throw DataFormatError("Cannot find nodeset or label map"); } for (int i = 0; i < (int)writers.size(); ++i) { os << writers[i].first << ' '; - idWriter->write(os, *(writers[i].second)); + labelWriter->write(os, *(writers[i].second)); os << std::endl; } } private: - std::string id; + std::string name; typedef std::vector > NodeWriters; NodeWriters writers; - std::auto_ptr<_writer_bits::IdWriterBase > idWriter; + std::auto_ptr<_writer_bits::LabelWriterBase > labelWriter; }; /// \ingroup io_group - /// \brief SectionWriter for writing labeled edges. + /// \brief SectionWriter for writing named edges. /// - /// The edges section's header line is \c \@edges \c edges_id, but the - /// \c edges_id may be empty. + /// The edges section's header line is \c \@edges \c edges_name, but the + /// \c edges_name may be empty. /// - /// Each line in the section contains the label of the edge and - /// then the edge id. + /// Each line in the section contains the name of the edge and + /// then the edge label. /// /// \relates LemonWriter template @@ -1036,14 +1036,14 @@ /// \brief Constructor. /// /// Constructor for EdgeWriter. It creates the EdgeWriter and - /// attach it into the given LemonWriter. The given \c _IdWriter - /// will write the edges' id what can be a edgeset writer. - template - EdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, - const std::string& _id = std::string()) - : Parent(_writer), id(_id) { - checkConcept<_writer_bits::ItemIdWriter, _IdWriter>(); - idWriter.reset(new _writer_bits::IdWriter(_idWriter)); + /// attach it into the given LemonWriter. The given \c _LabelWriter + /// will write the edges' label what can be a edgeset writer. + template + EdgeWriter(LemonWriter& _writer, const _LabelWriter& _labelWriter, + const std::string& _name = std::string()) + : Parent(_writer), name(_name) { + checkConcept<_writer_bits::ItemLabelWriter, _LabelWriter>(); + labelWriter.reset(new _writer_bits::LabelWriter(_labelWriter)); } /// \brief Destructor. @@ -1065,46 +1065,45 @@ protected: - /// \brief Header checking function. + /// \brief The header of the section. /// - /// It gives back true when the header line start with \c \@edges, - /// and the header line's id and the writer's id are the same. + /// It gives back the header of the section. virtual std::string header() { - return "@edges " + id; + return "@edges " + name; } /// \brief Writer function of the section. /// /// Write the content of the section. virtual void write(std::ostream& os) { - if (!idWriter->isIdWriter()) { - throw DataFormatError("Cannot find edgeset or ID map"); + if (!labelWriter->isLabelWriter()) { + throw DataFormatError("Cannot find edgeset or label map"); } for (int i = 0; i < (int)writers.size(); ++i) { os << writers[i].first << ' '; - idWriter->write(os, *(writers[i].second)); + labelWriter->write(os, *(writers[i].second)); os << std::endl; } } private: - std::string id; + std::string name; typedef std::vector > EdgeWriters; EdgeWriters writers; - std::auto_ptr<_writer_bits::IdWriterBase > idWriter; + std::auto_ptr<_writer_bits::LabelWriterBase > labelWriter; }; /// \ingroup io_group - /// \brief SectionWriter for writing labeled undirected edges. + /// \brief SectionWriter for writing named undirected edges. /// /// The undirected edges section's header line is \c \@undiredges - /// \c undiredges_id, but the \c undiredges_id may be empty. + /// \c undiredges_name, but the \c undiredges_name may be empty. /// - /// Each line in the section contains the label of the undirected edge and - /// then the undirected edge id. + /// Each line in the section contains the name of the undirected edge and + /// then the undirected edge label. /// /// \relates LemonWriter template @@ -1119,19 +1118,19 @@ /// \brief Constructor. /// /// Constructor for UndirEdgeWriter. It creates the UndirEdgeWriter and - /// attach it into the given LemonWriter. The given \c _IdWriter - /// will write the undirected edges' id what can be an undirected + /// attach it into the given LemonWriter. The given \c _LabelWriter + /// will write the undirected edges' label what can be an undirected /// edgeset writer. - template - UndirEdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, - const std::string& _id = std::string()) - : Parent(_writer), id(_id) { - checkConcept<_writer_bits::ItemIdWriter, _IdWriter>(); - checkConcept<_writer_bits::ItemIdWriter, _IdWriter>(); - undirEdgeIdWriter.reset(new _writer_bits:: - IdWriter(_idWriter)); - edgeIdWriter.reset(new _writer_bits:: - IdWriter(_idWriter)); + template + UndirEdgeWriter(LemonWriter& _writer, const _LabelWriter& _labelWriter, + const std::string& _name = std::string()) + : Parent(_writer), name(_name) { + checkConcept<_writer_bits::ItemLabelWriter, _LabelWriter>(); + checkConcept<_writer_bits::ItemLabelWriter, _LabelWriter>(); + undirEdgeLabelWriter.reset(new _writer_bits:: + LabelWriter(_labelWriter)); + edgeLabelWriter.reset(new _writer_bits:: + LabelWriter(_labelWriter)); } /// \brief Destructor. @@ -1160,48 +1159,47 @@ protected: - /// \brief Header checking function. + /// \brief The header of the section. /// - /// It gives back true when the header line start with \c \@undiredges, - /// and the header line's id and the writer's id are the same. + /// It gives back the header of the section. virtual std::string header() { - return "@undiredges " + id; + return "@undiredges " + name; } /// \brief Writer function of the section. /// /// Write the content of the section. virtual void write(std::ostream& os) { - if (!edgeIdWriter->isIdWriter()) { - throw DataFormatError("Cannot find undirected edgeset or ID map"); + if (!edgeLabelWriter->isLabelWriter()) { + throw DataFormatError("Cannot find undirected edgeset or label map"); } - if (!undirEdgeIdWriter->isIdWriter()) { - throw DataFormatError("Cannot find undirected edgeset or ID map"); + if (!undirEdgeLabelWriter->isLabelWriter()) { + throw DataFormatError("Cannot find undirected edgeset or label map"); } for (int i = 0; i < (int)undirEdgeWriters.size(); ++i) { os << undirEdgeWriters[i].first << ' '; - undirEdgeIdWriter->write(os, *(undirEdgeWriters[i].second)); + undirEdgeLabelWriter->write(os, *(undirEdgeWriters[i].second)); os << std::endl; } for (int i = 0; i < (int)edgeWriters.size(); ++i) { os << edgeWriters[i].first << ' '; - edgeIdWriter->write(os, *(edgeWriters[i].second)); + edgeLabelWriter->write(os, *(edgeWriters[i].second)); os << std::endl; } } private: - std::string id; + std::string name; typedef std::vector > UndirEdgeWriters; UndirEdgeWriters undirEdgeWriters; - std::auto_ptr<_writer_bits::IdWriterBase > undirEdgeIdWriter; + std::auto_ptr<_writer_bits::LabelWriterBase > undirEdgeLabelWriter; typedef std::vector > EdgeWriters; EdgeWriters edgeWriters; - std::auto_ptr<_writer_bits::IdWriterBase > edgeIdWriter; + std::auto_ptr<_writer_bits::LabelWriterBase > edgeLabelWriter; }; @@ -1209,8 +1207,8 @@ /// \brief SectionWriter for attributes. /// /// The lemon format can store multiple attribute set. Each set has - /// the header line \c \@attributes \c attributeset_id, but the - /// attributeset_id may be empty. + /// the header line \c \@attributes \c attributes_name, but the + /// attributeset_name may be empty. /// /// The attributeset section contains several lines. Each of them starts /// with the name of attribute and then the value. @@ -1226,8 +1224,8 @@ /// Constructor for AttributeWriter. It creates the AttributeWriter and /// attach it into the given LemonWriter. AttributeWriter(LemonWriter& _writer, - const std::string& _id = std::string()) - : Parent(_writer), id(_id) {} + const std::string& _name = std::string()) + : Parent(_writer), name(_name) {} /// \brief Destructor. /// @@ -1248,10 +1246,10 @@ /// /// Add an attribute writer command for the writer. template - AttributeWriter& writeAttribute(const std::string& id, + AttributeWriter& writeAttribute(const std::string& name, const Value& value) { return - writeAttribute >(id, value); + writeAttribute >(name, value); } /// \brief Add an attribute writer command for the writer. @@ -1273,7 +1271,7 @@ /// /// It gives back the header of the section. std::string header() { - return "@attributes " + id; + return "@attributes " + name; } /// \brief Writer function of the section. @@ -1289,7 +1287,7 @@ } private: - std::string id; + std::string name; typedef std::vector > Writers;