1.1 --- a/src/lemon/lemon_writer.h Thu May 19 11:46:42 2005 +0000
1.2 +++ b/src/lemon/lemon_writer.h Thu May 19 11:49:42 2005 +0000
1.3 @@ -243,7 +243,7 @@
1.4 : idWriter(_idWriter) {}
1.5
1.6 virtual void write(std::ostream& os, const Item& item) const {
1.7 - return idWriter.writeId(os, item);
1.8 + idWriter.writeId(os, item);
1.9 }
1.10 };
1.11 };
1.12 @@ -273,7 +273,7 @@
1.13
1.14 typedef _Graph Graph;
1.15 typedef _Traits Traits;
1.16 - typedef typename Graph::Node Item;
1.17 + typedef typename Graph::Node Node;
1.18
1.19 /// \brief Constructor.
1.20 ///
1.21 @@ -319,7 +319,7 @@
1.22 NodeSetWriter& writeNodeMap(std::string name, const Map& map,
1.23 const Writer& writer = Writer()) {
1.24 writers.push_back(
1.25 - make_pair(name, new MapWriter<Item, Map, Writer>(map, writer)));
1.26 + make_pair(name, new MapWriter<Node, Map, Writer>(map, writer)));
1.27 return *this;
1.28 }
1.29
1.30 @@ -379,7 +379,7 @@
1.31 /// named map then it will write the map value belongs to the node.
1.32 /// Otherwise if the \c forceId parameter was true it will write
1.33 /// its id in the graph.
1.34 - void writeId(std::ostream& os, const Item& item) const {
1.35 + void writeId(std::ostream& os, const Node& item) const {
1.36 if (forceIdMap) {
1.37 os << graph.id(item);
1.38 } else {
1.39 @@ -389,10 +389,10 @@
1.40
1.41 private:
1.42
1.43 - typedef std::vector<std::pair<std::string, WriterBase<Item>*> > MapWriters;
1.44 + typedef std::vector<std::pair<std::string, WriterBase<Node>*> > MapWriters;
1.45 MapWriters writers;
1.46
1.47 - WriterBase<Item>* idMap;
1.48 + WriterBase<Node>* idMap;
1.49 bool forceIdMap;
1.50
1.51 typename SmartConstReference<Graph>::Type graph;
1.52 @@ -430,7 +430,8 @@
1.53
1.54 typedef _Graph Graph;
1.55 typedef _Traits Traits;
1.56 - typedef typename Graph::Edge Item;
1.57 + typedef typename Graph::Node Node;
1.58 + typedef typename Graph::Edge Edge;
1.59
1.60 /// \brief Constructor.
1.61 ///
1.62 @@ -446,8 +447,7 @@
1.63 bool _forceIdMap = true)
1.64 : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
1.65 graph(_graph), id(_id),
1.66 - nodeIdWriter(new IdWriter<typename Graph::Node, NodeIdWriter>
1.67 - (_nodeIdWriter)) {}
1.68 + nodeIdWriter(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter)) {}
1.69
1.70 /// \brief Destructor.
1.71 ///
1.72 @@ -481,7 +481,7 @@
1.73 EdgeSetWriter& writeEdgeMap(std::string name, const Map& map,
1.74 const Writer& writer = Writer()) {
1.75 writers.push_back(
1.76 - make_pair(name, new MapWriter<Item, Map, Writer>(map, writer)));
1.77 + make_pair(name, new MapWriter<Edge, Map, Writer>(map, writer)));
1.78 return *this;
1.79 }
1.80
1.81 @@ -546,7 +546,7 @@
1.82 /// named map then it will write the map value belongs to the edge.
1.83 /// Otherwise if the \c forceId parameter was true it will write
1.84 /// its id in the graph.
1.85 - void writeId(std::ostream& os, const Item& item) const {
1.86 + void writeId(std::ostream& os, const Edge& item) const {
1.87 if (forceIdMap) {
1.88 os << graph.id(item);
1.89 } else {
1.90 @@ -556,16 +556,16 @@
1.91
1.92 private:
1.93
1.94 - typedef std::vector<std::pair<std::string, WriterBase<Item>*> > MapWriters;
1.95 + typedef std::vector<std::pair<std::string, WriterBase<Edge>*> > MapWriters;
1.96 MapWriters writers;
1.97
1.98 - WriterBase<Item>* idMap;
1.99 + WriterBase<Edge>* idMap;
1.100 bool forceIdMap;
1.101
1.102 typename SmartConstReference<Graph>::Type graph;
1.103 std::string id;
1.104
1.105 - std::auto_ptr<IdWriterBase<typename Graph::Node> > nodeIdWriter;
1.106 + std::auto_ptr<IdWriterBase<Node> > nodeIdWriter;
1.107 };
1.108
1.109 /// \ingroup io_group
1.110 @@ -604,7 +604,9 @@
1.111
1.112 typedef _Graph Graph;
1.113 typedef _Traits Traits;
1.114 - typedef typename Graph::UndirEdge Item;
1.115 + typedef typename Graph::Node Node;
1.116 + typedef typename Graph::Edge Edge;
1.117 + typedef typename Graph::UndirEdge UndirEdge;
1.118
1.119 /// \brief Constructor.
1.120 ///
1.121 @@ -620,8 +622,7 @@
1.122 bool _forceIdMap = true)
1.123 : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
1.124 graph(_graph), id(_id),
1.125 - nodeIdWriter(new IdWriter<typename Graph::Node, NodeIdWriter>
1.126 - (_nodeIdWriter)) {}
1.127 + nodeIdWriter(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter)) {}
1.128
1.129 /// \brief Destructor.
1.130 ///
1.131 @@ -655,7 +656,7 @@
1.132 UndirEdgeSetWriter& writeUndirEdgeMap(std::string name, const Map& map,
1.133 const Writer& writer = Writer()) {
1.134 writers.push_back(
1.135 - make_pair(name, new MapWriter<Item, Map, Writer>(map, writer)));
1.136 + make_pair(name, new MapWriter<UndirEdge, Map, Writer>(map, writer)));
1.137 return *this;
1.138 }
1.139
1.140 @@ -742,7 +743,27 @@
1.141 /// an "id" named map then it will write the map value belongs to the
1.142 /// undirected edge. Otherwise if the \c forceId parameter was true it
1.143 /// will write its id in the graph.
1.144 - void writeId(std::ostream& os, const Item& item) const {
1.145 + void writeId(std::ostream& os, const UndirEdge& item) const {
1.146 + if (forceIdMap) {
1.147 + os << graph.id(item);
1.148 + } else {
1.149 + idMap->write(os, item);
1.150 + }
1.151 + }
1.152 +
1.153 + /// \brief Write the id of the given edge.
1.154 + ///
1.155 + /// It writes the id of the given edge. If there was written
1.156 + /// an "id" named map then it will write the map value belongs to the
1.157 + /// edge. Otherwise if the \c forceId parameter was true it
1.158 + /// will write its id in the graph. If the edge is forward map
1.159 + /// then its prefix character is \c '+' elsewhere \c '-'.
1.160 + void writeId(std::ostream& os, const Edge& item) const {
1.161 + if (graph.forward(item)) {
1.162 + os << "+ ";
1.163 + } else {
1.164 + os << "- ";
1.165 + }
1.166 if (forceIdMap) {
1.167 os << graph.id(item);
1.168 } else {
1.169 @@ -752,16 +773,17 @@
1.170
1.171 private:
1.172
1.173 - typedef std::vector<std::pair<std::string, WriterBase<Item>*> > MapWriters;
1.174 + typedef std::vector<std::pair<std::string,
1.175 + WriterBase<UndirEdge>*> > MapWriters;
1.176 MapWriters writers;
1.177
1.178 - WriterBase<Item>* idMap;
1.179 + WriterBase<UndirEdge>* idMap;
1.180 bool forceIdMap;
1.181
1.182 typename SmartConstReference<Graph>::Type graph;
1.183 std::string id;
1.184
1.185 - std::auto_ptr<IdWriterBase<typename Graph::Node> > nodeIdWriter;
1.186 + std::auto_ptr<IdWriterBase<Node> > nodeIdWriter;
1.187 };
1.188
1.189 /// \ingroup io_group
1.190 @@ -778,7 +800,7 @@
1.191 class NodeWriter : public CommonSectionWriterBase {
1.192 typedef CommonSectionWriterBase Parent;
1.193 typedef _Graph Graph;
1.194 - typedef typename Graph::Node Item;
1.195 + typedef typename Graph::Node Node;
1.196 public:
1.197
1.198 /// \brief Constructor.
1.199 @@ -806,7 +828,7 @@
1.200 /// \brief Add a node writer command for the NodeWriter.
1.201 ///
1.202 /// Add a node writer command for the NodeWriter.
1.203 - void writeNode(const std::string& name, const Item& item) {
1.204 + void writeNode(const std::string& name, const Node& item) {
1.205 writers.push_back(make_pair(name, &item));
1.206 }
1.207
1.208 @@ -835,9 +857,9 @@
1.209
1.210 std::string id;
1.211
1.212 - typedef std::vector<std::pair<std::string, const Item*> > ItemWriters;
1.213 - ItemWriters writers;
1.214 - std::auto_ptr<IdWriterBase<Item> > idWriter;
1.215 + typedef std::vector<std::pair<std::string, const Node*> > NodeWriters;
1.216 + NodeWriters writers;
1.217 + std::auto_ptr<IdWriterBase<Node> > idWriter;
1.218 };
1.219
1.220 /// \ingroup io_group
1.221 @@ -854,7 +876,7 @@
1.222 class EdgeWriter : public CommonSectionWriterBase {
1.223 typedef CommonSectionWriterBase Parent;
1.224 typedef _Graph Graph;
1.225 - typedef typename Graph::Edge Item;
1.226 + typedef typename Graph::Edge Edge;
1.227 public:
1.228
1.229 /// \brief Constructor.
1.230 @@ -881,7 +903,7 @@
1.231 /// \brief Add an edge writer command for the EdgeWriter.
1.232 ///
1.233 /// Add an edge writer command for the EdgeWriter.
1.234 - void writeEdge(const std::string& name, const Item& item) {
1.235 + void writeEdge(const std::string& name, const Edge& item) {
1.236 writers.push_back(make_pair(name, &item));
1.237 }
1.238
1.239 @@ -910,10 +932,10 @@
1.240
1.241 std::string id;
1.242
1.243 - typedef std::vector<std::pair<std::string, const Item*> > ItemWriters;
1.244 - ItemWriters writers;
1.245 + typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters;
1.246 + EdgeWriters writers;
1.247
1.248 - std::auto_ptr<IdWriterBase<Item> > idWriter;
1.249 + std::auto_ptr<IdWriterBase<Edge> > idWriter;
1.250 };
1.251
1.252 /// \ingroup io_group
1.253 @@ -930,7 +952,9 @@
1.254 class UndirEdgeWriter : public CommonSectionWriterBase {
1.255 typedef CommonSectionWriterBase Parent;
1.256 typedef _Graph Graph;
1.257 - typedef typename Graph::UndirEdge Item;
1.258 + typedef typename Graph::Node Node;
1.259 + typedef typename Graph::Edge Edge;
1.260 + typedef typename Graph::UndirEdge UndirEdge;
1.261 public:
1.262
1.263 /// \brief Constructor.
1.264 @@ -943,8 +967,8 @@
1.265 UndirEdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter,
1.266 const std::string& _id = std::string())
1.267 : Parent(_writer), id(_id),
1.268 - idWriter(new IdWriter<typename Graph::UndirEdge, _IdWriter>
1.269 - (_idWriter)) {}
1.270 + undirEdgeIdWriter(new IdWriter<UndirEdge, _IdWriter>(_idWriter)),
1.271 + edgeIdWriter(new IdWriter<Edge, _IdWriter>(_idWriter)) {}
1.272
1.273 /// \brief Destructor.
1.274 ///
1.275 @@ -956,11 +980,18 @@
1.276
1.277 public:
1.278
1.279 + /// \brief Add an edge writer command for the UndirEdgeWriter.
1.280 + ///
1.281 + /// Add an edge writer command for the UndirEdgeWriter.
1.282 + void writeEdge(const std::string& name, const Edge& item) {
1.283 + edgeWriters.push_back(make_pair(name, &item));
1.284 + }
1.285 +
1.286 /// \brief Add an undirected edge writer command for the UndirEdgeWriter.
1.287 ///
1.288 - /// Add an edge writer command for the UndirEdgeWriter.
1.289 - void writeUndirEdge(const std::string& name, const Item& item) {
1.290 - writers.push_back(make_pair(name, &item));
1.291 + /// Add an undirected edge writer command for the UndirEdgeWriter.
1.292 + void writeUndirEdge(const std::string& name, const UndirEdge& item) {
1.293 + undirEdgeWriters.push_back(make_pair(name, &item));
1.294 }
1.295
1.296 protected:
1.297 @@ -970,16 +1001,21 @@
1.298 /// It gives back true when the header line start with \c \@undiredges,
1.299 /// and the header line's id and the writer's id are the same.
1.300 virtual std::string header() {
1.301 - return "@edges " + id;
1.302 + return "@undiredges " + id;
1.303 }
1.304
1.305 /// \brief Writer function of the section.
1.306 ///
1.307 /// Write the content of the section.
1.308 virtual void write(std::ostream& os) {
1.309 - for (int i = 0; i < (int)writers.size(); ++i) {
1.310 - os << writers[i].first << ' ';
1.311 - idWriter->write(os, *(writers[i].second));
1.312 + for (int i = 0; i < (int)undirEdgeWriters.size(); ++i) {
1.313 + os << undirEdgeWriters[i].first << ' ';
1.314 + undirEdgeIdWriter->write(os, *(undirEdgeWriters[i].second));
1.315 + os << std::endl;
1.316 + }
1.317 + for (int i = 0; i < (int)edgeWriters.size(); ++i) {
1.318 + os << edgeWriters[i].first << ' ';
1.319 + edgeIdWriter->write(os, *(edgeWriters[i].second));
1.320 os << std::endl;
1.321 }
1.322 }
1.323 @@ -988,10 +1024,15 @@
1.324
1.325 std::string id;
1.326
1.327 - typedef std::vector<std::pair<std::string, const Item*> > ItemWriters;
1.328 - ItemWriters writers;
1.329 + typedef std::vector<std::pair<std::string,
1.330 + const UndirEdge*> > UndirEdgeWriters;
1.331 + UndirEdgeWriters undirEdgeWriters;
1.332 + std::auto_ptr<IdWriterBase<UndirEdge> > undirEdgeIdWriter;
1.333
1.334 - std::auto_ptr<IdWriterBase<Item> > idWriter;
1.335 + typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters;
1.336 + EdgeWriters edgeWriters;
1.337 + std::auto_ptr<IdWriterBase<Edge> > edgeIdWriter;
1.338 +
1.339 };
1.340
1.341 /// \ingroup io_group