1.1 --- a/src/lemon/bits/item_reader.h Thu May 19 11:46:42 2005 +0000
1.2 +++ b/src/lemon/bits/item_reader.h Thu May 19 11:49:42 2005 +0000
1.3 @@ -348,7 +348,7 @@
1.4
1.5 void read(std::istream& is, Value& value) const {
1.6 char c;
1.7 - if (!(is >> c)) return;
1.8 + if (!(is >> std::ws >> c)) return;
1.9 is.putback(c);
1.10 switch (c) {
1.11 case '\"':
2.1 --- a/src/lemon/bits/item_writer.h Thu May 19 11:46:42 2005 +0000
2.2 +++ b/src/lemon/bits/item_writer.h Thu May 19 11:49:42 2005 +0000
2.3 @@ -177,6 +177,10 @@
2.4 }
2.5 };
2.6
2.7 + template <>
2.8 + class DefaultWriter<std::string>
2.9 + : public QuotedStringWriter<std::string> {};
2.10 +
2.11 template <typename Item>
2.12 class DefaultWriter<std::vector<Item> >
2.13 : public IterableWriter<std::vector<Item> > {};
3.1 --- a/src/lemon/graph_reader.h Thu May 19 11:46:42 2005 +0000
3.2 +++ b/src/lemon/graph_reader.h Thu May 19 11:49:42 2005 +0000
3.3 @@ -299,6 +299,22 @@
3.4 reader->run();
3.5 }
3.6
3.7 + /// \brief Gives back the node by its id.
3.8 + ///
3.9 + /// It reads an id from the stream and gives back which node belongs to
3.10 + /// it. It is possible only if there was read an "id" named node map.
3.11 + Node readId(std::istream& is, Node) const {
3.12 + return nodeset_reader.readId(is, Node());
3.13 + }
3.14 +
3.15 + /// \brief Gives back the edge by its id.
3.16 + ///
3.17 + /// It reads an id from the stream and gives back which edge belongs to
3.18 + /// it. It is possible only if there was read an "id" named edge map.
3.19 + Edge readId(std::istream& is, Edge) const {
3.20 + return edgeset_reader.readId(is, Edge());
3.21 + }
3.22 +
3.23 private:
3.24
3.25 LemonReader* reader;
3.26 @@ -673,6 +689,13 @@
3.27 /// \brief Add a new labeled edge reader for the reader.
3.28 ///
3.29 /// Add a new labeled edge reader for the reader.
3.30 + UndirGraphReader& readEdge(std::string name, Edge& edge) {
3.31 + undir_edge_reader.readEdge(name, edge);
3.32 + }
3.33 +
3.34 + /// \brief Add a new labeled undirected edge reader for the reader.
3.35 + ///
3.36 + /// Add a new labeled undirected edge reader for the reader.
3.37 UndirGraphReader& readUndirEdge(std::string name, UndirEdge& edge) {
3.38 undir_edge_reader.readUndirEdge(name, edge);
3.39 }
3.40 @@ -713,6 +736,32 @@
3.41 reader->run();
3.42 }
3.43
3.44 + /// \brief Gives back the node by its id.
3.45 + ///
3.46 + /// It reads an id from the stream and gives back which node belongs to
3.47 + /// it. It is possible only if there was read an "id" named node map.
3.48 + Node readId(std::istream& is, Node) const {
3.49 + return nodeset_reader.readId(is, Node());
3.50 + }
3.51 +
3.52 + /// \brief Gives back the edge by its id.
3.53 + ///
3.54 + /// It reads an id from the stream and gives back which edge belongs to
3.55 + /// it. It is possible only if there was read an "id" named edge map.
3.56 + Edge readId(std::istream& is, Edge) const {
3.57 + return undir_edgeset_reader.readId(is, Edge());
3.58 + }
3.59 +
3.60 + /// \brief Gives back the undirected edge by its id.
3.61 + ///
3.62 + /// It reads an id from the stream and gives back which undirected edge
3.63 + /// belongs to it. It is possible only if there was read an "id" named
3.64 + /// edge map.
3.65 + UndirEdge readId(std::istream& is, UndirEdge) const {
3.66 + return undir_edgeset_reader.readId(is, UndirEdge());
3.67 + }
3.68 +
3.69 +
3.70 private:
3.71
3.72 LemonReader* reader;
4.1 --- a/src/lemon/graph_writer.h Thu May 19 11:46:42 2005 +0000
4.2 +++ b/src/lemon/graph_writer.h Thu May 19 11:49:42 2005 +0000
4.3 @@ -238,6 +238,22 @@
4.4 writer->run();
4.5 }
4.6
4.7 + /// \brief Write the id of the given node.
4.8 + ///
4.9 + /// It writes the id of the given node. If there was written an "id"
4.10 + /// named node map then it will write the map value belongs to the node.
4.11 + void writeId(std::ostream& os, const Node& item) const {
4.12 + nodeset_writer.writeId(os, item);
4.13 + }
4.14 +
4.15 + /// \brief Write the id of the given edge.
4.16 + ///
4.17 + /// It writes the id of the given edge. If there was written an "id"
4.18 + /// named edge map then it will write the map value belongs to the edge.
4.19 + void writeId(std::ostream& os, const Edge& item) const {
4.20 + edgeset_writer.writeId(os, item);
4.21 + }
4.22 +
4.23 private:
4.24
4.25 LemonWriter* writer;
4.26 @@ -547,6 +563,13 @@
4.27 /// \brief Add a new labeled edge writer for the writer.
4.28 ///
4.29 /// Add a new labeled edge writer for the writer.
4.30 + UndirGraphWriter& writeEdge(std::string name, const Edge& edge) {
4.31 + undir_edge_writer.writeEdge(name, edge);
4.32 + }
4.33 +
4.34 + /// \brief Add a new labeled undirected edge writer for the writer.
4.35 + ///
4.36 + /// Add a new labeled undirected edge writer for the writer.
4.37 UndirGraphWriter& writeUndirEdge(std::string name, const UndirEdge& edge) {
4.38 undir_edge_writer.writeUndirEdge(name, edge);
4.39 }
4.40 @@ -587,6 +610,32 @@
4.41 writer->run();
4.42 }
4.43
4.44 + /// \brief Write the id of the given node.
4.45 + ///
4.46 + /// It writes the id of the given node. If there was written an "id"
4.47 + /// named node map then it will write the map value belongs to the node.
4.48 + void writeId(std::ostream& os, const Node& item) const {
4.49 + nodeset_writer.writeId(os, item);
4.50 + }
4.51 +
4.52 + /// \brief Write the id of the given edge.
4.53 + ///
4.54 + /// It writes the id of the given edge. If there was written an "id"
4.55 + /// named edge map then it will write the map value belongs to the edge.
4.56 + void writeId(std::ostream& os, const Edge& item) const {
4.57 + undir_edgeset_writer.writeId(os, item);
4.58 + }
4.59 +
4.60 + /// \brief Write the id of the given undirected edge.
4.61 + ///
4.62 + /// It writes the id of the given undirected edge. If there was written
4.63 + /// an "id" named edge map then it will write the map value belongs to
4.64 + /// the edge.
4.65 + void writeId(std::ostream& os, const UndirEdge& item) const {
4.66 + undir_edgeset_writer.writeId(os, item);
4.67 + }
4.68 +
4.69 +
4.70 private:
4.71
4.72 LemonWriter* writer;
5.1 --- a/src/lemon/lemon_reader.h Thu May 19 11:46:42 2005 +0000
5.2 +++ b/src/lemon/lemon_reader.h Thu May 19 11:49:42 2005 +0000
5.3 @@ -545,7 +545,7 @@
5.4 : boxedIdReader(_boxedIdReader) {}
5.5
5.6 virtual Item read(std::istream& is) const {
5.7 - return boxedIdReader.readId(is);
5.8 + return boxedIdReader.readId(is, Item());
5.9 }
5.10 };
5.11
5.12 @@ -597,7 +597,7 @@
5.13
5.14 typedef _Graph Graph;
5.15 typedef _Traits Traits;
5.16 - typedef typename Graph::Node Item;
5.17 + typedef typename Graph::Node Node;
5.18 typedef typename Traits::Skipper DefaultSkipper;
5.19
5.20 /// \brief Constructor.
5.21 @@ -652,17 +652,15 @@
5.22 template <typename Reader, typename Map>
5.23 NodeSetReader& readNodeMap(std::string name, Map& map,
5.24 const Reader& reader = Reader()) {
5.25 - return _readMap<
5.26 - typename Traits::template Reader<typename Map::Value>, Map,
5.27 - typename SmartParameter<Map>::Type>(name, map, reader);
5.28 + return _readMap<Reader, Map, typename SmartParameter<Map>::Type>
5.29 + (name, map, reader);
5.30 }
5.31
5.32 template <typename Reader, typename Map>
5.33 NodeSetReader& readNodeMap(std::string name, const Map& map,
5.34 const Reader& reader = Reader()) {
5.35 - return _readMap<
5.36 - typename Traits::template Reader<typename Map::Value>, Map,
5.37 - typename SmartParameter<Map>::Type>(name, map, reader);
5.38 + return _readMap<Reader, Map, typename SmartParameter<Map>::Type>
5.39 + (name, map, reader);
5.40 }
5.41
5.42 private:
5.43 @@ -676,7 +674,7 @@
5.44 throw IOParameterError(msg.message());
5.45 }
5.46 readers.insert(
5.47 - make_pair(name, new MapReader<Item, Map, Reader>(map, reader)));
5.48 + make_pair(name, new MapReader<Node, Map, Reader>(map, reader)));
5.49 return *this;
5.50 }
5.51
5.52 @@ -693,7 +691,7 @@
5.53 msg << "Multiple read rule for node map: " << name;
5.54 throw IOParameterError(msg.message());
5.55 }
5.56 - readers.insert(make_pair(name, new SkipReader<Item, Reader>(reader)));
5.57 + readers.insert(make_pair(name, new SkipReader<Node, Reader>(reader)));
5.58 return *this;
5.59 }
5.60
5.61 @@ -716,7 +714,7 @@
5.62 ///
5.63 /// It reads the content of the section.
5.64 virtual void read(std::istream& is) {
5.65 - std::vector<ReaderBase<Item>* > index;
5.66 + std::vector<ReaderBase<Node>* > index;
5.67 std::string line;
5.68
5.69 getline(is, line);
5.70 @@ -734,7 +732,7 @@
5.71 }
5.72 }
5.73 while (getline(is, line)) {
5.74 - typename Graph::Node node = graph.addNode();
5.75 + Node node = graph.addNode();
5.76 std::istringstream ls(line);
5.77 for (int i = 0; i < (int)index.size(); ++i) {
5.78 index[i]->read(ls, node);
5.79 @@ -756,20 +754,20 @@
5.80 ///
5.81 /// It reads an id from the stream and gives back which node belongs to
5.82 /// it. It is possible only if there was read an "id" named map.
5.83 - Item readId(std::istream& is) const {
5.84 + Node readId(std::istream& is, Node = Node()) const {
5.85 return inverter->read(is);
5.86 }
5.87
5.88 private:
5.89
5.90 - typedef std::map<std::string, ReaderBase<Item>*> MapReaders;
5.91 + typedef std::map<std::string, ReaderBase<Node>*> MapReaders;
5.92 MapReaders readers;
5.93
5.94 typename SmartReference<Graph>::Type graph;
5.95 std::string id;
5.96 - SkipReader<Item, DefaultSkipper> skipper;
5.97 + SkipReader<Node, DefaultSkipper> skipper;
5.98
5.99 - std::auto_ptr<InverterBase<Item> > inverter;
5.100 + std::auto_ptr<InverterBase<Node> > inverter;
5.101 };
5.102
5.103 /// \ingroup io_group
5.104 @@ -801,7 +799,8 @@
5.105
5.106 typedef _Graph Graph;
5.107 typedef _Traits Traits;
5.108 - typedef typename Graph::Edge Item;
5.109 + typedef typename Graph::Node Node;
5.110 + typedef typename Graph::Edge Edge;
5.111 typedef typename Traits::Skipper DefaultSkipper;
5.112
5.113 /// \brief Constructor.
5.114 @@ -819,8 +818,7 @@
5.115 const std::string& _id = std::string(),
5.116 const DefaultSkipper& _skipper = DefaultSkipper())
5.117 : Parent(_reader), graph(_graph), id(_id), skipper(_skipper),
5.118 - nodeIdReader(new IdReader<typename Graph::Node, NodeIdReader>
5.119 - (_nodeIdReader)) {}
5.120 + nodeIdReader(new IdReader<Node, NodeIdReader>(_nodeIdReader)) {}
5.121
5.122 /// \brief Destructor.
5.123 ///
5.124 @@ -861,16 +859,14 @@
5.125 template <typename Reader, typename Map>
5.126 EdgeSetReader& readEdgeMap(std::string name, Map& map,
5.127 const Reader& reader = Reader()) {
5.128 - return _readMap<
5.129 - typename Traits::template Reader<typename Map::Value>, Map,
5.130 + return _readMap<Reader, Map,
5.131 typename SmartParameter<Map>::Type>(name, map, reader);
5.132 }
5.133
5.134 template <typename Reader, typename Map>
5.135 EdgeSetReader& readEdgeMap(std::string name, const Map& map,
5.136 const Reader& reader = Reader()) {
5.137 - return _readMap<
5.138 - typename Traits::template Reader<typename Map::Value>, Map,
5.139 + return _readMap<Reader, Map,
5.140 typename SmartParameter<Map>::Type>(name, map, reader);
5.141 }
5.142
5.143 @@ -885,7 +881,7 @@
5.144 throw IOParameterError(msg.message());
5.145 }
5.146 readers.insert(
5.147 - make_pair(name, new MapReader<Item, Map, Reader>(map, reader)));
5.148 + make_pair(name, new MapReader<Edge, Map, Reader>(map, reader)));
5.149 return *this;
5.150 }
5.151
5.152 @@ -902,7 +898,7 @@
5.153 msg << "Multiple read rule for edge map: " << name;
5.154 throw IOParameterError(msg.message());
5.155 }
5.156 - readers.insert(make_pair(name, new SkipReader<Item, Reader>(reader)));
5.157 + readers.insert(make_pair(name, new SkipReader<Edge, Reader>(reader)));
5.158 return *this;
5.159 }
5.160
5.161 @@ -925,7 +921,7 @@
5.162 ///
5.163 /// It reads the content of the section.
5.164 virtual void read(std::istream& is) {
5.165 - std::vector<ReaderBase<Item>* > index;
5.166 + std::vector<ReaderBase<Edge>* > index;
5.167 std::string line;
5.168
5.169 getline(is, line);
5.170 @@ -944,9 +940,9 @@
5.171 }
5.172 while (getline(is, line)) {
5.173 std::istringstream ls(line);
5.174 - typename Graph::Node from = nodeIdReader->read(ls);
5.175 - typename Graph::Node to = nodeIdReader->read(ls);
5.176 - typename Graph::Edge edge = graph.addEdge(from, to);
5.177 + Node from = nodeIdReader->read(ls);
5.178 + Node to = nodeIdReader->read(ls);
5.179 + Edge edge = graph.addEdge(from, to);
5.180 for (int i = 0; i < (int)index.size(); ++i) {
5.181 index[i]->read(ls, edge);
5.182 }
5.183 @@ -967,21 +963,21 @@
5.184 ///
5.185 /// It reads an id from the stream and gives back which edge belongs to
5.186 /// it. It is possible only if there was read an "id" named map.
5.187 - Item readId(std::istream& is) const {
5.188 + Edge readId(std::istream& is, Edge = Edge()) const {
5.189 return inverter->read(is);
5.190 }
5.191
5.192 private:
5.193
5.194 - typedef std::map<std::string, ReaderBase<Item>*> MapReaders;
5.195 + typedef std::map<std::string, ReaderBase<Edge>*> MapReaders;
5.196 MapReaders readers;
5.197
5.198 typename SmartReference<Graph>::Type graph;
5.199 std::string id;
5.200 - SkipReader<Item, DefaultSkipper> skipper;
5.201 + SkipReader<Edge, DefaultSkipper> skipper;
5.202
5.203 - std::auto_ptr<InverterBase<Item> > inverter;
5.204 - std::auto_ptr<IdReaderBase<typename Graph::Node> > nodeIdReader;
5.205 + std::auto_ptr<InverterBase<Edge> > inverter;
5.206 + std::auto_ptr<IdReaderBase<Node> > nodeIdReader;
5.207 };
5.208
5.209 /// \ingroup io_group
5.210 @@ -1018,7 +1014,9 @@
5.211
5.212 typedef _Graph Graph;
5.213 typedef _Traits Traits;
5.214 - typedef typename Graph::UndirEdge Item;
5.215 + typedef typename Graph::Node Node;
5.216 + typedef typename Graph::Edge Edge;
5.217 + typedef typename Graph::UndirEdge UndirEdge;
5.218 typedef typename Traits::Skipper DefaultSkipper;
5.219
5.220 /// \brief Constructor.
5.221 @@ -1036,8 +1034,7 @@
5.222 const std::string& _id = std::string(),
5.223 const DefaultSkipper& _skipper = DefaultSkipper())
5.224 : Parent(_reader), graph(_graph), id(_id), skipper(_skipper),
5.225 - nodeIdReader(new IdReader<typename Graph::Node, NodeIdReader>
5.226 - (_nodeIdReader)) {}
5.227 + nodeIdReader(new IdReader<Node, NodeIdReader>(_nodeIdReader)) {}
5.228
5.229 /// \brief Destructor.
5.230 ///
5.231 @@ -1100,7 +1097,7 @@
5.232 throw IOParameterError(msg.message());
5.233 }
5.234 readers.insert(
5.235 - make_pair(name, new MapReader<Item, Map, Reader>(map, reader)));
5.236 + make_pair(name, new MapReader<UndirEdge, Map, Reader>(map, reader)));
5.237 return *this;
5.238 }
5.239
5.240 @@ -1117,7 +1114,8 @@
5.241 msg << "Multiple read rule for node map: " << name;
5.242 throw IOParameterError(msg.message());
5.243 }
5.244 - readers.insert(make_pair(name, new SkipReader<Item, Reader>(reader)));
5.245 + readers.insert(make_pair(name,
5.246 + new SkipReader<UndirEdge, Reader>(reader)));
5.247 return *this;
5.248 }
5.249
5.250 @@ -1199,7 +1197,7 @@
5.251 ///
5.252 /// It reads the content of the section.
5.253 virtual void read(std::istream& is) {
5.254 - std::vector<ReaderBase<Item>* > index;
5.255 + std::vector<ReaderBase<UndirEdge>* > index;
5.256 std::string line;
5.257
5.258 getline(is, line);
5.259 @@ -1218,9 +1216,9 @@
5.260 }
5.261 while (getline(is, line)) {
5.262 std::istringstream ls(line);
5.263 - typename Graph::Node from = nodeIdReader->read(ls);
5.264 - typename Graph::Node to = nodeIdReader->read(ls);
5.265 - typename Graph::UndirEdge edge = graph.addEdge(from, to);
5.266 + Node from = nodeIdReader->read(ls);
5.267 + Node to = nodeIdReader->read(ls);
5.268 + UndirEdge edge = graph.addEdge(from, to);
5.269 for (int i = 0; i < (int)index.size(); ++i) {
5.270 index[i]->read(ls, edge);
5.271 }
5.272 @@ -1241,21 +1239,41 @@
5.273 ///
5.274 /// It reads an id from the stream and gives back which undirected edge
5.275 /// belongs to it. It is possible only if there was read an "id" named map.
5.276 - Item readId(std::istream& is) const {
5.277 + UndirEdge readId(std::istream& is, UndirEdge = UndirEdge()) const {
5.278 return inverter->read(is);
5.279 }
5.280
5.281 + /// \brief Gives back the directed edge by its id.
5.282 + ///
5.283 + /// It reads an id from the stream and gives back which directed edge
5.284 + /// belongs to it. The directed edge id is the \c '+' or \c '-' character
5.285 + /// and the undirected edge id. It is possible only if there was read
5.286 + /// an "id" named map.
5.287 + Edge readId(std::istream& is, Edge = Edge()) const {
5.288 + char c;
5.289 + is >> c;
5.290 + UndirEdge undirEdge = inverter->read(is);
5.291 + if (c == '+') {
5.292 + return graph.edgeWithSource(undirEdge, graph.source(undirEdge));
5.293 + } else if (c == '-') {
5.294 + return graph.edgeWithSource(undirEdge, graph.target(undirEdge));
5.295 + } else {
5.296 + throw DataFormatError("Wrong id format for edge "
5.297 + "in undirected edgeset");
5.298 + }
5.299 + }
5.300 +
5.301 private:
5.302
5.303 - typedef std::map<std::string, ReaderBase<Item>*> MapReaders;
5.304 + typedef std::map<std::string, ReaderBase<UndirEdge>*> MapReaders;
5.305 MapReaders readers;
5.306
5.307 typename SmartReference<Graph>::Type graph;
5.308 std::string id;
5.309 - SkipReader<Item, DefaultSkipper> skipper;
5.310 + SkipReader<UndirEdge, DefaultSkipper> skipper;
5.311
5.312 - std::auto_ptr<InverterBase<Item> > inverter;
5.313 - std::auto_ptr<IdReaderBase<typename Graph::Node> > nodeIdReader;
5.314 + std::auto_ptr<InverterBase<UndirEdge> > inverter;
5.315 + std::auto_ptr<IdReaderBase<Node> > nodeIdReader;
5.316 };
5.317
5.318 /// \ingroup io_group
5.319 @@ -1272,7 +1290,7 @@
5.320 class NodeReader : public CommonSectionReaderBase {
5.321 typedef CommonSectionReaderBase Parent;
5.322 typedef _Graph Graph;
5.323 - typedef typename Graph::Node Item;
5.324 + typedef typename Graph::Node Node;
5.325 public:
5.326
5.327 /// \brief Constructor.
5.328 @@ -1301,7 +1319,7 @@
5.329 /// \brief Add a node reader command for the NodeReader.
5.330 ///
5.331 /// Add a node reader command for the NodeReader.
5.332 - void readNode(const std::string& name, Item& item) {
5.333 + void readNode(const std::string& name, Node& item) {
5.334 if (readers.find(name) != readers.end()) {
5.335 ErrorMessage msg;
5.336 msg << "Multiple read rule for node: " << name;
5.337 @@ -1334,7 +1352,7 @@
5.338 std::istringstream ls(line);
5.339 std::string id;
5.340 ls >> id;
5.341 - typename ItemReaders::iterator it = readers.find(id);
5.342 + typename NodeReaders::iterator it = readers.find(id);
5.343 if (it != readers.end()) {
5.344 *(it->second) = idReader->read(ls);
5.345 }
5.346 @@ -1345,9 +1363,9 @@
5.347
5.348 std::string id;
5.349
5.350 - typedef std::map<std::string, Item*> ItemReaders;
5.351 - ItemReaders readers;
5.352 - std::auto_ptr<IdReaderBase<Item> > idReader;
5.353 + typedef std::map<std::string, Node*> NodeReaders;
5.354 + NodeReaders readers;
5.355 + std::auto_ptr<IdReaderBase<Node> > idReader;
5.356 };
5.357
5.358 /// \ingroup io_group
5.359 @@ -1364,7 +1382,7 @@
5.360 class EdgeReader : public CommonSectionReaderBase {
5.361 typedef CommonSectionReaderBase Parent;
5.362 typedef _Graph Graph;
5.363 - typedef typename Graph::Edge Item;
5.364 + typedef typename Graph::Edge Edge;
5.365 public:
5.366
5.367 /// \brief Constructor.
5.368 @@ -1392,7 +1410,7 @@
5.369 /// \brief Add an edge reader command for the EdgeReader.
5.370 ///
5.371 /// Add an edge reader command for the EdgeReader.
5.372 - void readEdge(const std::string& name, Item& item) {
5.373 + void readEdge(const std::string& name, Edge& item) {
5.374 if (readers.find(name) != readers.end()) {
5.375 ErrorMessage msg;
5.376 msg << "Multiple read rule for edge: " << name;
5.377 @@ -1425,7 +1443,7 @@
5.378 std::istringstream ls(line);
5.379 std::string id;
5.380 ls >> id;
5.381 - typename ItemReaders::iterator it = readers.find(id);
5.382 + typename EdgeReaders::iterator it = readers.find(id);
5.383 if (it != readers.end()) {
5.384 *(it->second) = idReader->read(ls);
5.385 }
5.386 @@ -1436,9 +1454,9 @@
5.387
5.388 std::string id;
5.389
5.390 - typedef std::map<std::string, Item*> ItemReaders;
5.391 - ItemReaders readers;
5.392 - std::auto_ptr<IdReaderBase<Item> > idReader;
5.393 + typedef std::map<std::string, Edge*> EdgeReaders;
5.394 + EdgeReaders readers;
5.395 + std::auto_ptr<IdReaderBase<Edge> > idReader;
5.396 };
5.397
5.398 /// \ingroup io_group
5.399 @@ -1455,7 +1473,8 @@
5.400 class UndirEdgeReader : public CommonSectionReaderBase {
5.401 typedef CommonSectionReaderBase Parent;
5.402 typedef _Graph Graph;
5.403 - typedef typename Graph::UndirEdge Item;
5.404 + typedef typename Graph::Edge Edge;
5.405 + typedef typename Graph::UndirEdge UndirEdge;
5.406 public:
5.407
5.408 /// \brief Constructor.
5.409 @@ -1469,7 +1488,8 @@
5.410 UndirEdgeReader(LemonReader& _reader, const _IdReader& _idReader,
5.411 const std::string& _id = std::string())
5.412 : Parent(_reader), id(_id),
5.413 - idReader(new IdReader<typename Graph::UndirEdge, _IdReader>(_idReader))
5.414 + undirEdgeIdReader(new IdReader<UndirEdge, _IdReader>(_idReader)),
5.415 + edgeIdReader(new IdReader<Edge, _IdReader>(_idReader))
5.416 {}
5.417
5.418 /// \brief Destructor.
5.419 @@ -1485,13 +1505,25 @@
5.420 /// \brief Add an undirected edge reader command for the UndirEdgeReader.
5.421 ///
5.422 /// Add an undirected edge reader command for the UndirEdgeReader.
5.423 - void readUndirEdge(const std::string& name, Item& item) {
5.424 - if (readers.find(name) != readers.end()) {
5.425 + void readUndirEdge(const std::string& name, UndirEdge& item) {
5.426 + if (undirEdgeReaders.find(name) != undirEdgeReaders.end()) {
5.427 + ErrorMessage msg;
5.428 + msg << "Multiple read rule for undirected edge: " << name;
5.429 + throw IOParameterError(msg.message());
5.430 + }
5.431 + undirEdgeReaders.insert(make_pair(name, &item));
5.432 + }
5.433 +
5.434 + /// \brief Add an edge reader command for the UndirEdgeReader.
5.435 + ///
5.436 + /// Add an edge reader command for the UndirEdgeReader.
5.437 + void readEdge(const std::string& name, Edge& item) {
5.438 + if (edgeReaders.find(name) != edgeReaders.end()) {
5.439 ErrorMessage msg;
5.440 msg << "Multiple read rule for edge: " << name;
5.441 throw IOParameterError(msg.message());
5.442 }
5.443 - readers.insert(make_pair(name, &item));
5.444 + edgeReaders.insert(make_pair(name, &item));
5.445 }
5.446
5.447 protected:
5.448 @@ -1506,7 +1538,7 @@
5.449 std::string command;
5.450 std::string name;
5.451 ls >> command >> name;
5.452 - return command == "@edges" && name == id;
5.453 + return command == "@undiredges" && name == id;
5.454 }
5.455
5.456 /// \brief Reader function of the section.
5.457 @@ -1518,10 +1550,19 @@
5.458 std::istringstream ls(line);
5.459 std::string id;
5.460 ls >> id;
5.461 - typename ItemReaders::iterator it = readers.find(id);
5.462 - if (it != readers.end()) {
5.463 - *(it->second) = idReader->read(ls);
5.464 - }
5.465 + {
5.466 + typename UndirEdgeReaders::iterator it = undirEdgeReaders.find(id);
5.467 + if (it != undirEdgeReaders.end()) {
5.468 + *(it->second) = undirEdgeIdReader->read(ls);
5.469 + break;
5.470 + }
5.471 + } {
5.472 + typename EdgeReaders::iterator it = edgeReaders.find(id);
5.473 + if (it != edgeReaders.end()) {
5.474 + *(it->second) = edgeIdReader->read(ls);
5.475 + break;
5.476 + }
5.477 + }
5.478 }
5.479 }
5.480
5.481 @@ -1529,9 +1570,13 @@
5.482
5.483 std::string id;
5.484
5.485 - typedef std::map<std::string, Item*> ItemReaders;
5.486 - ItemReaders readers;
5.487 - std::auto_ptr<IdReaderBase<Item> > idReader;
5.488 + typedef std::map<std::string, UndirEdge*> UndirEdgeReaders;
5.489 + UndirEdgeReaders undirEdgeReaders;
5.490 + std::auto_ptr<IdReaderBase<UndirEdge> > undirEdgeIdReader;
5.491 +
5.492 + typedef std::map<std::string, Edge*> EdgeReaders;
5.493 + EdgeReaders edgeReaders;
5.494 + std::auto_ptr<IdReaderBase<Edge> > edgeIdReader;
5.495 };
5.496
5.497 /// \ingroup io_group
6.1 --- a/src/lemon/lemon_writer.h Thu May 19 11:46:42 2005 +0000
6.2 +++ b/src/lemon/lemon_writer.h Thu May 19 11:49:42 2005 +0000
6.3 @@ -243,7 +243,7 @@
6.4 : idWriter(_idWriter) {}
6.5
6.6 virtual void write(std::ostream& os, const Item& item) const {
6.7 - return idWriter.writeId(os, item);
6.8 + idWriter.writeId(os, item);
6.9 }
6.10 };
6.11 };
6.12 @@ -273,7 +273,7 @@
6.13
6.14 typedef _Graph Graph;
6.15 typedef _Traits Traits;
6.16 - typedef typename Graph::Node Item;
6.17 + typedef typename Graph::Node Node;
6.18
6.19 /// \brief Constructor.
6.20 ///
6.21 @@ -319,7 +319,7 @@
6.22 NodeSetWriter& writeNodeMap(std::string name, const Map& map,
6.23 const Writer& writer = Writer()) {
6.24 writers.push_back(
6.25 - make_pair(name, new MapWriter<Item, Map, Writer>(map, writer)));
6.26 + make_pair(name, new MapWriter<Node, Map, Writer>(map, writer)));
6.27 return *this;
6.28 }
6.29
6.30 @@ -379,7 +379,7 @@
6.31 /// named map then it will write the map value belongs to the node.
6.32 /// Otherwise if the \c forceId parameter was true it will write
6.33 /// its id in the graph.
6.34 - void writeId(std::ostream& os, const Item& item) const {
6.35 + void writeId(std::ostream& os, const Node& item) const {
6.36 if (forceIdMap) {
6.37 os << graph.id(item);
6.38 } else {
6.39 @@ -389,10 +389,10 @@
6.40
6.41 private:
6.42
6.43 - typedef std::vector<std::pair<std::string, WriterBase<Item>*> > MapWriters;
6.44 + typedef std::vector<std::pair<std::string, WriterBase<Node>*> > MapWriters;
6.45 MapWriters writers;
6.46
6.47 - WriterBase<Item>* idMap;
6.48 + WriterBase<Node>* idMap;
6.49 bool forceIdMap;
6.50
6.51 typename SmartConstReference<Graph>::Type graph;
6.52 @@ -430,7 +430,8 @@
6.53
6.54 typedef _Graph Graph;
6.55 typedef _Traits Traits;
6.56 - typedef typename Graph::Edge Item;
6.57 + typedef typename Graph::Node Node;
6.58 + typedef typename Graph::Edge Edge;
6.59
6.60 /// \brief Constructor.
6.61 ///
6.62 @@ -446,8 +447,7 @@
6.63 bool _forceIdMap = true)
6.64 : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
6.65 graph(_graph), id(_id),
6.66 - nodeIdWriter(new IdWriter<typename Graph::Node, NodeIdWriter>
6.67 - (_nodeIdWriter)) {}
6.68 + nodeIdWriter(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter)) {}
6.69
6.70 /// \brief Destructor.
6.71 ///
6.72 @@ -481,7 +481,7 @@
6.73 EdgeSetWriter& writeEdgeMap(std::string name, const Map& map,
6.74 const Writer& writer = Writer()) {
6.75 writers.push_back(
6.76 - make_pair(name, new MapWriter<Item, Map, Writer>(map, writer)));
6.77 + make_pair(name, new MapWriter<Edge, Map, Writer>(map, writer)));
6.78 return *this;
6.79 }
6.80
6.81 @@ -546,7 +546,7 @@
6.82 /// named map then it will write the map value belongs to the edge.
6.83 /// Otherwise if the \c forceId parameter was true it will write
6.84 /// its id in the graph.
6.85 - void writeId(std::ostream& os, const Item& item) const {
6.86 + void writeId(std::ostream& os, const Edge& item) const {
6.87 if (forceIdMap) {
6.88 os << graph.id(item);
6.89 } else {
6.90 @@ -556,16 +556,16 @@
6.91
6.92 private:
6.93
6.94 - typedef std::vector<std::pair<std::string, WriterBase<Item>*> > MapWriters;
6.95 + typedef std::vector<std::pair<std::string, WriterBase<Edge>*> > MapWriters;
6.96 MapWriters writers;
6.97
6.98 - WriterBase<Item>* idMap;
6.99 + WriterBase<Edge>* idMap;
6.100 bool forceIdMap;
6.101
6.102 typename SmartConstReference<Graph>::Type graph;
6.103 std::string id;
6.104
6.105 - std::auto_ptr<IdWriterBase<typename Graph::Node> > nodeIdWriter;
6.106 + std::auto_ptr<IdWriterBase<Node> > nodeIdWriter;
6.107 };
6.108
6.109 /// \ingroup io_group
6.110 @@ -604,7 +604,9 @@
6.111
6.112 typedef _Graph Graph;
6.113 typedef _Traits Traits;
6.114 - typedef typename Graph::UndirEdge Item;
6.115 + typedef typename Graph::Node Node;
6.116 + typedef typename Graph::Edge Edge;
6.117 + typedef typename Graph::UndirEdge UndirEdge;
6.118
6.119 /// \brief Constructor.
6.120 ///
6.121 @@ -620,8 +622,7 @@
6.122 bool _forceIdMap = true)
6.123 : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
6.124 graph(_graph), id(_id),
6.125 - nodeIdWriter(new IdWriter<typename Graph::Node, NodeIdWriter>
6.126 - (_nodeIdWriter)) {}
6.127 + nodeIdWriter(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter)) {}
6.128
6.129 /// \brief Destructor.
6.130 ///
6.131 @@ -655,7 +656,7 @@
6.132 UndirEdgeSetWriter& writeUndirEdgeMap(std::string name, const Map& map,
6.133 const Writer& writer = Writer()) {
6.134 writers.push_back(
6.135 - make_pair(name, new MapWriter<Item, Map, Writer>(map, writer)));
6.136 + make_pair(name, new MapWriter<UndirEdge, Map, Writer>(map, writer)));
6.137 return *this;
6.138 }
6.139
6.140 @@ -742,7 +743,27 @@
6.141 /// an "id" named map then it will write the map value belongs to the
6.142 /// undirected edge. Otherwise if the \c forceId parameter was true it
6.143 /// will write its id in the graph.
6.144 - void writeId(std::ostream& os, const Item& item) const {
6.145 + void writeId(std::ostream& os, const UndirEdge& item) const {
6.146 + if (forceIdMap) {
6.147 + os << graph.id(item);
6.148 + } else {
6.149 + idMap->write(os, item);
6.150 + }
6.151 + }
6.152 +
6.153 + /// \brief Write the id of the given edge.
6.154 + ///
6.155 + /// It writes the id of the given edge. If there was written
6.156 + /// an "id" named map then it will write the map value belongs to the
6.157 + /// edge. Otherwise if the \c forceId parameter was true it
6.158 + /// will write its id in the graph. If the edge is forward map
6.159 + /// then its prefix character is \c '+' elsewhere \c '-'.
6.160 + void writeId(std::ostream& os, const Edge& item) const {
6.161 + if (graph.forward(item)) {
6.162 + os << "+ ";
6.163 + } else {
6.164 + os << "- ";
6.165 + }
6.166 if (forceIdMap) {
6.167 os << graph.id(item);
6.168 } else {
6.169 @@ -752,16 +773,17 @@
6.170
6.171 private:
6.172
6.173 - typedef std::vector<std::pair<std::string, WriterBase<Item>*> > MapWriters;
6.174 + typedef std::vector<std::pair<std::string,
6.175 + WriterBase<UndirEdge>*> > MapWriters;
6.176 MapWriters writers;
6.177
6.178 - WriterBase<Item>* idMap;
6.179 + WriterBase<UndirEdge>* idMap;
6.180 bool forceIdMap;
6.181
6.182 typename SmartConstReference<Graph>::Type graph;
6.183 std::string id;
6.184
6.185 - std::auto_ptr<IdWriterBase<typename Graph::Node> > nodeIdWriter;
6.186 + std::auto_ptr<IdWriterBase<Node> > nodeIdWriter;
6.187 };
6.188
6.189 /// \ingroup io_group
6.190 @@ -778,7 +800,7 @@
6.191 class NodeWriter : public CommonSectionWriterBase {
6.192 typedef CommonSectionWriterBase Parent;
6.193 typedef _Graph Graph;
6.194 - typedef typename Graph::Node Item;
6.195 + typedef typename Graph::Node Node;
6.196 public:
6.197
6.198 /// \brief Constructor.
6.199 @@ -806,7 +828,7 @@
6.200 /// \brief Add a node writer command for the NodeWriter.
6.201 ///
6.202 /// Add a node writer command for the NodeWriter.
6.203 - void writeNode(const std::string& name, const Item& item) {
6.204 + void writeNode(const std::string& name, const Node& item) {
6.205 writers.push_back(make_pair(name, &item));
6.206 }
6.207
6.208 @@ -835,9 +857,9 @@
6.209
6.210 std::string id;
6.211
6.212 - typedef std::vector<std::pair<std::string, const Item*> > ItemWriters;
6.213 - ItemWriters writers;
6.214 - std::auto_ptr<IdWriterBase<Item> > idWriter;
6.215 + typedef std::vector<std::pair<std::string, const Node*> > NodeWriters;
6.216 + NodeWriters writers;
6.217 + std::auto_ptr<IdWriterBase<Node> > idWriter;
6.218 };
6.219
6.220 /// \ingroup io_group
6.221 @@ -854,7 +876,7 @@
6.222 class EdgeWriter : public CommonSectionWriterBase {
6.223 typedef CommonSectionWriterBase Parent;
6.224 typedef _Graph Graph;
6.225 - typedef typename Graph::Edge Item;
6.226 + typedef typename Graph::Edge Edge;
6.227 public:
6.228
6.229 /// \brief Constructor.
6.230 @@ -881,7 +903,7 @@
6.231 /// \brief Add an edge writer command for the EdgeWriter.
6.232 ///
6.233 /// Add an edge writer command for the EdgeWriter.
6.234 - void writeEdge(const std::string& name, const Item& item) {
6.235 + void writeEdge(const std::string& name, const Edge& item) {
6.236 writers.push_back(make_pair(name, &item));
6.237 }
6.238
6.239 @@ -910,10 +932,10 @@
6.240
6.241 std::string id;
6.242
6.243 - typedef std::vector<std::pair<std::string, const Item*> > ItemWriters;
6.244 - ItemWriters writers;
6.245 + typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters;
6.246 + EdgeWriters writers;
6.247
6.248 - std::auto_ptr<IdWriterBase<Item> > idWriter;
6.249 + std::auto_ptr<IdWriterBase<Edge> > idWriter;
6.250 };
6.251
6.252 /// \ingroup io_group
6.253 @@ -930,7 +952,9 @@
6.254 class UndirEdgeWriter : public CommonSectionWriterBase {
6.255 typedef CommonSectionWriterBase Parent;
6.256 typedef _Graph Graph;
6.257 - typedef typename Graph::UndirEdge Item;
6.258 + typedef typename Graph::Node Node;
6.259 + typedef typename Graph::Edge Edge;
6.260 + typedef typename Graph::UndirEdge UndirEdge;
6.261 public:
6.262
6.263 /// \brief Constructor.
6.264 @@ -943,8 +967,8 @@
6.265 UndirEdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter,
6.266 const std::string& _id = std::string())
6.267 : Parent(_writer), id(_id),
6.268 - idWriter(new IdWriter<typename Graph::UndirEdge, _IdWriter>
6.269 - (_idWriter)) {}
6.270 + undirEdgeIdWriter(new IdWriter<UndirEdge, _IdWriter>(_idWriter)),
6.271 + edgeIdWriter(new IdWriter<Edge, _IdWriter>(_idWriter)) {}
6.272
6.273 /// \brief Destructor.
6.274 ///
6.275 @@ -956,11 +980,18 @@
6.276
6.277 public:
6.278
6.279 + /// \brief Add an edge writer command for the UndirEdgeWriter.
6.280 + ///
6.281 + /// Add an edge writer command for the UndirEdgeWriter.
6.282 + void writeEdge(const std::string& name, const Edge& item) {
6.283 + edgeWriters.push_back(make_pair(name, &item));
6.284 + }
6.285 +
6.286 /// \brief Add an undirected edge writer command for the UndirEdgeWriter.
6.287 ///
6.288 - /// Add an edge writer command for the UndirEdgeWriter.
6.289 - void writeUndirEdge(const std::string& name, const Item& item) {
6.290 - writers.push_back(make_pair(name, &item));
6.291 + /// Add an undirected edge writer command for the UndirEdgeWriter.
6.292 + void writeUndirEdge(const std::string& name, const UndirEdge& item) {
6.293 + undirEdgeWriters.push_back(make_pair(name, &item));
6.294 }
6.295
6.296 protected:
6.297 @@ -970,16 +1001,21 @@
6.298 /// It gives back true when the header line start with \c \@undiredges,
6.299 /// and the header line's id and the writer's id are the same.
6.300 virtual std::string header() {
6.301 - return "@edges " + id;
6.302 + return "@undiredges " + id;
6.303 }
6.304
6.305 /// \brief Writer function of the section.
6.306 ///
6.307 /// Write the content of the section.
6.308 virtual void write(std::ostream& os) {
6.309 - for (int i = 0; i < (int)writers.size(); ++i) {
6.310 - os << writers[i].first << ' ';
6.311 - idWriter->write(os, *(writers[i].second));
6.312 + for (int i = 0; i < (int)undirEdgeWriters.size(); ++i) {
6.313 + os << undirEdgeWriters[i].first << ' ';
6.314 + undirEdgeIdWriter->write(os, *(undirEdgeWriters[i].second));
6.315 + os << std::endl;
6.316 + }
6.317 + for (int i = 0; i < (int)edgeWriters.size(); ++i) {
6.318 + os << edgeWriters[i].first << ' ';
6.319 + edgeIdWriter->write(os, *(edgeWriters[i].second));
6.320 os << std::endl;
6.321 }
6.322 }
6.323 @@ -988,10 +1024,15 @@
6.324
6.325 std::string id;
6.326
6.327 - typedef std::vector<std::pair<std::string, const Item*> > ItemWriters;
6.328 - ItemWriters writers;
6.329 + typedef std::vector<std::pair<std::string,
6.330 + const UndirEdge*> > UndirEdgeWriters;
6.331 + UndirEdgeWriters undirEdgeWriters;
6.332 + std::auto_ptr<IdWriterBase<UndirEdge> > undirEdgeIdWriter;
6.333
6.334 - std::auto_ptr<IdWriterBase<Item> > idWriter;
6.335 + typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters;
6.336 + EdgeWriters edgeWriters;
6.337 + std::auto_ptr<IdWriterBase<Edge> > edgeIdWriter;
6.338 +
6.339 };
6.340
6.341 /// \ingroup io_group