Changeset 1901:723b2b81d900 in lemon-0.x
- Timestamp:
- 01/24/06 17:07:38 (18 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2476
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
demo/coloring.lgf
r1683 r1901 1 1 @nodeset 2 coords id2 coords label 3 3 (162, 142) 10 4 4 (169, -35) 9 … … 13 13 (-282, -149) 0 14 14 @undiredgeset 15 id15 label 16 16 9 10 17 17 17 1 9 15 -
demo/dir_components.lgf
r1802 r1901 1 1 @nodeset 2 coordinates_x coordinates_y id2 coordinates_x coordinates_y label 3 3 218.178 27.2723 19 4 4 157.79 -130.517 18 … … 21 21 -389.604 -136.361 1 22 22 @edgeset 23 id23 label 24 24 17 19 23 25 25 19 18 24 -
demo/graph_orientation.cc
r1875 r1901 50 50 51 51 ListGraph::NodeMap<int> f(g); //in-deg requirement; 52 ListGraph::NodeMap<int> id(g);52 ListGraph::NodeMap<int> label(g); 53 53 ListGraph::NodeMap<xy<double> > coords(g); 54 54 … … 56 56 GraphReader<ListGraph> reader(argv[1],g); 57 57 reader.readNodeMap("f",f); 58 reader.readNodeMap(" id",id);58 reader.readNodeMap("label",label); 59 59 reader.readNodeMap("coordinates_x",xMap(coords)); 60 60 reader.readNodeMap("coordinates_y",yMap(coords)); … … 81 81 Node act; 82 82 while((act=IterableBoolNodeMap<ListGraph>::TrueIt(active))!=INVALID) { 83 std::cout << "Process node " << id[act]83 std::cout << "Process node " << label[act] 84 84 << " (def=" << def[act] 85 85 << " lev=" << level[act] << "): "; … … 88 88 if(e!=INVALID) { 89 89 std::cout << " REVERT EDGE " << g.id(e) 90 << " (" << id[g.source(e)] << "---"91 << id[g.target(e)] << ")"90 << " (" << label[g.source(e)] << "---" 91 << label[g.target(e)] << ")" 92 92 << std::endl; 93 93 if(--def[act]==0) active[act]=false; -
demo/graph_orientation.lgf
r1687 r1901 1 1 @nodeset 2 coordinates_x coordinates_y f id2 coordinates_x coordinates_y f label 3 3 -198 -73 2 7 4 4 120 30 4 6 … … 9 9 -131 83 3 1 10 10 @edgeset 11 id11 label 12 12 7 6 3 13 13 1 6 2 -
demo/partitions.lgf
r1802 r1901 1 1 @nodeset 2 coordinates_x coordinates_y id2 coordinates_x coordinates_y label 3 3 513.857 -446.322 23 4 4 393.468 566.711 22 … … 25 25 -274 -131 1 26 26 @undiredgeset 27 id27 label 28 28 12 23 15 29 29 13 23 14 -
demo/route.lgf
r1530 r1901 1 1 @nodeset 2 idcoordinates_x coordinates_y2 label coordinates_x coordinates_y 3 3 9 447.907 578.328 4 4 8 79.2573 909.464 … … 12 12 0 189.239 92.5316 13 13 @edgeset 14 length id14 length label 15 15 2 3 901.074 0 16 16 8 5 270.85 1 -
demo/sample.lgf
r1541 r1901 1 1 @nodeset 2 idcoordinates_x coordinates_y2 label coordinates_x coordinates_y 3 3 5 796.398 208.035 4 4 4 573.002 63.002 … … 8 8 0 102.239 257.532 9 9 @edgeset 10 idcapacity10 label capacity 11 11 4 5 6 8 12 12 3 5 5 8 -
demo/sub_gad_input.lgf
r1577 r1901 1 1 @nodeset 2 id 2 label 3 3 6 4 4 5 … … 9 9 0 10 10 @edgeset 11 idlength11 label length 12 12 5 6 9 4 13 13 4 6 8 2 -
demo/undir_components.lgf
r1802 r1901 1 1 @nodeset 2 coordinates_x coordinates_y id2 coordinates_x coordinates_y label 3 3 574.035 177.301 44 4 4 694.579 115.483 43 … … 45 45 -567.302 43.6423 33 46 46 @undiredgeset 47 id47 label 48 48 41 42 44 49 49 40 42 43 -
doc/graph_io.dox
r1848 r1901 32 32 The next line contains the names of the nodemaps, separated by whitespaces. Each 33 33 following line describes a node in the graph: it contains the values of the 34 maps in the right order. The map named " id" should contain unique values35 because it is regarded as a n ID-map. These ids need not be numbers but they34 maps in the right order. The map named "label" should contain unique values 35 because it is regarded as a label map. These labels need not be numbers but they 36 36 must identify the nodes uniquely for later reference. For example: 37 37 38 38 \code 39 39 @nodeset 40 idx-coord y-coord color40 label x-coord y-coord color 41 41 3 1.0 4.0 blue 42 42 5 2.3 5.7 red … … 51 51 The next line contains the whitespace separated list of names of the edge 52 52 maps. Each of the next lines describes one edge. The first two elements in 53 the line are the IDs of the source and target (or tail and head) nodes of the54 edge as they occur in the IDnode map of the nodeset section. You can also55 have an optional IDmap on the edges for later reference (which has to be53 the line are the labels of the source and target (or tail and head) nodes of the 54 edge as they occur in the label node map of the nodeset section. You can also 55 have an optional label map on the edges for later reference (which has to be 56 56 unique in this case). 57 57 58 58 \code 59 59 @edgeset 60 id weight label61 3 5 a 4.3 a-edge62 5 12 c 2.6 c-edge63 3 12 g 3.4 g-edge60 label weight note 61 3 5 a 4.3 a-edge 62 5 12 c 2.6 c-edge 63 3 12 g 3.4 g-edge 64 64 \endcode 65 65 … … 71 71 72 72 Each of the next lines contains a label for a node in the graph 73 and then the IDas described in the \e nodeset section.73 and then the label as described in the \e nodeset section. 74 74 75 75 \code … … 81 81 The last section describes the <em>labeled (distinguished) edges</em> 82 82 (i.e. edges having a special label on them). It starts with \c \@edges 83 and then each line contains the name of the edge and the ID.83 and then each line contains the name of the edge and the label. 84 84 85 85 \code … … 104 104 \endcode 105 105 106 <tt> \@end </tt> 107 108 line. 106 Finally, the file should be closed with \c \@end line. 109 107 110 108 … … 133 131 \ref lemon::GraphWriter "GraphWriter". 134 132 You should give a name to the map and the map 135 object as parameters. The NodeMap writing command with name " id" should write a136 unique map because it will be regarded as a n IDmap.133 object as parameters. The NodeMap writing command with name "label" should write a 134 unique map because it will be regarded as a label map. 137 135 138 136 \see IdMap, DescriptorMap 139 137 140 138 \code 141 IdMap<ListGraph, Node> node IdMap;142 writer.writeNodeMap(" id", nodeIdMap);139 IdMap<ListGraph, Node> nodeLabelMap; 140 writer.writeNodeMap("label", nodeLabelMap); 143 141 144 142 writer.writeNodeMap("x-coord", xCoordMap); … … 158 156 159 157 writer.writeEdgeMap("weight", weightMap); 160 writer.writeEdgeMap(" label", labelMap);158 writer.writeEdgeMap("note", noteMap); 161 159 \endcode 162 160 … … 315 313 special template parameter to the GraphReader class. By default, the 316 314 template parameter is \c DefaultReaderTraits. A reader traits class 317 should provide a n innertemplate class Reader for each type, and a315 should provide a nested template class Reader for each type, and a 318 316 DefaultReader for skipping a value. 319 317 320 The specialization of 318 The specialization of writing is very similar to that of reading. 321 319 322 320 \section undir Undirected graphs … … 334 332 \code 335 333 @undiredgeset 336 id capacity +flow-flow337 32 2 1 4.3 2.00.0338 21 21 5 2.6 0.02.6339 21 12 8 3.4 0.00.0334 label capacity +flow -flow 335 32 2 1 4.3 2.0 0.0 336 21 21 5 2.6 0.0 2.6 337 21 12 8 3.4 0.0 0.0 340 338 \endcode 341 339 … … 462 460 and the \ref lemon::UndirGraphReader "UndirGraphReader" can be converted 463 461 to \ref lemon::LemonReader "LemonReader" 464 and it can resolve the ID's of the items, the previous462 and it can resolve the label's of the items, the previous 465 463 result can be achived with the \ref lemon::UndirGraphReader "UndirGraphReader" 466 464 class, too. -
gui/graphocska.lgf
r1581 r1901 1 1 @nodeset 2 idcoordinates_x coordinates_y data2 label coordinates_x coordinates_y data 3 3 1 230 -80 1.123 4 4 2 230 100 3.234 -
lemon/graph_reader.h
r1875 r1901 68 68 /// reader.readNodeMap("coords", coords); 69 69 /// 70 /// reader.readNodeMap<QuotedStringReader>("label", labelMap); 71 /// reader.skipNodeMap<QuotedStringReader>("description"); 70 /// reader.skipNodeMap("description", desc); 72 71 /// 73 72 /// reader.readNodeMap("color", colorMap); … … 307 306 } 308 307 309 /// \brief Gives back the node by its id. 310 /// 311 /// It reads an id from the stream and gives back which node belongs to 312 /// it. It is possible only if there was read an "id" named node map. 313 Node readId(std::istream& is, Node) const { 314 return nodeset_reader.readId(is, Node()); 308 309 /// \brief Returns true if the reader can give back the items by its label. 310 /// 311 /// \brief Returns true if the reader can give back the items by its label. 312 bool isLabelReader() const { 313 return nodeset_reader.isLabelReader() && edgeset_reader.isLabelReader(); 314 } 315 316 /// \brief Gives back the node by its label. 317 /// 318 /// It reads an label from the stream and gives back which node belongs to 319 /// it. It is possible only if there was read an "label" named node map. 320 void readLabel(std::istream& is, Node& node) const { 321 nodeset_reader.readLabel(is, node); 315 322 } 316 323 317 /// \brief Gives back the edge by its id.318 /// 319 /// It reads an idfrom the stream and gives back which edge belongs to320 /// it. It is possible only if there was read an " id" named edge map.321 Edge readId(std::istream& is, Edge) const {322 return edgeset_reader.read Id(is, Edge());324 /// \brief Gives back the edge by its label. 325 /// 326 /// It reads an label from the stream and gives back which edge belongs to 327 /// it. It is possible only if there was read an "label" named edge map. 328 void readLabel(std::istream& is, Edge& edge) const { 329 return edgeset_reader.readLabel(is, edge); 323 330 } 324 331 … … 405 412 /// reader.readNodeMap("coords", coords); 406 413 /// 407 /// reader.readNodeMap<QuotedStringReader>("label", labelMap); 408 /// reader.skipNodeMap<QuotedStringReader>("description"); 414 /// reader.skipNodeMap("description", desc); 409 415 /// 410 416 /// reader.readNodeMap("color", colorMap); … … 705 711 } 706 712 707 /// \brief Gives back the node by its id. 708 /// 709 /// It reads an id from the stream and gives back which node belongs to 710 /// it. It is possible only if there was read an "id" named node map. 711 Node readId(std::istream& is, Node) const { 712 return nodeset_reader.readId(is, Node()); 713 714 /// \brief Returns true if the reader can give back the items by its label. 715 /// 716 /// \brief Returns true if the reader can give back the items by its label. 717 bool isLabelReader() const { 718 return nodeset_reader.isLabelReader() && 719 undir_edgeset_reader.isLabelReader(); 720 } 721 722 /// \brief Gives back the node by its label. 723 /// 724 /// It reads an label from the stream and gives back which node belongs to 725 /// it. It is possible only if there was read an "label" named node map. 726 void readLabel(std::istream& is, Node& node) const { 727 return nodeset_reader.readLabel(is, node); 713 728 } 714 729 715 /// \brief Gives back the edge by its id.716 /// 717 /// It reads an idfrom the stream and gives back which edge belongs to718 /// it. It is possible only if there was read an " id" named edge map.719 Edge readId(std::istream& is, Edge) const {720 return undir_edgeset_reader.read Id(is, Edge());730 /// \brief Gives back the edge by its label. 731 /// 732 /// It reads an label from the stream and gives back which edge belongs to 733 /// it. It is possible only if there was read an "label" named edge map. 734 void readLabel(std::istream& is, Edge& edge) const { 735 return undir_edgeset_reader.readLabel(is, edge); 721 736 } 722 737 723 /// \brief Gives back the undirected edge by its id.724 /// 725 /// It reads an idfrom the stream and gives back which undirected edge726 /// belongs to it. It is possible only if there was read an " id" named738 /// \brief Gives back the undirected edge by its label. 739 /// 740 /// It reads an label from the stream and gives back which undirected edge 741 /// belongs to it. It is possible only if there was read an "label" named 727 742 /// edge map. 728 UndirEdge readId(std::istream& is, UndirEdge) const {729 return undir_edgeset_reader.read Id(is, UndirEdge());743 void readLabel(std::istream& is, UndirEdge& uedge) const { 744 return undir_edgeset_reader.readLabel(is, uedge); 730 745 } 731 746 -
lemon/graph_writer.h
r1875 r1901 55 55 /// command in the \c GraphWriter. You should give as parameter 56 56 /// the name of the map and the map object. The NodeMap writing 57 /// command with name " id" should write a unique map because it58 /// is regarded as IDmap (such a map is essential if the graph has edges).59 /// 60 /// \code 61 /// IdMap<ListGraph, Node> node IdMap;62 /// writer.writeNodeMap(" id", nodeIdMap);57 /// command with name "label" should write a unique map because it 58 /// is regarded as label map (such a map is essential if the graph has edges). 59 /// 60 /// \code 61 /// IdMap<ListGraph, Node> nodeLabelMap; 62 /// writer.writeNodeMap("label", nodeLabelMap); 63 63 /// 64 64 /// writer.writeNodeMap("coords", coords); … … 254 254 } 255 255 256 /// \brief Write the idof the given node.257 /// 258 /// It writes the id of the given node. If there was written an "id"256 /// \brief Write the label of the given node. 257 /// 258 /// It writes the label of the given node. If there was written an "label" 259 259 /// named node map then it will write the map value belonging to the node. 260 void write Id(std::ostream& os, const Node& item) const {261 nodeset_writer.write Id(os, item);260 void writeLabel(std::ostream& os, const Node& item) const { 261 nodeset_writer.writeLabel(os, item); 262 262 } 263 263 264 /// \brief Write the idof the given edge.265 /// 266 /// It writes the id of the given edge. If there was written an "id"264 /// \brief Write the label of the given edge. 265 /// 266 /// It writes the label of the given edge. If there was written an "label" 267 267 /// named edge map then it will write the map value belonging to the edge. 268 void write Id(std::ostream& os, const Edge& item) const {269 edgeset_writer.write Id(os, item);268 void writeLabel(std::ostream& os, const Edge& item) const { 269 edgeset_writer.writeLabel(os, item); 270 270 } 271 271 … … 328 328 /// command in the \c UndirGraphWriter. You should give as parameter 329 329 /// the name of the map and the map object. The NodeMap writing 330 /// command with name " id" should write a unique map because it331 /// is regarded as IDmap.332 /// 333 /// \code 334 /// IdMap<UndirListGraph, Node> node IdMap;335 /// writer.writeNodeMap(" id", nodeIdMap);330 /// command with name "label" should write a unique map because it 331 /// is regarded as label map. 332 /// 333 /// \code 334 /// IdMap<UndirListGraph, Node> nodeLabelMap; 335 /// writer.writeNodeMap("label", nodeLabelMap); 336 336 /// 337 337 /// writer.writeNodeMap("coords", coords); … … 562 562 } 563 563 564 /// \brief Write the idof the given node.565 /// 566 /// It writes the id of the given node. If there was written an "id"564 /// \brief Write the label of the given node. 565 /// 566 /// It writes the label of the given node. If there was written an "label" 567 567 /// named node map then it will write the map value belonging to the node. 568 void write Id(std::ostream& os, const Node& item) const {569 nodeset_writer.write Id(os, item);568 void writeLabel(std::ostream& os, const Node& item) const { 569 nodeset_writer.writeLabel(os, item); 570 570 } 571 571 572 /// \brief Write the idof the given edge.573 /// 574 /// It writes the id of the given edge. If there was written an "id"572 /// \brief Write the label of the given edge. 573 /// 574 /// It writes the label of the given edge. If there was written an "label" 575 575 /// named edge map then it will write the map value belonging to the edge. 576 void write Id(std::ostream& os, const Edge& item) const {577 undir_edgeset_writer.write Id(os, item);576 void writeLabel(std::ostream& os, const Edge& item) const { 577 undir_edgeset_writer.writeLabel(os, item); 578 578 } 579 579 580 /// \brief Write the idof the given undirected edge.581 /// 582 /// It writes the idof the given undirected edge. If there was written583 /// an " id" named edge map then it will write the map value belonging to580 /// \brief Write the label of the given undirected edge. 581 /// 582 /// It writes the label of the given undirected edge. If there was written 583 /// an "label" named edge map then it will write the map value belonging to 584 584 /// the edge. 585 void write Id(std::ostream& os, const UndirEdge& item) const {586 undir_edgeset_writer.write Id(os, item);585 void writeLabel(std::ostream& os, const UndirEdge& item) const { 586 undir_edgeset_writer.writeLabel(os, item); 587 587 } 588 588 -
lemon/lemon_reader.h
r1875 r1901 48 48 template <typename T> 49 49 bool operator<(T, T) { 50 throw DataFormatError(" Idis not comparable");50 throw DataFormatError("Label is not comparable"); 51 51 } 52 52 … … 59 59 60 60 template <typename Item> 61 class Item IdReader {61 class ItemLabelReader { 62 62 public: 63 63 64 bool is IdReader() { return true; }65 66 void read Id(std::istream&, Item&) {}64 bool isLabelReader() { return true; } 65 66 void readLabel(std::istream&, Item&) {} 67 67 68 template <class _Item IdReader>68 template <class _ItemLabelReader> 69 69 struct Constraints { 70 70 void constraints() { 71 bool b = reader.is IdReader();71 bool b = reader.isLabelReader(); 72 72 ignore_unused_variable_warning(b); 73 73 Item item; 74 reader.read Id(is, item);75 } 76 _Item IdReader& reader;74 reader.readLabel(is, item); 75 } 76 _ItemLabelReader& reader; 77 77 std::istream& is; 78 78 }; … … 242 242 inverse.insert(std::make_pair(value, item)); 243 243 } else { 244 throw DataFormatError("Multiple IDoccurence");244 throw DataFormatError("Multiple label occurence"); 245 245 } 246 246 } … … 253 253 return it->second; 254 254 } else { 255 throw DataFormatError("Invalid IDerror");255 throw DataFormatError("Invalid label error"); 256 256 } 257 257 } … … 280 280 inverse.insert(std::make_pair(value, item)); 281 281 } else { 282 throw DataFormatError("Multiple IDoccurence error");282 throw DataFormatError("Multiple label occurence error"); 283 283 } 284 284 } … … 291 291 return it->second; 292 292 } else { 293 throw DataFormatError("Invalid IDerror");293 throw DataFormatError("Invalid label error"); 294 294 } 295 295 } … … 371 371 372 372 template <typename _Item> 373 class IdReaderBase {373 class LabelReaderBase { 374 374 public: 375 375 typedef _Item Item; 376 virtual ~ IdReaderBase() {}376 virtual ~LabelReaderBase() {} 377 377 virtual Item read(std::istream& is) const = 0; 378 virtual bool is IdReader() const = 0;379 }; 380 381 template <typename _Item, typename _Boxed IdReader>382 class IdReader : public IdReaderBase<_Item> {378 virtual bool isLabelReader() const = 0; 379 }; 380 381 template <typename _Item, typename _BoxedLabelReader> 382 class LabelReader : public LabelReaderBase<_Item> { 383 383 public: 384 384 typedef _Item Item; 385 typedef _Boxed IdReader BoxedIdReader;385 typedef _BoxedLabelReader BoxedLabelReader; 386 386 387 const Boxed IdReader& boxedIdReader;388 389 IdReader(const BoxedIdReader& _boxedIdReader)390 : boxed IdReader(_boxedIdReader) {}387 const BoxedLabelReader& boxedLabelReader; 388 389 LabelReader(const BoxedLabelReader& _boxedLabelReader) 390 : boxedLabelReader(_boxedLabelReader) {} 391 391 392 392 virtual Item read(std::istream& is) const { 393 393 Item item; 394 boxed IdReader.readId(is, item);394 boxedLabelReader.readLabel(is, item); 395 395 return item; 396 396 } 397 397 398 virtual bool is IdReader() const {399 return boxed IdReader.isIdReader();398 virtual bool isLabelReader() const { 399 return boxedLabelReader.isLabelReader(); 400 400 } 401 401 }; … … 728 728 /// 729 729 /// The lemon format can store multiple graph nodesets with several maps. 730 /// The nodeset section's header line is \c \@nodeset \c nodeset_ id, but the731 /// \c nodeset_ idmay be empty.730 /// The nodeset section's header line is \c \@nodeset \c nodeset_name, but the 731 /// \c nodeset_name may be empty. 732 732 /// 733 733 /// The first line of the section contains the names of the maps separated … … 735 735 /// contains the mapped values for each map. 736 736 /// 737 /// If the nodeset contains an \c " id" named map then it will be regarded737 /// If the nodeset contains an \c "label" named map then it will be regarded 738 738 /// as id map. This map should contain only unique values and when the 739 /// \c read Id() member will read a value from the given stream it will739 /// \c readLabel() member will read a value from the given stream it will 740 740 /// give back that node which is mapped to this value. 741 741 /// … … 756 756 /// attach it into the given LemonReader. The nodeset reader will 757 757 /// add the readed nodes to the given Graph. The reader will read 758 /// the section when the \c section_ id and the \c _idare the same.758 /// the section when the \c section_name and the \c _name are the same. 759 759 NodeSetReader(LemonReader& _reader, 760 760 Graph& _graph, 761 const std::string& _ id= std::string(),761 const std::string& _name = std::string(), 762 762 const DefaultSkipper& _skipper = DefaultSkipper()) 763 : Parent(_reader), graph(_graph), id(_id), skipper(_skipper) {}763 : Parent(_reader), graph(_graph), name(_name), skipper(_skipper) {} 764 764 765 765 … … 856 856 /// 857 857 /// It gives back true when the header line starts with \c \@nodeset, 858 /// and the header line's id and the nodeset's idare the same.858 /// and the header line's name and the nodeset's name are the same. 859 859 virtual bool header(const std::string& line) { 860 860 std::istringstream ls(line); 861 861 std::string command; 862 std::string name;862 std::string id; 863 863 ls >> command >> name; 864 864 return command == "@nodeset" && name == id; … … 873 873 874 874 getline(is, line); 875 std::istringstream ls(line); 875 std::istringstream ls(line); 876 std::string id; 876 877 while (ls >> id) { 877 878 typename MapReaders::iterator it = readers.find(id); … … 882 883 index.push_back(&skipper); 883 884 } 884 if (id == " id" && inverter.get() == 0) {885 if (id == "label" || (id =="id" && inverter.get() == 0)) { 885 886 inverter.reset(index.back()->getInverter()); 886 887 index.back() = inverter.get(); … … 906 907 public: 907 908 908 /// \brief Returns true if the nodeset can give back the node by its id.909 /// 910 /// Returns true if the nodeset can give back the node by its id.911 /// It is possible only if an " id" named map was read.912 bool is IdReader() const {909 /// \brief Returns true if the nodeset can give back the node by its label. 910 /// 911 /// Returns true if the nodeset can give back the node by its label. 912 /// It is possible only if an "label" named map was read. 913 bool isLabelReader() const { 913 914 return inverter.get() != 0; 914 915 } 915 916 916 /// \brief Gives back the node by its id.917 /// \brief Gives back the node by its label. 917 918 /// 918 919 /// It reads an id from the stream and gives back which node belongs to 919 /// it. It is possible only if there was read an " id" named map.920 void read Id(std::istream& is, Node& node) const {920 /// it. It is possible only if there was read an "label" named map. 921 void readLabel(std::istream& is, Node& node) const { 921 922 node = inverter->read(is); 922 923 } … … 928 929 929 930 Graph& graph; 930 std::string id;931 std::string name; 931 932 _reader_bits::SkipReader<Node, DefaultSkipper> skipper; 932 933 … … 938 939 /// 939 940 /// The lemon format can store multiple graph edgesets with several maps. 940 /// The edgeset section's header line is \c \@edgeset \c edgeset_ id, but the941 /// \c edgeset_ idmay be empty.941 /// The edgeset section's header line is \c \@edgeset \c edgeset_name, but the 942 /// \c edgeset_name may be empty. 942 943 /// 943 944 /// The first line of the section contains the names of the maps separated … … 946 947 /// values for each map. 947 948 /// 948 /// If the edgeset contains an \c " id" named map then it will be regarded949 /// If the edgeset contains an \c "label" named map then it will be regarded 949 950 /// as id map. This map should contain only unique values and when the 950 /// \c read Id() member will read a value from the given stream it will951 /// \c readLabel() member will read a value from the given stream it will 951 952 /// give back that edge which is mapped to this value. 952 953 /// 953 954 /// The edgeset reader needs a node id reader to identify which nodes 954 /// have to be connected. If a NodeSetReader reads an " id" named map,955 /// have to be connected. If a NodeSetReader reads an "label" named map, 955 956 /// it will be able to resolve the nodes by ids. 956 957 /// … … 973 974 /// add the readed edges to the given Graph. It will use the given 974 975 /// node id reader to read the source and target nodes of the edges. 975 /// The reader will read the section only if the \c _ idand the976 /// \c edgset_ idare the same.977 template <typename Node IdReader>976 /// The reader will read the section only if the \c _name and the 977 /// \c edgset_name are the same. 978 template <typename NodeLabelReader> 978 979 EdgeSetReader(LemonReader& _reader, 979 980 Graph& _graph, 980 const Node IdReader& _nodeIdReader,981 const std::string& _ id= std::string(),981 const NodeLabelReader& _nodeLabelReader, 982 const std::string& _name = std::string(), 982 983 const DefaultSkipper& _skipper = DefaultSkipper()) 983 : Parent(_reader), graph(_graph), id(_id), skipper(_skipper) {984 checkConcept<_reader_bits::Item IdReader<Node>, NodeIdReader>();985 node IdReader.reset(new _reader_bits::986 IdReader<Node, NodeIdReader>(_nodeIdReader));984 : Parent(_reader), graph(_graph), name(_name), skipper(_skipper) { 985 checkConcept<_reader_bits::ItemLabelReader<Node>, NodeLabelReader>(); 986 nodeLabelReader.reset(new _reader_bits:: 987 LabelReader<Node, NodeLabelReader>(_nodeLabelReader)); 987 988 } 988 989 /// \brief Destructor. … … 1078 1079 /// 1079 1080 /// It gives back true when the header line starts with \c \@edgeset, 1080 /// and the header line's id and the edgeset's idare the same.1081 /// and the header line's name and the edgeset's name are the same. 1081 1082 virtual bool header(const std::string& line) { 1082 1083 std::istringstream ls(line); 1083 1084 std::string command; 1084 std::string name;1085 std::string id; 1085 1086 ls >> command >> name; 1086 1087 return command == "@edgeset" && name == id; … … 1091 1092 /// It reads the content of the section. 1092 1093 virtual void read(std::istream& is) { 1093 if (!node IdReader->isIdReader()) {1094 throw DataFormatError("Cannot find nodeset or IDmap");1094 if (!nodeLabelReader->isLabelReader()) { 1095 throw DataFormatError("Cannot find nodeset or label map"); 1095 1096 } 1096 1097 std::vector<_reader_bits::MapReaderBase<Edge>* > index; … … 1099 1100 getline(is, line); 1100 1101 std::istringstream ls(line); 1102 std::string id; 1101 1103 while (ls >> id) { 1102 1104 typename MapReaders::iterator it = readers.find(id); … … 1107 1109 index.push_back(&skipper); 1108 1110 } 1109 if (id == " id" && inverter.get() == 0) {1111 if (id == "label" || (id =="id" && inverter.get() == 0)) { 1110 1112 inverter.reset(index.back()->getInverter()); 1111 1113 index.back() = inverter.get(); … … 1122 1124 while (getline(is, line)) { 1123 1125 std::istringstream ls(line); 1124 Node from = node IdReader->read(ls);1125 Node to = node IdReader->read(ls);1126 Node from = nodeLabelReader->read(ls); 1127 Node to = nodeLabelReader->read(ls); 1126 1128 Edge edge = graph.addEdge(from, to); 1127 1129 for (int i = 0; i < (int)index.size(); ++i) { … … 1133 1135 public: 1134 1136 1135 /// \brief Returns true if the edgeset can give back the edge by its id.1136 /// 1137 /// Returns true if the edgeset can give back the edge by its id.1138 /// It is possible only if an " id" named map was read.1139 bool is IdReader() const {1137 /// \brief Returns true if the edgeset can give back the edge by its label. 1138 /// 1139 /// Returns true if the edgeset can give back the edge by its label. 1140 /// It is possible only if an "label" named map was read. 1141 bool isLabelReader() const { 1140 1142 return inverter.get() != 0; 1141 1143 } 1142 1144 1143 /// \brief Gives back the edge by its id.1145 /// \brief Gives back the edge by its label. 1144 1146 /// 1145 1147 /// It reads an id from the stream and gives back which edge belongs to 1146 /// it. It is possible only if there was read an " id" named map.1147 void read Id(std::istream& is, Edge& edge) const {1148 /// it. It is possible only if there was read an "label" named map. 1149 void readLabel(std::istream& is, Edge& edge) const { 1148 1150 edge = inverter->read(is); 1149 1151 } … … 1155 1157 1156 1158 Graph& graph; 1157 std::string id;1159 std::string name; 1158 1160 _reader_bits::SkipReader<Edge, DefaultSkipper> skipper; 1159 1161 1160 1162 std::auto_ptr<_reader_bits::MapInverterBase<Edge> > inverter; 1161 std::auto_ptr<_reader_bits:: IdReaderBase<Node> > nodeIdReader;1163 std::auto_ptr<_reader_bits::LabelReaderBase<Node> > nodeLabelReader; 1162 1164 }; 1163 1165 … … 1167 1169 /// The lemon format can store multiple undirected edgesets with several 1168 1170 /// maps. The undirected edgeset section's header line is \c \@undiredgeset 1169 /// \c undiredgeset_ id, but the \c undiredgeset_idmay be empty.1171 /// \c undiredgeset_name, but the \c undiredgeset_name may be empty. 1170 1172 /// 1171 1173 /// The first line of the section contains the names of the maps separated … … 1179 1181 /// difference. 1180 1182 /// 1181 /// If the edgeset contains an \c " id" named map then it will be regarded1183 /// If the edgeset contains an \c "label" named map then it will be regarded 1182 1184 /// as id map. This map should contain only unique values and when the 1183 /// \c read Id() member will read a value from the given stream it will1185 /// \c readLabel() member will read a value from the given stream it will 1184 1186 /// give back that undiricted edge which is mapped to this value. 1185 1187 /// 1186 1188 /// The undirected edgeset reader needs a node id reader to identify which 1187 /// nodes have to be connected. If a NodeSetReader reads an " id" named map,1189 /// nodes have to be connected. If a NodeSetReader reads an "label" named map, 1188 1190 /// it will be able to resolve the nodes by ids. 1189 1191 /// … … 1208 1210 /// will use the given node id reader to read the source and target 1209 1211 /// nodes of the edges. The reader will read the section only if the 1210 /// \c _ id and the \c undiredgset_idare the same.1211 template <typename Node IdReader>1212 /// \c _name and the \c undiredgset_name are the same. 1213 template <typename NodeLabelReader> 1212 1214 UndirEdgeSetReader(LemonReader& _reader, 1213 1215 Graph& _graph, 1214 const Node IdReader& _nodeIdReader,1215 const std::string& _ id= std::string(),1216 const NodeLabelReader& _nodeLabelReader, 1217 const std::string& _name = std::string(), 1216 1218 const DefaultSkipper& _skipper = DefaultSkipper()) 1217 : Parent(_reader), graph(_graph), id(_id), skipper(_skipper) {1218 checkConcept<_reader_bits::Item IdReader<Node>, NodeIdReader>();1219 node IdReader.reset(new _reader_bits::1220 IdReader<Node, NodeIdReader>(_nodeIdReader));1219 : Parent(_reader), graph(_graph), name(_name), skipper(_skipper) { 1220 checkConcept<_reader_bits::ItemLabelReader<Node>, NodeLabelReader>(); 1221 nodeLabelReader.reset(new _reader_bits:: 1222 LabelReader<Node, NodeLabelReader>(_nodeLabelReader)); 1221 1223 } 1222 1224 /// \brief Destructor. … … 1373 1375 /// 1374 1376 /// It gives back true when the header line starts with \c \@undiredgeset, 1375 /// and the header line's id and the edgeset's idare the same.1377 /// and the header line's name and the edgeset's name are the same. 1376 1378 virtual bool header(const std::string& line) { 1377 1379 std::istringstream ls(line); 1378 1380 std::string command; 1379 std::string name;1381 std::string id; 1380 1382 ls >> command >> name; 1381 1383 return command == "@undiredgeset" && name == id; … … 1386 1388 /// It reads the content of the section. 1387 1389 virtual void read(std::istream& is) { 1388 if (!node IdReader->isIdReader()) {1389 throw DataFormatError("Cannot find nodeset or IDmap");1390 if (!nodeLabelReader->isLabelReader()) { 1391 throw DataFormatError("Cannot find nodeset or label map"); 1390 1392 } 1391 1393 std::vector<_reader_bits::MapReaderBase<UndirEdge>* > index; … … 1394 1396 getline(is, line); 1395 1397 std::istringstream ls(line); 1398 std::string id; 1396 1399 while (ls >> id) { 1397 1400 typename MapReaders::iterator it = readers.find(id); … … 1402 1405 index.push_back(&skipper); 1403 1406 } 1404 if (id == " id" && inverter.get() == 0) {1407 if (id == "label" || (id =="id" && inverter.get() == 0)) { 1405 1408 inverter.reset(index.back()->getInverter()); 1406 1409 index.back() = inverter.get(); … … 1417 1420 while (getline(is, line)) { 1418 1421 std::istringstream ls(line); 1419 Node from = node IdReader->read(ls);1420 Node to = node IdReader->read(ls);1422 Node from = nodeLabelReader->read(ls); 1423 Node to = nodeLabelReader->read(ls); 1421 1424 UndirEdge edge = graph.addEdge(from, to); 1422 1425 for (int i = 0; i < (int)index.size(); ++i) { … … 1428 1431 public: 1429 1432 1430 /// \brief Returns true if the edgeset can give back the edge by its id.1433 /// \brief Returns true if the edgeset can give back the edge by its label. 1431 1434 /// 1432 1435 /// Returns true if the edgeset can give back the undirected edge by its 1433 /// id. It is possible only if an " id" named map was read.1434 bool is IdReader() const {1436 /// id. It is possible only if an "label" named map was read. 1437 bool isLabelReader() const { 1435 1438 return inverter.get() != 0; 1436 1439 } 1437 1440 1438 /// \brief Gives back the undirected edge by its id.1441 /// \brief Gives back the undirected edge by its label. 1439 1442 /// 1440 1443 /// It reads an id from the stream and gives back which undirected edge 1441 /// belongs to it. It is possible only if there was read an " id" named map.1442 void read Id(std::istream& is, UndirEdge& undirEdge) const {1444 /// belongs to it. It is possible only if there was read an "label" named map. 1445 void readLabel(std::istream& is, UndirEdge& undirEdge) const { 1443 1446 undirEdge = inverter->read(is); 1444 1447 } 1445 1448 1446 /// \brief Gives back the directed edge by its id.1449 /// \brief Gives back the directed edge by its label. 1447 1450 /// 1448 1451 /// It reads an id from the stream and gives back which directed edge 1449 1452 /// belongs to it. The directed edge id is the \c '+' or \c '-' character 1450 1453 /// and the undirected edge id. It is possible only if there was read 1451 /// an " id" named map.1452 void read Id(std::istream& is, Edge& edge) const {1454 /// an "label" named map. 1455 void readLabel(std::istream& is, Edge& edge) const { 1453 1456 char c; 1454 1457 is >> c; … … 1471 1474 1472 1475 Graph& graph; 1473 std::string id;1476 std::string name; 1474 1477 _reader_bits::SkipReader<UndirEdge, DefaultSkipper> skipper; 1475 1478 1476 1479 std::auto_ptr<_reader_bits::MapInverterBase<UndirEdge> > inverter; 1477 std::auto_ptr<_reader_bits:: IdReaderBase<Node> > nodeIdReader;1480 std::auto_ptr<_reader_bits::LabelReaderBase<Node> > nodeLabelReader; 1478 1481 }; 1479 1482 … … 1481 1484 /// \brief SectionReader for reading labeled nodes. 1482 1485 /// 1483 /// The nodes section's header line is \c \@nodes \c nodes_ id, but the1484 /// \c nodes_ idmay be empty.1486 /// The nodes section's header line is \c \@nodes \c nodes_name, but the 1487 /// \c nodes_name may be empty. 1485 1488 /// 1486 1489 /// Each line in the section contains the name of the node … … 1500 1503 /// attach it into the given LemonReader. It will use the given 1501 1504 /// node id reader to give back the nodes. The reader will read the 1502 /// section only if the \c _ id and the \c nodes_idare the same.1503 template <typename _ IdReader>1504 NodeReader(LemonReader& _reader, const _ IdReader& _idReader,1505 const std::string& _ id= std::string())1506 : Parent(_reader), id(_id) {1507 checkConcept<_reader_bits::Item IdReader<Node>, _IdReader>();1508 node IdReader.reset(new _reader_bits::1509 IdReader<Node, _IdReader>(_idReader));1505 /// section only if the \c _name and the \c nodes_name are the same. 1506 template <typename _LabelReader> 1507 NodeReader(LemonReader& _reader, const _LabelReader& _labelReader, 1508 const std::string& _name = std::string()) 1509 : Parent(_reader), name(_name) { 1510 checkConcept<_reader_bits::ItemLabelReader<Node>, _LabelReader>(); 1511 nodeLabelReader.reset(new _reader_bits:: 1512 LabelReader<Node, _LabelReader>(_labelReader)); 1510 1513 } 1511 1514 … … 1539 1542 /// 1540 1543 /// It gives back true when the header line start with \c \@nodes, 1541 /// and the header line's id and the reader's idare the same.1544 /// and the header line's name and the reader's name are the same. 1542 1545 virtual bool header(const std::string& line) { 1543 1546 std::istringstream ls(line); 1544 1547 std::string command; 1545 std::string name;1548 std::string id; 1546 1549 ls >> command >> name; 1547 1550 return command == "@nodes" && name == id; … … 1552 1555 /// It reads the content of the section. 1553 1556 virtual void read(std::istream& is) { 1554 if (!node IdReader->isIdReader()) {1555 throw DataFormatError("Cannot find nodeset or IDmap");1557 if (!nodeLabelReader->isLabelReader()) { 1558 throw DataFormatError("Cannot find nodeset or label map"); 1556 1559 } 1557 1560 std::string line; … … 1562 1565 typename NodeReaders::iterator it = readers.find(id); 1563 1566 if (it != readers.end()) { 1564 it->second.read(node IdReader->read(ls));1567 it->second.read(nodeLabelReader->read(ls)); 1565 1568 it->second.touch(); 1566 1569 } … … 1578 1581 private: 1579 1582 1580 std::string id;1583 std::string name; 1581 1584 1582 1585 typedef std::map<std::string, _reader_bits::ItemStore<Node> > NodeReaders; 1583 1586 NodeReaders readers; 1584 std::auto_ptr<_reader_bits:: IdReaderBase<Node> > nodeIdReader;1587 std::auto_ptr<_reader_bits::LabelReaderBase<Node> > nodeLabelReader; 1585 1588 }; 1586 1589 … … 1588 1591 /// \brief SectionReader for reading labeled edges. 1589 1592 /// 1590 /// The edges section's header line is \c \@edges \c edges_ id, but the1591 /// \c edges_ idmay be empty.1593 /// The edges section's header line is \c \@edges \c edges_name, but the 1594 /// \c edges_name may be empty. 1592 1595 /// 1593 1596 /// Each line in the section contains the name of the edge … … 1607 1610 /// attach it into the given LemonReader. It will use the given 1608 1611 /// edge id reader to give back the edges. The reader will read the 1609 /// section only if the \c _ id and the \c edges_idare the same.1610 template <typename _ IdReader>1611 EdgeReader(LemonReader& _reader, const _ IdReader& _idReader,1612 const std::string& _ id= std::string())1613 : Parent(_reader), id(_id) {1614 checkConcept<_reader_bits::Item IdReader<Edge>, _IdReader>();1615 edge IdReader.reset(new _reader_bits::1616 IdReader<Edge, _IdReader>(_idReader));1612 /// section only if the \c _name and the \c edges_name are the same. 1613 template <typename _LabelReader> 1614 EdgeReader(LemonReader& _reader, const _LabelReader& _labelReader, 1615 const std::string& _name = std::string()) 1616 : Parent(_reader), name(_name) { 1617 checkConcept<_reader_bits::ItemLabelReader<Edge>, _LabelReader>(); 1618 edgeLabelReader.reset(new _reader_bits:: 1619 LabelReader<Edge, _LabelReader>(_labelReader)); 1617 1620 } 1618 1621 … … 1645 1648 /// 1646 1649 /// It gives back true when the header line start with \c \@edges, 1647 /// and the header line's id and the reader's idare the same.1650 /// and the header line's name and the reader's name are the same. 1648 1651 virtual bool header(const std::string& line) { 1649 1652 std::istringstream ls(line); 1650 1653 std::string command; 1651 std::string name;1654 std::string id; 1652 1655 ls >> command >> name; 1653 1656 return command == "@edges" && name == id; … … 1658 1661 /// It reads the content of the section. 1659 1662 virtual void read(std::istream& is) { 1660 if (!edge IdReader->isIdReader()) {1661 throw DataFormatError("Cannot find edgeset or IDmap");1663 if (!edgeLabelReader->isLabelReader()) { 1664 throw DataFormatError("Cannot find edgeset or label map"); 1662 1665 } 1663 1666 std::string line; … … 1668 1671 typename EdgeReaders::iterator it = readers.find(id); 1669 1672 if (it != readers.end()) { 1670 it->second.read(edge IdReader->read(ls));1673 it->second.read(edgeLabelReader->read(ls)); 1671 1674 it->second.touch(); 1672 1675 } … … 1684 1687 private: 1685 1688 1686 std::string id;1689 std::string name; 1687 1690 1688 1691 typedef std::map<std::string, _reader_bits::ItemStore<Edge> > EdgeReaders; 1689 1692 EdgeReaders readers; 1690 std::auto_ptr<_reader_bits:: IdReaderBase<Edge> > edgeIdReader;1693 std::auto_ptr<_reader_bits::LabelReaderBase<Edge> > edgeLabelReader; 1691 1694 }; 1692 1695 … … 1695 1698 /// 1696 1699 /// The undirected edges section's header line is \c \@undiredges 1697 /// \c undiredges_ id, but the \c undiredges_idmay be empty.1700 /// \c undiredges_name, but the \c undiredges_name may be empty. 1698 1701 /// 1699 1702 /// Each line in the section contains the name of the undirected edge … … 1714 1717 /// attach it into the given LemonReader. It will use the given 1715 1718 /// undirected edge id reader to give back the edges. The reader will 1716 /// read the section only if the \c _ id and the \c undiredges_idare1719 /// read the section only if the \c _name and the \c undiredges_name are 1717 1720 /// the same. 1718 template <typename _ IdReader>1719 UndirEdgeReader(LemonReader& _reader, const _ IdReader& _idReader,1720 const std::string& _ id= std::string())1721 : Parent(_reader), id(_id) {1722 checkConcept<_reader_bits::Item IdReader<UndirEdge>, _IdReader>();1723 checkConcept<_reader_bits::Item IdReader<Edge>, _IdReader>();1724 undirEdge IdReader.reset(new _reader_bits::1725 IdReader<UndirEdge, _IdReader>(_idReader));1726 edge IdReader.reset(new _reader_bits::1727 IdReader<Edge, _IdReader>(_idReader));1721 template <typename _LabelReader> 1722 UndirEdgeReader(LemonReader& _reader, const _LabelReader& _labelReader, 1723 const std::string& _name = std::string()) 1724 : Parent(_reader), name(_name) { 1725 checkConcept<_reader_bits::ItemLabelReader<UndirEdge>, _LabelReader>(); 1726 checkConcept<_reader_bits::ItemLabelReader<Edge>, _LabelReader>(); 1727 undirEdgeLabelReader.reset(new _reader_bits:: 1728 LabelReader<UndirEdge, _LabelReader>(_labelReader)); 1729 edgeLabelReader.reset(new _reader_bits:: 1730 LabelReader<Edge, _LabelReader>(_labelReader)); 1728 1731 } 1729 1732 … … 1769 1772 /// 1770 1773 /// It gives back true when the header line start with \c \@edges, 1771 /// and the header line's id and the reader's idare the same.1774 /// and the header line's name and the reader's name are the same. 1772 1775 virtual bool header(const std::string& line) { 1773 1776 std::istringstream ls(line); 1774 1777 std::string command; 1775 std::string name;1778 std::string id; 1776 1779 ls >> command >> name; 1777 1780 return command == "@undiredges" && name == id; … … 1782 1785 /// It reads the content of the section. 1783 1786 virtual void read(std::istream& is) { 1784 if (!edge IdReader->isIdReader()) {1785 throw DataFormatError("Cannot find undirected edgeset or IDmap");1786 } 1787 if (!undirEdge IdReader->isIdReader()) {1788 throw DataFormatError("Cannot find undirected edgeset or IDmap");1787 if (!edgeLabelReader->isLabelReader()) { 1788 throw DataFormatError("Cannot find undirected edgeset or label map"); 1789 } 1790 if (!undirEdgeLabelReader->isLabelReader()) { 1791 throw DataFormatError("Cannot find undirected edgeset or label map"); 1789 1792 } 1790 1793 std::string line; … … 1796 1799 typename UndirEdgeReaders::iterator it = undirEdgeReaders.find(id); 1797 1800 if (it != undirEdgeReaders.end()) { 1798 it->second.read(undirEdge IdReader->read(ls));1801 it->second.read(undirEdgeLabelReader->read(ls)); 1799 1802 it->second.touch(); 1800 1803 continue; … … 1803 1806 typename EdgeReaders::iterator it = edgeReaders.find(id); 1804 1807 if (it != edgeReaders.end()) { 1805 it->second.read(edge IdReader->read(ls));1808 it->second.read(edgeLabelReader->read(ls)); 1806 1809 it->second.touch(); 1807 1810 continue; … … 1829 1832 private: 1830 1833 1831 std::string id;1834 std::string name; 1832 1835 1833 1836 typedef std::map<std::string, 1834 1837 _reader_bits::ItemStore<UndirEdge> > UndirEdgeReaders; 1835 1838 UndirEdgeReaders undirEdgeReaders; 1836 std::auto_ptr<_reader_bits:: IdReaderBase<UndirEdge> > undirEdgeIdReader;1839 std::auto_ptr<_reader_bits::LabelReaderBase<UndirEdge> > undirEdgeLabelReader; 1837 1840 1838 1841 typedef std::map<std::string, _reader_bits::ItemStore<Edge> > EdgeReaders; 1839 1842 EdgeReaders edgeReaders; 1840 std::auto_ptr<_reader_bits:: IdReaderBase<Edge> > edgeIdReader;1843 std::auto_ptr<_reader_bits::LabelReaderBase<Edge> > edgeLabelReader; 1841 1844 }; 1842 1845 … … 1845 1848 /// 1846 1849 /// The lemon format can store multiple attribute set. Each set has 1847 /// the header line \c \@attributes \c attributeset_ id, but the1848 /// attributeset_ idmay be empty.1850 /// the header line \c \@attributes \c attributeset_name, but the 1851 /// attributeset_name may be empty. 1849 1852 /// 1850 1853 /// The attributeset section contains several lines. Each of them starts … … 1861 1864 /// Constructor for AttributeReader. It creates the AttributeReader and 1862 1865 /// attach it into the given LemonReader. The reader process a section 1863 /// only if the \c section_ id and the \c _idare the same.1866 /// only if the \c section_name and the \c _name are the same. 1864 1867 AttributeReader(LemonReader& _reader, 1865 const std::string& _ id= std::string())1866 : Parent(_reader), id(_id) {}1868 const std::string& _name = std::string()) 1869 : Parent(_reader), name(_name) {} 1867 1870 1868 1871 /// \brief Destructor. … … 1917 1920 std::istringstream ls(line); 1918 1921 std::string command; 1919 std::string name;1922 std::string id; 1920 1923 ls >> command >> name; 1921 1924 return command == "@attributes" && name == id; … … 1934 1937 if (it != readers.end()) { 1935 1938 it->second->read(ls); 1936 it->second->touch();1939 it->second->touch(); 1937 1940 } 1938 1941 } … … 1948 1951 1949 1952 private: 1950 std::string id;1953 std::string name; 1951 1954 1952 1955 typedef std::map<std::string, _reader_bits::ValueReaderBase*> Readers; … … 2204 2207 2205 2208 void readMapNames(std::istream& is, std::vector<std::string>& maps) { 2206 std::string line, id;2209 std::string line, name; 2207 2210 std::getline(is, line); 2208 2211 std::istringstream ls(line); 2209 while (ls >> id) {2210 maps.push_back( id);2212 while (ls >> name) { 2213 maps.push_back(name); 2211 2214 } 2212 2215 while (getline(is, line)); … … 2214 2217 2215 2218 void readItemNames(std::istream& is, std::vector<std::string>& maps) { 2216 std::string line, id;2219 std::string line, name; 2217 2220 while (std::getline(is, line)) { 2218 2221 std::istringstream ls(line); 2219 ls >> id;2220 maps.push_back( id);2222 ls >> name; 2223 maps.push_back(name); 2221 2224 } 2222 2225 } -
lemon/lemon_writer.h
r1875 r1901 47 47 48 48 template <typename Item> 49 class Item IdWriter {49 class ItemLabelWriter { 50 50 public: 51 51 52 bool is IdWriter() { return true; }53 54 void write Id(std::ostream&, const Item&) {}52 bool isLabelWriter() { return true; } 53 54 void writeLabel(std::ostream&, const Item&) {} 55 55 56 template <class _Item IdWriter>56 template <class _ItemLabelWriter> 57 57 struct Constraints { 58 58 void constraints() { 59 bool b = writer.is IdWriter();59 bool b = writer.isLabelWriter(); 60 60 ignore_unused_variable_warning(b); 61 writer.write Id(os, item);61 writer.writeLabel(os, item); 62 62 } 63 _Item IdWriter& writer;63 _ItemLabelWriter& writer; 64 64 std::ostream& os; 65 65 const Item& item; … … 226 226 227 227 template <typename _Item> 228 class IdWriterBase {228 class LabelWriterBase { 229 229 public: 230 230 typedef _Item Item; 231 virtual ~ IdWriterBase() {}231 virtual ~LabelWriterBase() {} 232 232 virtual void write(std::ostream&, const Item&) const = 0; 233 virtual bool is IdWriter() const = 0;234 }; 235 236 template <typename _Item, typename _Boxed IdWriter>237 class IdWriter : public IdWriterBase<_Item> {233 virtual bool isLabelWriter() const = 0; 234 }; 235 236 template <typename _Item, typename _BoxedLabelWriter> 237 class LabelWriter : public LabelWriterBase<_Item> { 238 238 public: 239 239 typedef _Item Item; 240 typedef _Boxed IdWriter BoxedIdWriter;241 242 const Boxed IdWriter& idWriter;243 244 IdWriter(const BoxedIdWriter& _idWriter)245 : idWriter(_idWriter) {}240 typedef _BoxedLabelWriter BoxedLabelWriter; 241 242 const BoxedLabelWriter& labelWriter; 243 244 LabelWriter(const BoxedLabelWriter& _labelWriter) 245 : labelWriter(_labelWriter) {} 246 246 247 247 virtual void write(std::ostream& os, const Item& item) const { 248 idWriter.writeId(os, item);249 } 250 251 virtual bool is IdWriter() const {252 return idWriter.isIdWriter();248 labelWriter.writeLabel(os, item); 249 } 250 251 virtual bool isLabelWriter() const { 252 return labelWriter.isLabelWriter(); 253 253 } 254 254 }; … … 375 375 /// 376 376 /// The lemon format can store multiple graph nodesets with several maps. 377 /// The nodeset section's header line is \c \@nodeset \c nodeset_ id, but the378 /// \c nodeset_idmay be empty.377 /// The nodeset section's header line is \c \@nodeset \c nodeset_name, but 378 /// the \c nodeset_name may be empty. 379 379 /// 380 380 /// The first line of the section contains the names of the maps separated … … 382 382 /// contains the mapped values for each map. 383 383 /// 384 /// If the nodeset contains an \c " id" named map then it will be regarded385 /// as idmap. This map should contain only unique values and when the386 /// \c write Id() member will be called with a node it will write it's id.387 /// Otherwise if the \c _forceIdMap constructor parameter is true then388 /// the idmap will be the id in the graph.384 /// If the nodeset contains an \c "label" named map then it will be regarded 385 /// as label map. This map should contain only unique values and when the 386 /// \c writeLabel() member will be called with a node it will write it's 387 /// label. Otherwise if the \c _forceLabelMap constructor parameter is true 388 /// then the label map will be the id in the graph. 389 389 /// 390 390 /// \relates LemonWriter … … 401 401 /// 402 402 /// Constructor for NodeSetWriter. It creates the NodeSetWriter and 403 /// attach it into the given LemonWriter. If the \c _force IdMap404 /// parameter is true then the writer will write own idmap when405 /// the user does not give " id" named map.403 /// attach it into the given LemonWriter. If the \c _forceLabelMap 404 /// parameter is true then the writer will write own label map when 405 /// the user does not give "label" named map. 406 406 NodeSetWriter(LemonWriter& _writer, const Graph& _graph, 407 const std::string& _ id= std::string(),408 bool _force IdMap = true)409 : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),410 graph(_graph), id(_id) {}407 const std::string& _name = std::string(), 408 bool _forceLabelMap = true) 409 : Parent(_writer), labelMap(0), forceLabelMap(_forceLabelMap), 410 graph(_graph), name(_name) {} 411 411 412 412 /// \brief Destructor. … … 455 455 /// It gives back the header of the section. 456 456 virtual std::string header() { 457 return "@nodeset " + id;457 return "@nodeset " + name; 458 458 } 459 459 … … 463 463 virtual void write(std::ostream& os) { 464 464 for (int i = 0; i < (int)writers.size(); ++i) { 465 if (writers[i].first == " id") {466 idMap = writers[i].second;467 force IdMap = false;465 if (writers[i].first == "label" || (writers[i].first == "id" && labelMap == 0)) { 466 labelMap = writers[i].second; 467 forceLabelMap = false; 468 468 break; 469 469 } 470 470 } 471 if (force IdMap) {472 os << " id\t";471 if (forceLabelMap) { 472 os << "label\t"; 473 473 } 474 474 for (int i = 0; i < (int)writers.size(); ++i) { … … 477 477 os << std::endl; 478 478 for (typename Graph::NodeIt it(graph); it != INVALID; ++it) { 479 if (force IdMap) {479 if (forceLabelMap) { 480 480 os << graph.id(it) << '\t'; 481 481 } … … 490 490 public: 491 491 492 /// \brief Returns true if the nodeset can write the ids of the nodes.493 /// 494 /// Returns true if the nodeset can write the ids of the nodes.495 /// It is possible only if an " id" named map was written or the496 /// \c _force IdMap constructor parameter was true.497 bool is IdWriter() const {498 return idMap != 0 || forceIdMap;499 } 500 501 /// \brief Write the idof the given node.502 /// 503 /// It writes the id of the given node. If there was written an "id"492 /// \brief Returns true if the nodeset can write the labels of the nodes. 493 /// 494 /// Returns true if the nodeset can write the labels of the nodes. 495 /// It is possible only if an "label" named map was written or the 496 /// \c _forceLabelMap constructor parameter was true. 497 bool isLabelWriter() const { 498 return labelMap != 0 || forceLabelMap; 499 } 500 501 /// \brief Write the label of the given node. 502 /// 503 /// It writes the label of the given node. If there was written an "label" 504 504 /// named map then it will write the map value belongs to the node. 505 /// Otherwise if the \c force Idparameter was true it will write506 /// its idin the graph.507 void write Id(std::ostream& os, const Node& item) const {508 if (force IdMap) {505 /// Otherwise if the \c forceLabel parameter was true it will write 506 /// its label in the graph. 507 void writeLabel(std::ostream& os, const Node& item) const { 508 if (forceLabelMap) { 509 509 os << graph.id(item); 510 510 } else { 511 idMap->write(os, item);511 labelMap->write(os, item); 512 512 } 513 513 } … … 519 519 MapWriters writers; 520 520 521 _writer_bits::MapWriterBase<Node>* idMap;522 bool force IdMap;521 _writer_bits::MapWriterBase<Node>* labelMap; 522 bool forceLabelMap; 523 523 524 524 const Graph& graph; 525 std::string id;525 std::string name; 526 526 527 527 }; … … 531 531 /// 532 532 /// The lemon format can store multiple graph edgesets with several maps. 533 /// The edgeset section's header line is \c \@edgeset \c edgeset_ id, but the534 /// \c edgeset_idmay be empty.533 /// The edgeset section's header line is \c \@edgeset \c edgeset_name, but 534 /// the \c edgeset_name may be empty. 535 535 /// 536 536 /// The first line of the section contains the names of the maps separated 537 537 /// with white spaces. Each next lines describes a edge in the edgeset. The 538 /// line contains the source and the target nodes' idand the mapped538 /// line contains the source and the target nodes' label and the mapped 539 539 /// values for each map. 540 540 /// 541 /// If the edgeset contains an \c " id" named map then it will be regarded542 /// as idmap. This map should contain only unique values and when the543 /// \c write Id() member will be called with an edge it will write it's id.544 /// Otherwise if the \c _forceIdMap constructor parameter is true then545 /// the idmap will be the id in the graph.546 /// 547 /// The edgeset writer needs a node idwriter to identify which nodes548 /// have to be connected. If a NodeSetWriter can write the nodes' id,541 /// If the edgeset contains an \c "label" named map then it will be regarded 542 /// as label map. This map should contain only unique values and when the 543 /// \c writeLabel() member will be called with an edge it will write it's 544 /// label. Otherwise if the \c _forceLabelMap constructor parameter is true 545 /// then the label map will be the id in the graph. 546 /// 547 /// The edgeset writer needs a node label writer to identify which nodes 548 /// have to be connected. If a NodeSetWriter can write the nodes' label, 549 549 /// it will be able to use with this class. 550 550 /// … … 563 563 /// 564 564 /// Constructor for EdgeSetWriter. It creates the EdgeSetWriter and 565 /// attach it into the given LemonWriter. It will write node ids by566 /// the \c _node IdWriter. If the \c _forceIdMap parameter is true567 /// then the writer will write own idmap if the user does not give568 /// " id" named map.569 template <typename Node IdWriter>565 /// attach it into the given LemonWriter. It will write node labels by 566 /// the \c _nodeLabelWriter. If the \c _forceLabelMap parameter is true 567 /// then the writer will write own label map if the user does not give 568 /// "label" named map. 569 template <typename NodeLabelWriter> 570 570 EdgeSetWriter(LemonWriter& _writer, const Graph& _graph, 571 const Node IdWriter& _nodeIdWriter,572 const std::string& _ id= std::string(),573 bool _force IdMap = true)574 : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),575 graph(_graph), id(_id) {576 checkConcept<_writer_bits::Item IdWriter<Node>, NodeIdWriter>();577 node IdWriter.reset(new _writer_bits::578 IdWriter<Node, NodeIdWriter>(_nodeIdWriter));571 const NodeLabelWriter& _nodeLabelWriter, 572 const std::string& _name = std::string(), 573 bool _forceLabelMap = true) 574 : Parent(_writer), labelMap(0), forceLabelMap(_forceLabelMap), 575 graph(_graph), name(_name) { 576 checkConcept<_writer_bits::ItemLabelWriter<Node>, NodeLabelWriter>(); 577 nodeLabelWriter.reset(new _writer_bits:: 578 LabelWriter<Node, NodeLabelWriter>(_nodeLabelWriter)); 579 579 } 580 580 … … 624 624 /// It gives back the header of the section. 625 625 virtual std::string header() { 626 return "@edgeset " + id;626 return "@edgeset " + name; 627 627 } 628 628 … … 631 631 /// Write the content of the section. 632 632 virtual void write(std::ostream& os) { 633 if (!node IdWriter->isIdWriter()) {634 throw DataFormatError("Cannot find nodeset or IDmap");633 if (!nodeLabelWriter->isLabelWriter()) { 634 throw DataFormatError("Cannot find nodeset or label map"); 635 635 } 636 636 for (int i = 0; i < (int)writers.size(); ++i) { 637 if (writers[i].first == " id") {638 idMap = writers[i].second;639 force IdMap = false;637 if (writers[i].first == "label" || (writers[i].first == "id" && labelMap == 0)) { 638 labelMap = writers[i].second; 639 forceLabelMap = false; 640 640 break; 641 641 } 642 642 } 643 643 os << "\t\t"; 644 if (force IdMap) {645 os << " id\t";644 if (forceLabelMap) { 645 os << "label\t"; 646 646 } 647 647 for (int i = 0; i < (int)writers.size(); ++i) { … … 650 650 os << std::endl; 651 651 for (typename Graph::EdgeIt it(graph); it != INVALID; ++it) { 652 node IdWriter->write(os, graph.source(it));652 nodeLabelWriter->write(os, graph.source(it)); 653 653 os << '\t'; 654 node IdWriter->write(os, graph.target(it));654 nodeLabelWriter->write(os, graph.target(it)); 655 655 os << '\t'; 656 if (force IdMap) {656 if (forceLabelMap) { 657 657 os << graph.id(it) << '\t'; 658 658 } … … 667 667 public: 668 668 669 /// \brief Returns true if the edgeset can write the ids of the edges.670 /// 671 /// Returns true if the edgeset can write the ids of the edges.672 /// It is possible only if an " id" named map was written or the673 /// \c _force IdMap constructor parameter was true.674 bool is IdWriter() const {675 return force IdMap || idMap != 0;676 } 677 678 /// \brief Write the idof the given edge.679 /// 680 /// It writes the id of the given edge. If there was written an "id"669 /// \brief Returns true if the edgeset can write the labels of the edges. 670 /// 671 /// Returns true if the edgeset can write the labels of the edges. 672 /// It is possible only if an "label" named map was written or the 673 /// \c _forceLabelMap constructor parameter was true. 674 bool isLabelWriter() const { 675 return forceLabelMap || labelMap != 0; 676 } 677 678 /// \brief Write the label of the given edge. 679 /// 680 /// It writes the label of the given edge. If there was written an "label" 681 681 /// named map then it will write the map value belongs to the edge. 682 /// Otherwise if the \c force Idparameter was true it will write683 /// its idin the graph.684 void write Id(std::ostream& os, const Edge& item) const {685 if (force IdMap) {682 /// Otherwise if the \c forceLabel parameter was true it will write 683 /// its label in the graph. 684 void writeLabel(std::ostream& os, const Edge& item) const { 685 if (forceLabelMap) { 686 686 os << graph.id(item); 687 687 } else { 688 idMap->write(os, item);688 labelMap->write(os, item); 689 689 } 690 690 } … … 696 696 MapWriters writers; 697 697 698 _writer_bits::MapWriterBase<Edge>* idMap;699 bool force IdMap;698 _writer_bits::MapWriterBase<Edge>* labelMap; 699 bool forceLabelMap; 700 700 701 701 const Graph& graph; 702 std::string id;703 704 std::auto_ptr<_writer_bits:: IdWriterBase<Node> > nodeIdWriter;702 std::string name; 703 704 std::auto_ptr<_writer_bits::LabelWriterBase<Node> > nodeLabelWriter; 705 705 }; 706 706 … … 710 710 /// The lemon format can store multiple undirected edgesets with several 711 711 /// maps. The undirected edgeset section's header line is \c \@undiredgeset 712 /// \c undiredgeset_ id, but the \c undiredgeset_idmay be empty.712 /// \c undiredgeset_name, but the \c undiredgeset_name may be empty. 713 713 /// 714 714 /// The first line of the section contains the names of the maps separated 715 715 /// with white spaces. Each next lines describes an undirected edge in the 716 /// edgeset. The line contains the two connected nodes' idand the mapped716 /// edgeset. The line contains the two connected nodes' label and the mapped 717 717 /// values for each undirected map. 718 718 /// … … 723 723 /// difference. 724 724 /// 725 /// If the edgeset contains an \c " id" named map then it will be regarded726 /// as idmap. This map should contain only unique values and when the727 /// \c write Id() member will be called with an undirected edge it will728 /// write it's id. Otherwise if the \c _forceIdMap constructor parameter729 /// is true then the idmap will be the id in the graph.730 /// 731 /// The undirected edgeset writer needs a node idwriter to identify725 /// If the edgeset contains an \c "label" named map then it will be regarded 726 /// as label map. This map should contain only unique values and when the 727 /// \c writeLabel() member will be called with an undirected edge it will 728 /// write it's label. Otherwise if the \c _forceLabelMap constructor 729 /// parameter is true then the label map will be the id in the graph. 730 /// 731 /// The undirected edgeset writer needs a node label writer to identify 732 732 /// which nodes have to be connected. If a NodeSetWriter can write the 733 /// nodes' id, it will be able to use with this class.733 /// nodes' label, it will be able to use with this class. 734 734 /// 735 735 /// \relates LemonWriter … … 748 748 /// 749 749 /// Constructor for UndirEdgeSetWriter. It creates the UndirEdgeSetWriter 750 /// and attach it into the given LemonWriter. It will write node ids by751 /// the \c _node IdWriter. If the \c _forceIdMap parameter is true752 /// then the writer will write own idmap if the user does not give753 /// " id" named map.754 template <typename Node IdWriter>750 /// and attach it into the given LemonWriter. It will write node labels by 751 /// the \c _nodeLabelWriter. If the \c _forceLabelMap parameter is true 752 /// then the writer will write own label map if the user does not give 753 /// "label" named map. 754 template <typename NodeLabelWriter> 755 755 UndirEdgeSetWriter(LemonWriter& _writer, const Graph& _graph, 756 const Node IdWriter& _nodeIdWriter,757 const std::string& _ id= std::string(),758 bool _force IdMap = true)759 : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),760 graph(_graph), id(_id) {761 checkConcept<_writer_bits::Item IdWriter<Node>, NodeIdWriter>();762 node IdWriter.reset(new _writer_bits::763 IdWriter<Node, NodeIdWriter>(_nodeIdWriter));756 const NodeLabelWriter& _nodeLabelWriter, 757 const std::string& _name = std::string(), 758 bool _forceLabelMap = true) 759 : Parent(_writer), labelMap(0), forceLabelMap(_forceLabelMap), 760 graph(_graph), name(_name) { 761 checkConcept<_writer_bits::ItemLabelWriter<Node>, NodeLabelWriter>(); 762 nodeLabelWriter.reset(new _writer_bits:: 763 LabelWriter<Node, NodeLabelWriter>(_nodeLabelWriter)); 764 764 } 765 765 … … 833 833 /// It gives back the header of the section. 834 834 virtual std::string header() { 835 return "@undiredgeset " + id;835 return "@undiredgeset " + name; 836 836 } 837 837 … … 840 840 /// Write the content of the section. 841 841 virtual void write(std::ostream& os) { 842 if (!node IdWriter->isIdWriter()) {843 throw DataFormatError("Cannot find nodeset or IDmap");842 if (!nodeLabelWriter->isLabelWriter()) { 843 throw DataFormatError("Cannot find nodeset or label map"); 844 844 } 845 845 for (int i = 0; i < (int)writers.size(); ++i) { 846 if (writers[i].first == " id") {847 idMap = writers[i].second;848 force IdMap = false;846 if (writers[i].first == "label") { 847 labelMap = writers[i].second; 848 forceLabelMap = false; 849 849 break; 850 850 } 851 851 } 852 852 os << "\t\t"; 853 if (force IdMap) {854 os << " id\t";853 if (forceLabelMap) { 854 os << "label\t"; 855 855 } 856 856 for (int i = 0; i < (int)writers.size(); ++i) { … … 859 859 os << std::endl; 860 860 for (typename Graph::UndirEdgeIt it(graph); it != INVALID; ++it) { 861 node IdWriter->write(os, graph.source(it));861 nodeLabelWriter->write(os, graph.source(it)); 862 862 os << '\t'; 863 node IdWriter->write(os, graph.target(it));863 nodeLabelWriter->write(os, graph.target(it)); 864 864 os << '\t'; 865 if (force IdMap) {865 if (forceLabelMap) { 866 866 os << graph.id(it) << '\t'; 867 867 } … … 876 876 public: 877 877 878 /// \brief Returns true if the undirected edgeset can write the ids of878 /// \brief Returns true if the undirected edgeset can write the labels of 879 879 /// the edges. 880 880 /// 881 /// Returns true if the undirected edgeset can write the ids of the882 /// undirected edges. It is possible only if an " id" named map was883 /// written or the \c _force IdMap constructor parameter was true.884 bool is IdWriter() const {885 return force IdMap || idMap != 0;886 } 887 888 /// \brief Write the idof the given undirected edge.889 /// 890 /// It writes the idof the given undirected edge. If there was written891 /// an " id" named map then it will write the map value belongs to the892 /// undirected edge. Otherwise if the \c force Idparameter was true it881 /// Returns true if the undirected edgeset can write the labels of the 882 /// undirected edges. It is possible only if an "label" named map was 883 /// written or the \c _forceLabelMap constructor parameter was true. 884 bool isLabelWriter() const { 885 return forceLabelMap || labelMap != 0; 886 } 887 888 /// \brief Write the label of the given undirected edge. 889 /// 890 /// It writes the label of the given undirected edge. If there was written 891 /// an "label" named map then it will write the map value belongs to the 892 /// undirected edge. Otherwise if the \c forceLabel parameter was true it 893 893 /// will write its id in the graph. 894 void write Id(std::ostream& os, const UndirEdge& item) const {895 if (force IdMap) {894 void writeLabel(std::ostream& os, const UndirEdge& item) const { 895 if (forceLabelMap) { 896 896 os << graph.id(item); 897 897 } else { 898 idMap->write(os, item);898 labelMap->write(os, item); 899 899 } 900 900 } 901 901 902 /// \brief Write the idof the given edge.903 /// 904 /// It writes the idof the given edge. If there was written905 /// an " id" named map then it will write the map value belongs to the906 /// edge. Otherwise if the \c force Idparameter was true it902 /// \brief Write the label of the given edge. 903 /// 904 /// It writes the label of the given edge. If there was written 905 /// an "label" named map then it will write the map value belongs to the 906 /// edge. Otherwise if the \c forceLabel parameter was true it 907 907 /// will write its id in the graph. If the edge is forward map 908 908 /// then its prefix character is \c '+' elsewhere \c '-'. 909 void write Id(std::ostream& os, const Edge& item) const {909 void writeLabel(std::ostream& os, const Edge& item) const { 910 910 if (graph.direction(item)) { 911 911 os << "+ "; … … 913 913 os << "- "; 914 914 } 915 if (force IdMap) {915 if (forceLabelMap) { 916 916 os << graph.id(item); 917 917 } else { 918 idMap->write(os, item);918 labelMap->write(os, item); 919 919 } 920 920 } … … 926 926 MapWriters writers; 927 927 928 _writer_bits::MapWriterBase<UndirEdge>* idMap;929 bool force IdMap;928 _writer_bits::MapWriterBase<UndirEdge>* labelMap; 929 bool forceLabelMap; 930 930 931 931 const Graph& graph; 932 std::string id;933 934 std::auto_ptr<_writer_bits:: IdWriterBase<Node> > nodeIdWriter;932 std::string name; 933 934 std::auto_ptr<_writer_bits::LabelWriterBase<Node> > nodeLabelWriter; 935 935 }; 936 936 937 937 /// \ingroup io_group 938 /// \brief SectionWriter for writing labeled nodes.939 /// 940 /// The nodes section's header line is \c \@nodes \c nodes_ id, but the941 /// \c nodes_ idmay be empty.942 /// 943 /// Each line in the section contains the labelof the node and944 /// then the node id.938 /// \brief SectionWriter for writing named nodes. 939 /// 940 /// The nodes section's header line is \c \@nodes \c nodes_name, but the 941 /// \c nodes_name may be empty. 942 /// 943 /// Each line in the section contains the name of the node and 944 /// then the node label. 945 945 /// 946 946 /// \relates LemonWriter … … 955 955 /// 956 956 /// Constructor for NodeWriter. It creates the NodeWriter and 957 /// attach it into the given LemonWriter. The given \c _IdWriter 958 /// will write the nodes' id what can be a nodeset writer. 959 template <typename _IdWriter> 960 NodeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, 961 const std::string& _id = std::string()) 962 : Parent(_writer), id(_id) { 963 checkConcept<_writer_bits::ItemIdWriter<Node>, _IdWriter>(); 964 idWriter.reset(new _writer_bits::IdWriter<Node, _IdWriter>(_idWriter)); 957 /// attach it into the given LemonWriter. The given \c _LabelWriter 958 /// will write the nodes' label what can be a nodeset writer. 959 template <typename _LabelWriter> 960 NodeWriter(LemonWriter& _writer, const _LabelWriter& _labelWriter, 961 const std::string& _name = std::string()) 962 : Parent(_writer), name(_name) { 963 checkConcept<_writer_bits::ItemLabelWriter<Node>, _LabelWriter>(); 964 labelWriter.reset(new _writer_bits::LabelWriter<Node, _LabelWriter> 965 (_labelWriter)); 965 966 } 966 967 … … 986 987 protected: 987 988 988 /// \brief Header checking function. 989 /// 990 /// It gives back true when the header line start with \c \@nodes, 991 /// and the header line's id and the writer's id are the same. 989 /// \brief The header of the section. 990 /// 991 /// It gives back the header of the section. 992 992 virtual std::string header() { 993 return "@nodes " + id;993 return "@nodes " + name; 994 994 } 995 995 … … 998 998 /// Write the content of the section. 999 999 virtual void write(std::ostream& os) { 1000 if (! idWriter->isIdWriter()) {1001 throw DataFormatError("Cannot find nodeset or IDmap");1000 if (!labelWriter->isLabelWriter()) { 1001 throw DataFormatError("Cannot find nodeset or label map"); 1002 1002 } 1003 1003 for (int i = 0; i < (int)writers.size(); ++i) { 1004 1004 os << writers[i].first << ' '; 1005 idWriter->write(os, *(writers[i].second));1005 labelWriter->write(os, *(writers[i].second)); 1006 1006 os << std::endl; 1007 1007 } … … 1010 1010 private: 1011 1011 1012 std::string id;1012 std::string name; 1013 1013 1014 1014 typedef std::vector<std::pair<std::string, const Node*> > NodeWriters; 1015 1015 NodeWriters writers; 1016 std::auto_ptr<_writer_bits:: IdWriterBase<Node> > idWriter;1016 std::auto_ptr<_writer_bits::LabelWriterBase<Node> > labelWriter; 1017 1017 }; 1018 1018 1019 1019 /// \ingroup io_group 1020 /// \brief SectionWriter for writing labeled edges.1021 /// 1022 /// The edges section's header line is \c \@edges \c edges_ id, but the1023 /// \c edges_ idmay be empty.1024 /// 1025 /// Each line in the section contains the labelof the edge and1026 /// then the edge id.1020 /// \brief SectionWriter for writing named edges. 1021 /// 1022 /// The edges section's header line is \c \@edges \c edges_name, but the 1023 /// \c edges_name may be empty. 1024 /// 1025 /// Each line in the section contains the name of the edge and 1026 /// then the edge label. 1027 1027 /// 1028 1028 /// \relates LemonWriter … … 1037 1037 /// 1038 1038 /// Constructor for EdgeWriter. It creates the EdgeWriter and 1039 /// attach it into the given LemonWriter. The given \c _ IdWriter1040 /// will write the edges' idwhat can be a edgeset writer.1041 template <typename _ IdWriter>1042 EdgeWriter(LemonWriter& _writer, const _ IdWriter& _idWriter,1043 const std::string& _ id= std::string())1044 : Parent(_writer), id(_id) {1045 checkConcept<_writer_bits::Item IdWriter<Edge>, _IdWriter>();1046 idWriter.reset(new _writer_bits::IdWriter<Edge, _IdWriter>(_idWriter));1039 /// attach it into the given LemonWriter. The given \c _LabelWriter 1040 /// will write the edges' label what can be a edgeset writer. 1041 template <typename _LabelWriter> 1042 EdgeWriter(LemonWriter& _writer, const _LabelWriter& _labelWriter, 1043 const std::string& _name = std::string()) 1044 : Parent(_writer), name(_name) { 1045 checkConcept<_writer_bits::ItemLabelWriter<Edge>, _LabelWriter>(); 1046 labelWriter.reset(new _writer_bits::LabelWriter<Edge, _LabelWriter>(_labelWriter)); 1047 1047 } 1048 1048 … … 1066 1066 protected: 1067 1067 1068 /// \brief Header checking function. 1069 /// 1070 /// It gives back true when the header line start with \c \@edges, 1071 /// and the header line's id and the writer's id are the same. 1068 /// \brief The header of the section. 1069 /// 1070 /// It gives back the header of the section. 1072 1071 virtual std::string header() { 1073 return "@edges " + id;1072 return "@edges " + name; 1074 1073 } 1075 1074 … … 1078 1077 /// Write the content of the section. 1079 1078 virtual void write(std::ostream& os) { 1080 if (! idWriter->isIdWriter()) {1081 throw DataFormatError("Cannot find edgeset or IDmap");1079 if (!labelWriter->isLabelWriter()) { 1080 throw DataFormatError("Cannot find edgeset or label map"); 1082 1081 } 1083 1082 for (int i = 0; i < (int)writers.size(); ++i) { 1084 1083 os << writers[i].first << ' '; 1085 idWriter->write(os, *(writers[i].second));1084 labelWriter->write(os, *(writers[i].second)); 1086 1085 os << std::endl; 1087 1086 } … … 1090 1089 private: 1091 1090 1092 std::string id;1091 std::string name; 1093 1092 1094 1093 typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters; 1095 1094 EdgeWriters writers; 1096 1095 1097 std::auto_ptr<_writer_bits:: IdWriterBase<Edge> > idWriter;1096 std::auto_ptr<_writer_bits::LabelWriterBase<Edge> > labelWriter; 1098 1097 }; 1099 1098 1100 1099 /// \ingroup io_group 1101 /// \brief SectionWriter for writing labeled undirected edges.1100 /// \brief SectionWriter for writing named undirected edges. 1102 1101 /// 1103 1102 /// The undirected edges section's header line is \c \@undiredges 1104 /// \c undiredges_ id, but the \c undiredges_idmay be empty.1105 /// 1106 /// Each line in the section contains the labelof the undirected edge and1107 /// then the undirected edge id.1103 /// \c undiredges_name, but the \c undiredges_name may be empty. 1104 /// 1105 /// Each line in the section contains the name of the undirected edge and 1106 /// then the undirected edge label. 1108 1107 /// 1109 1108 /// \relates LemonWriter … … 1120 1119 /// 1121 1120 /// Constructor for UndirEdgeWriter. It creates the UndirEdgeWriter and 1122 /// attach it into the given LemonWriter. The given \c _ IdWriter1123 /// will write the undirected edges' idwhat can be an undirected1121 /// attach it into the given LemonWriter. The given \c _LabelWriter 1122 /// will write the undirected edges' label what can be an undirected 1124 1123 /// edgeset writer. 1125 template <typename _ IdWriter>1126 UndirEdgeWriter(LemonWriter& _writer, const _ IdWriter& _idWriter,1127 const std::string& _ id= std::string())1128 : Parent(_writer), id(_id) {1129 checkConcept<_writer_bits::Item IdWriter<Edge>, _IdWriter>();1130 checkConcept<_writer_bits::Item IdWriter<UndirEdge>, _IdWriter>();1131 undirEdge IdWriter.reset(new _writer_bits::1132 IdWriter<UndirEdge, _IdWriter>(_idWriter));1133 edge IdWriter.reset(new _writer_bits::1134 IdWriter<Edge, _IdWriter>(_idWriter));1124 template <typename _LabelWriter> 1125 UndirEdgeWriter(LemonWriter& _writer, const _LabelWriter& _labelWriter, 1126 const std::string& _name = std::string()) 1127 : Parent(_writer), name(_name) { 1128 checkConcept<_writer_bits::ItemLabelWriter<Edge>, _LabelWriter>(); 1129 checkConcept<_writer_bits::ItemLabelWriter<UndirEdge>, _LabelWriter>(); 1130 undirEdgeLabelWriter.reset(new _writer_bits:: 1131 LabelWriter<UndirEdge, _LabelWriter>(_labelWriter)); 1132 edgeLabelWriter.reset(new _writer_bits:: 1133 LabelWriter<Edge, _LabelWriter>(_labelWriter)); 1135 1134 } 1136 1135 … … 1161 1160 protected: 1162 1161 1163 /// \brief Header checking function. 1164 /// 1165 /// It gives back true when the header line start with \c \@undiredges, 1166 /// and the header line's id and the writer's id are the same. 1162 /// \brief The header of the section. 1163 /// 1164 /// It gives back the header of the section. 1167 1165 virtual std::string header() { 1168 return "@undiredges " + id;1166 return "@undiredges " + name; 1169 1167 } 1170 1168 … … 1173 1171 /// Write the content of the section. 1174 1172 virtual void write(std::ostream& os) { 1175 if (!edge IdWriter->isIdWriter()) {1176 throw DataFormatError("Cannot find undirected edgeset or IDmap");1177 } 1178 if (!undirEdge IdWriter->isIdWriter()) {1179 throw DataFormatError("Cannot find undirected edgeset or IDmap");1173 if (!edgeLabelWriter->isLabelWriter()) { 1174 throw DataFormatError("Cannot find undirected edgeset or label map"); 1175 } 1176 if (!undirEdgeLabelWriter->isLabelWriter()) { 1177 throw DataFormatError("Cannot find undirected edgeset or label map"); 1180 1178 } 1181 1179 for (int i = 0; i < (int)undirEdgeWriters.size(); ++i) { 1182 1180 os << undirEdgeWriters[i].first << ' '; 1183 undirEdge IdWriter->write(os, *(undirEdgeWriters[i].second));1181 undirEdgeLabelWriter->write(os, *(undirEdgeWriters[i].second)); 1184 1182 os << std::endl; 1185 1183 } 1186 1184 for (int i = 0; i < (int)edgeWriters.size(); ++i) { 1187 1185 os << edgeWriters[i].first << ' '; 1188 edge IdWriter->write(os, *(edgeWriters[i].second));1186 edgeLabelWriter->write(os, *(edgeWriters[i].second)); 1189 1187 os << std::endl; 1190 1188 } … … 1193 1191 private: 1194 1192 1195 std::string id;1193 std::string name; 1196 1194 1197 1195 typedef std::vector<std::pair<std::string, 1198 1196 const UndirEdge*> > UndirEdgeWriters; 1199 1197 UndirEdgeWriters undirEdgeWriters; 1200 std::auto_ptr<_writer_bits:: IdWriterBase<UndirEdge> > undirEdgeIdWriter;1198 std::auto_ptr<_writer_bits::LabelWriterBase<UndirEdge> > undirEdgeLabelWriter; 1201 1199 1202 1200 typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters; 1203 1201 EdgeWriters edgeWriters; 1204 std::auto_ptr<_writer_bits:: IdWriterBase<Edge> > edgeIdWriter;1202 std::auto_ptr<_writer_bits::LabelWriterBase<Edge> > edgeLabelWriter; 1205 1203 1206 1204 }; … … 1210 1208 /// 1211 1209 /// The lemon format can store multiple attribute set. Each set has 1212 /// the header line \c \@attributes \c attributes et_id, but the1213 /// attributeset_ idmay be empty.1210 /// the header line \c \@attributes \c attributes_name, but the 1211 /// attributeset_name may be empty. 1214 1212 /// 1215 1213 /// The attributeset section contains several lines. Each of them starts … … 1227 1225 /// attach it into the given LemonWriter. 1228 1226 AttributeWriter(LemonWriter& _writer, 1229 const std::string& _ id= std::string())1230 : Parent(_writer), id(_id) {}1227 const std::string& _name = std::string()) 1228 : Parent(_writer), name(_name) {} 1231 1229 1232 1230 /// \brief Destructor. … … 1249 1247 /// Add an attribute writer command for the writer. 1250 1248 template <typename Value> 1251 AttributeWriter& writeAttribute(const std::string& id,1249 AttributeWriter& writeAttribute(const std::string& name, 1252 1250 const Value& value) { 1253 1251 return 1254 writeAttribute<typename Traits::template Writer<Value> >( id, value);1252 writeAttribute<typename Traits::template Writer<Value> >(name, value); 1255 1253 } 1256 1254 … … 1274 1272 /// It gives back the header of the section. 1275 1273 std::string header() { 1276 return "@attributes " + id;1274 return "@attributes " + name; 1277 1275 } 1278 1276 … … 1290 1288 1291 1289 private: 1292 std::string id;1290 std::string name; 1293 1291 1294 1292 typedef std::vector<std::pair<std::string, -
test/Makefile.am
r1847 r1901 11 11 heap_test.h 12 12 13 13 14 check_PROGRAMS = \ 14 15 all_pairs_shortest_path_test \ … … 21 22 graph_utils_test \ 22 23 kruskal_test \ 23 max_matching_test \24 24 maps_test \ 25 25 matrix_maps_test \ 26 max_matching_test \ 26 27 min_cost_flow_test \ 27 28 suurballe_test \ -
test/dijkstra_test.lgf
r1435 r1901 1 1 @nodeset 2 id2 label 3 3 999 4 4 998 … … 1002 1002 0 1003 1003 @edgeset 1004 idcapacity1004 label capacity 1005 1005 75 377 6906 27 1006 1006 417 515 6905 69
Note: See TracChangeset
for help on using the changeset viewer.