diff -r feb7974cf4ec -r 2025a571895e lemon/graph_writer.h --- a/lemon/graph_writer.h Tue Aug 28 13:58:54 2007 +0000 +++ b/lemon/graph_writer.h Tue Aug 28 14:00:42 2007 +0000 @@ -251,9 +251,17 @@ writer->run(); } + /// \brief Returns true if the writer can give back the labels by the items. + /// + /// Returns true if the writer can give back the the labels by the items. + bool isLabelWriter() const { + return nodeset_writer.isLabelWriter() && + edgeset_writer.isLabelWriter(); + } + /// \brief Write the label of the given node. /// - /// It writes the label of the given node. If there was written an "label" + /// It writes the label of the given node. If there was written a "label" /// named node map then it will write the map value belonging to the node. void writeLabel(std::ostream& os, const Node& item) const { nodeset_writer.writeLabel(os, item); @@ -261,12 +269,32 @@ /// \brief Write the label of the given edge. /// - /// It writes the label of the given edge. If there was written an "label" + /// It writes the label of the given edge. If there was written a "label" /// named edge map then it will write the map value belonging to the edge. void writeLabel(std::ostream& os, const Edge& item) const { edgeset_writer.writeLabel(os, item); } + /// \brief Sorts the given node vector by label. + /// + /// Sorts the given node vector by label. If there was written an + /// "label" named map then the vector will be sorted by the values + /// of this map. Otherwise if the \c forceLabel parameter was true + /// it will be sorted by its id in the graph. + void sortByLabel(std::vector& nodes) const { + nodeset_writer.sortByLabel(nodes); + } + + /// \brief Sorts the given edge vector by label. + /// + /// Sorts the given edge vector by label. If there was written an + /// "label" named map then the vector will be sorted by the values + /// of this map. Otherwise if the \c forceLabel parameter was true + /// it will be sorted by its id in the graph. + void sortByLabel(std::vector& edges) const { + edgeset_writer.sortByLabel(edges); + } + private: LemonWriter* writer; @@ -370,9 +398,9 @@ UGraphWriter(std::ostream& _os, const Graph& _graph) : writer(new LemonWriter(_os)), own_writer(true), nodeset_writer(*writer, _graph, std::string()), - u_edgeset_writer(*writer, _graph, nodeset_writer, std::string()), + uedgeset_writer(*writer, _graph, nodeset_writer, std::string()), node_writer(*writer, nodeset_writer, std::string()), - u_edge_writer(*writer, u_edgeset_writer, std::string()), + uedge_writer(*writer, uedgeset_writer, std::string()), attribute_writer(*writer, std::string()) {} /// \brief Construct a new UGraphWriter. @@ -382,21 +410,21 @@ UGraphWriter(const std::string& _filename, const Graph& _graph) : writer(new LemonWriter(_filename)), own_writer(true), nodeset_writer(*writer, _graph, std::string()), - u_edgeset_writer(*writer, _graph, nodeset_writer, std::string()), + uedgeset_writer(*writer, _graph, nodeset_writer, std::string()), node_writer(*writer, nodeset_writer, std::string()), - u_edge_writer(*writer, u_edgeset_writer, std::string()), + uedge_writer(*writer, uedgeset_writer, std::string()), attribute_writer(*writer, std::string()) {} /// \brief Construct a new UGraphWriter. /// /// Construct a new UGraphWriter. It writes the given graph - /// to given LemonReader. + /// to given LemonWriter. UGraphWriter(LemonWriter& _writer, const Graph& _graph) : writer(_writer), own_writer(false), nodeset_writer(*writer, _graph, std::string()), - u_edgeset_writer(*writer, _graph, nodeset_writer, std::string()), + uedgeset_writer(*writer, _graph, nodeset_writer, std::string()), node_writer(*writer, nodeset_writer, std::string()), - u_edge_writer(*writer, u_edgeset_writer, std::string()), + uedge_writer(*writer, uedgeset_writer, std::string()), attribute_writer(*writer, std::string()) {} /// \brief Destruct the graph writer. @@ -434,7 +462,7 @@ /// the writer. template UGraphWriter& writeEdgeMap(std::string label, const Map& map) { - u_edgeset_writer.writeEdgeMap(label, map); + uedgeset_writer.writeEdgeMap(label, map); return *this; } @@ -445,7 +473,7 @@ template UGraphWriter& writeEdgeMap(std::string label, const Map& map, const ItemWriter& iw = ItemWriter()) { - u_edgeset_writer.writeEdgeMap(label, map, iw); + uedgeset_writer.writeEdgeMap(label, map, iw); return *this; } @@ -455,7 +483,7 @@ /// command to the writer. template UGraphWriter& writeUEdgeMap(std::string label, const Map& map) { - u_edgeset_writer.writeUEdgeMap(label, map); + uedgeset_writer.writeUEdgeMap(label, map); return *this; } @@ -466,7 +494,7 @@ template UGraphWriter& writeUEdgeMap(std::string label, const Map& map, const ItemWriter& iw = ItemWriter()) { - u_edgeset_writer.writeUEdgeMap(label, map, iw); + uedgeset_writer.writeUEdgeMap(label, map, iw); return *this; } @@ -484,7 +512,7 @@ /// This function issues a new labeled edge writing /// command to the writer. UGraphWriter& writeEdge(std::string label, const Edge& edge) { - u_edge_writer.writeEdge(label, edge); + uedge_writer.writeEdge(label, edge); } /// \brief Issue a new labeled undirected edge writing command to @@ -493,7 +521,7 @@ /// Issue a new labeled undirected edge writing command to /// the writer. UGraphWriter& writeUEdge(std::string label, const UEdge& edge) { - u_edge_writer.writeUEdge(label, edge); + uedge_writer.writeUEdge(label, edge); } /// \brief Issue a new attribute writing command. @@ -534,9 +562,17 @@ writer->run(); } + /// \brief Returns true if the writer can give back the labels by the items. + /// + /// Returns true if the writer can give back the the labels by the items. + bool isLabelWriter() const { + return nodeset_writer.isLabelWriter() && + uedgeset_writer.isLabelWriter(); + } + /// \brief Write the label of the given node. /// - /// It writes the label of the given node. If there was written an "label" + /// It writes the label of the given node. If there was written a "label" /// named node map then it will write the map value belonging to the node. void writeLabel(std::ostream& os, const Node& item) const { nodeset_writer.writeLabel(os, item); @@ -544,21 +580,50 @@ /// \brief Write the label of the given edge. /// - /// It writes the label of the given edge. If there was written an "label" + /// It writes the label of the given edge. If there was written a "label" /// named edge map then it will write the map value belonging to the edge. void writeLabel(std::ostream& os, const Edge& item) const { - u_edgeset_writer.writeLabel(os, item); + uedgeset_writer.writeLabel(os, item); } /// \brief Write the label of the given undirected edge. /// /// It writes the label of the given undirected edge. If there was - /// written an "label" named edge map then it will write the map + /// written a "label" named edge map then it will write the map /// value belonging to the edge. void writeLabel(std::ostream& os, const UEdge& item) const { - u_edgeset_writer.writeLabel(os, item); + uedgeset_writer.writeLabel(os, item); } + /// \brief Sorts the given node vector by label. + /// + /// Sorts the given node vector by label. If there was written an + /// "label" named map then the vector will be sorted by the values + /// of this map. Otherwise if the \c forceLabel parameter was true + /// it will be sorted by its id in the graph. + void sortByLabel(std::vector& nodes) const { + nodeset_writer.sortByLabel(nodes); + } + + /// \brief Sorts the given edge vector by label. + /// + /// Sorts the given edge vector by label. If there was written an + /// "label" named map then the vector will be sorted by the values + /// of this map. Otherwise if the \c forceLabel parameter was true + /// it will be sorted by its id in the graph. + void sortByLabel(std::vector& edges) const { + uedgeset_writer.sortByLabel(edges); + } + + /// \brief Sorts the given undirected edge vector by label. + /// + /// Sorts the given undirected edge vector by label. If there was + /// written an "label" named map then the vector will be sorted by + /// the values of this map. Otherwise if the \c forceLabel + /// parameter was true it will be sorted by its id in the graph. + void sortByLabel(std::vector& uedges) const { + uedgeset_writer.sortByLabel(uedges); + } private: @@ -566,10 +631,10 @@ bool own_writer; NodeSetWriter nodeset_writer; - UEdgeSetWriter u_edgeset_writer; + UEdgeSetWriter uedgeset_writer; NodeWriter node_writer; - UEdgeWriter u_edge_writer; + UEdgeWriter uedge_writer; AttributeWriter attribute_writer; };