diff -r 9ba88ddc629c -r 4283998fb2be src/lemon/lemon_writer.h --- a/src/lemon/lemon_writer.h Thu May 19 11:46:42 2005 +0000 +++ b/src/lemon/lemon_writer.h Thu May 19 11:49:42 2005 +0000 @@ -243,7 +243,7 @@ : idWriter(_idWriter) {} virtual void write(std::ostream& os, const Item& item) const { - return idWriter.writeId(os, item); + idWriter.writeId(os, item); } }; }; @@ -273,7 +273,7 @@ typedef _Graph Graph; typedef _Traits Traits; - typedef typename Graph::Node Item; + typedef typename Graph::Node Node; /// \brief Constructor. /// @@ -319,7 +319,7 @@ NodeSetWriter& writeNodeMap(std::string name, const Map& map, const Writer& writer = Writer()) { writers.push_back( - make_pair(name, new MapWriter(map, writer))); + make_pair(name, new MapWriter(map, writer))); return *this; } @@ -379,7 +379,7 @@ /// 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 Item& item) const { + void writeId(std::ostream& os, const Node& item) const { if (forceIdMap) { os << graph.id(item); } else { @@ -389,10 +389,10 @@ private: - typedef std::vector*> > MapWriters; + typedef std::vector*> > MapWriters; MapWriters writers; - WriterBase* idMap; + WriterBase* idMap; bool forceIdMap; typename SmartConstReference::Type graph; @@ -430,7 +430,8 @@ typedef _Graph Graph; typedef _Traits Traits; - typedef typename Graph::Edge Item; + typedef typename Graph::Node Node; + typedef typename Graph::Edge Edge; /// \brief Constructor. /// @@ -446,8 +447,7 @@ bool _forceIdMap = true) : Parent(_writer), idMap(0), forceIdMap(_forceIdMap), graph(_graph), id(_id), - nodeIdWriter(new IdWriter - (_nodeIdWriter)) {} + nodeIdWriter(new IdWriter(_nodeIdWriter)) {} /// \brief Destructor. /// @@ -481,7 +481,7 @@ EdgeSetWriter& writeEdgeMap(std::string name, const Map& map, const Writer& writer = Writer()) { writers.push_back( - make_pair(name, new MapWriter(map, writer))); + make_pair(name, new MapWriter(map, writer))); return *this; } @@ -546,7 +546,7 @@ /// 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 Item& item) const { + void writeId(std::ostream& os, const Edge& item) const { if (forceIdMap) { os << graph.id(item); } else { @@ -556,16 +556,16 @@ private: - typedef std::vector*> > MapWriters; + typedef std::vector*> > MapWriters; MapWriters writers; - WriterBase* idMap; + WriterBase* idMap; bool forceIdMap; typename SmartConstReference::Type graph; std::string id; - std::auto_ptr > nodeIdWriter; + std::auto_ptr > nodeIdWriter; }; /// \ingroup io_group @@ -604,7 +604,9 @@ typedef _Graph Graph; typedef _Traits Traits; - typedef typename Graph::UndirEdge Item; + typedef typename Graph::Node Node; + typedef typename Graph::Edge Edge; + typedef typename Graph::UndirEdge UndirEdge; /// \brief Constructor. /// @@ -620,8 +622,7 @@ bool _forceIdMap = true) : Parent(_writer), idMap(0), forceIdMap(_forceIdMap), graph(_graph), id(_id), - nodeIdWriter(new IdWriter - (_nodeIdWriter)) {} + nodeIdWriter(new IdWriter(_nodeIdWriter)) {} /// \brief Destructor. /// @@ -655,7 +656,7 @@ UndirEdgeSetWriter& writeUndirEdgeMap(std::string name, const Map& map, const Writer& writer = Writer()) { writers.push_back( - make_pair(name, new MapWriter(map, writer))); + make_pair(name, new MapWriter(map, writer))); return *this; } @@ -742,7 +743,27 @@ /// 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 /// will write its id in the graph. - void writeId(std::ostream& os, const Item& item) const { + void writeId(std::ostream& os, const UndirEdge& item) const { + if (forceIdMap) { + os << graph.id(item); + } else { + idMap->write(os, item); + } + } + + /// \brief Write the id 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 + /// 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 { + if (graph.forward(item)) { + os << "+ "; + } else { + os << "- "; + } if (forceIdMap) { os << graph.id(item); } else { @@ -752,16 +773,17 @@ private: - typedef std::vector*> > MapWriters; + typedef std::vector*> > MapWriters; MapWriters writers; - WriterBase* idMap; + WriterBase* idMap; bool forceIdMap; typename SmartConstReference::Type graph; std::string id; - std::auto_ptr > nodeIdWriter; + std::auto_ptr > nodeIdWriter; }; /// \ingroup io_group @@ -778,7 +800,7 @@ class NodeWriter : public CommonSectionWriterBase { typedef CommonSectionWriterBase Parent; typedef _Graph Graph; - typedef typename Graph::Node Item; + typedef typename Graph::Node Node; public: /// \brief Constructor. @@ -806,7 +828,7 @@ /// \brief Add a node writer command for the NodeWriter. /// /// Add a node writer command for the NodeWriter. - void writeNode(const std::string& name, const Item& item) { + void writeNode(const std::string& name, const Node& item) { writers.push_back(make_pair(name, &item)); } @@ -835,9 +857,9 @@ std::string id; - typedef std::vector > ItemWriters; - ItemWriters writers; - std::auto_ptr > idWriter; + typedef std::vector > NodeWriters; + NodeWriters writers; + std::auto_ptr > idWriter; }; /// \ingroup io_group @@ -854,7 +876,7 @@ class EdgeWriter : public CommonSectionWriterBase { typedef CommonSectionWriterBase Parent; typedef _Graph Graph; - typedef typename Graph::Edge Item; + typedef typename Graph::Edge Edge; public: /// \brief Constructor. @@ -881,7 +903,7 @@ /// \brief Add an edge writer command for the EdgeWriter. /// /// Add an edge writer command for the EdgeWriter. - void writeEdge(const std::string& name, const Item& item) { + void writeEdge(const std::string& name, const Edge& item) { writers.push_back(make_pair(name, &item)); } @@ -910,10 +932,10 @@ std::string id; - typedef std::vector > ItemWriters; - ItemWriters writers; + typedef std::vector > EdgeWriters; + EdgeWriters writers; - std::auto_ptr > idWriter; + std::auto_ptr > idWriter; }; /// \ingroup io_group @@ -930,7 +952,9 @@ class UndirEdgeWriter : public CommonSectionWriterBase { typedef CommonSectionWriterBase Parent; typedef _Graph Graph; - typedef typename Graph::UndirEdge Item; + typedef typename Graph::Node Node; + typedef typename Graph::Edge Edge; + typedef typename Graph::UndirEdge UndirEdge; public: /// \brief Constructor. @@ -943,8 +967,8 @@ UndirEdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, const std::string& _id = std::string()) : Parent(_writer), id(_id), - idWriter(new IdWriter - (_idWriter)) {} + undirEdgeIdWriter(new IdWriter(_idWriter)), + edgeIdWriter(new IdWriter(_idWriter)) {} /// \brief Destructor. /// @@ -956,11 +980,18 @@ public: + /// \brief Add an edge writer command for the UndirEdgeWriter. + /// + /// Add an edge writer command for the UndirEdgeWriter. + void writeEdge(const std::string& name, const Edge& item) { + edgeWriters.push_back(make_pair(name, &item)); + } + /// \brief Add an undirected edge writer command for the UndirEdgeWriter. /// - /// Add an edge writer command for the UndirEdgeWriter. - void writeUndirEdge(const std::string& name, const Item& item) { - writers.push_back(make_pair(name, &item)); + /// Add an undirected edge writer command for the UndirEdgeWriter. + void writeUndirEdge(const std::string& name, const UndirEdge& item) { + undirEdgeWriters.push_back(make_pair(name, &item)); } protected: @@ -970,16 +1001,21 @@ /// 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. virtual std::string header() { - return "@edges " + id; + return "@undiredges " + id; } /// \brief Writer function of the section. /// /// Write the content of the section. virtual void write(std::ostream& os) { - for (int i = 0; i < (int)writers.size(); ++i) { - os << writers[i].first << ' '; - idWriter->write(os, *(writers[i].second)); + for (int i = 0; i < (int)undirEdgeWriters.size(); ++i) { + os << undirEdgeWriters[i].first << ' '; + undirEdgeIdWriter->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)); os << std::endl; } } @@ -988,10 +1024,15 @@ std::string id; - typedef std::vector > ItemWriters; - ItemWriters writers; + typedef std::vector > UndirEdgeWriters; + UndirEdgeWriters undirEdgeWriters; + std::auto_ptr > undirEdgeIdWriter; - std::auto_ptr > idWriter; + typedef std::vector > EdgeWriters; + EdgeWriters edgeWriters; + std::auto_ptr > edgeIdWriter; + }; /// \ingroup io_group