lemon/graph_reader.h
changeset 2478 bf783151bc92
parent 2391 14a343be7a5a
child 2502 9c23c3762bc5
equal deleted inserted replaced
18:8baf8faed29a 19:03614bc310bd
   322     /// \brief Gives back the edge by its label.
   322     /// \brief Gives back the edge by its label.
   323     ///
   323     ///
   324     /// It reads an label from the stream and gives back which edge belongs to
   324     /// It reads an label from the stream and gives back which edge belongs to
   325     /// it. It is possible only if there was read a "label" named edge map.
   325     /// it. It is possible only if there was read a "label" named edge map.
   326     void readLabel(std::istream& is, Edge& edge) const {
   326     void readLabel(std::istream& is, Edge& edge) const {
   327       return edgeset_reader.readLabel(is, edge);
   327       edgeset_reader.readLabel(is, edge);
   328     } 
   328     } 
   329 
   329 
   330   private:
   330   private:
   331 
   331 
   332     LemonReader* reader;
   332     LemonReader* reader;
   441     /// and it use the given reader as the default skipper.
   441     /// and it use the given reader as the default skipper.
   442     UGraphReader(std::istream& _is, Graph& _graph, 
   442     UGraphReader(std::istream& _is, Graph& _graph, 
   443 		     const DefaultSkipper& _skipper = DefaultSkipper()) 
   443 		     const DefaultSkipper& _skipper = DefaultSkipper()) 
   444       : reader(new LemonReader(_is)), own_reader(true), skipper(_skipper),
   444       : reader(new LemonReader(_is)), own_reader(true), skipper(_skipper),
   445 	nodeset_reader(*reader, _graph, std::string(), skipper),
   445 	nodeset_reader(*reader, _graph, std::string(), skipper),
   446 	u_edgeset_reader(*reader, _graph, nodeset_reader, 
   446 	uedgeset_reader(*reader, _graph, nodeset_reader, 
   447 			     std::string(), skipper),
   447 			     std::string(), skipper),
   448 	node_reader(*reader, nodeset_reader, std::string()),
   448 	node_reader(*reader, nodeset_reader, std::string()),
   449 	u_edge_reader(*reader, u_edgeset_reader, std::string()),
   449 	uedge_reader(*reader, uedgeset_reader, std::string()),
   450 	attribute_reader(*reader, std::string()) {}
   450 	attribute_reader(*reader, std::string()) {}
   451 
   451 
   452     /// \brief Construct a new UGraphReader.
   452     /// \brief Construct a new UGraphReader.
   453     ///
   453     ///
   454     /// Construct a new UGraphReader. It reads into the given graph
   454     /// Construct a new UGraphReader. It reads into the given graph
   456     UGraphReader(const std::string& _filename, Graph& _graph, 
   456     UGraphReader(const std::string& _filename, Graph& _graph, 
   457 		     const DefaultSkipper& _skipper = DefaultSkipper()) 
   457 		     const DefaultSkipper& _skipper = DefaultSkipper()) 
   458       : reader(new LemonReader(_filename)), own_reader(true), 
   458       : reader(new LemonReader(_filename)), own_reader(true), 
   459 	skipper(_skipper),
   459 	skipper(_skipper),
   460 	nodeset_reader(*reader, _graph, std::string(), skipper),
   460 	nodeset_reader(*reader, _graph, std::string(), skipper),
   461 	u_edgeset_reader(*reader, _graph, nodeset_reader, 
   461 	uedgeset_reader(*reader, _graph, nodeset_reader, 
   462 			     std::string(), skipper),
   462 			     std::string(), skipper),
   463 	node_reader(*reader, nodeset_reader, std::string()),
   463 	node_reader(*reader, nodeset_reader, std::string()),
   464 	u_edge_reader(*reader, u_edgeset_reader, std::string()),
   464 	uedge_reader(*reader, uedgeset_reader, std::string()),
   465 	attribute_reader(*reader, std::string()) {}
   465 	attribute_reader(*reader, std::string()) {}
   466 
   466 
   467     /// \brief Construct a new UGraphReader.
   467     /// \brief Construct a new UGraphReader.
   468     ///
   468     ///
   469     /// Construct a new UGraphReader. It reads into the given graph
   469     /// Construct a new UGraphReader. It reads into the given graph
   470     /// and it use the given reader as the default skipper.
   470     /// and it use the given reader as the default skipper.
   471     UGraphReader(LemonReader& _reader, Graph& _graph, 
   471     UGraphReader(LemonReader& _reader, Graph& _graph, 
   472 		     const DefaultSkipper& _skipper = DefaultSkipper()) 
   472 		     const DefaultSkipper& _skipper = DefaultSkipper()) 
   473       : reader(_reader), own_reader(false), skipper(_skipper),
   473       : reader(_reader), own_reader(false), skipper(_skipper),
   474 	nodeset_reader(*reader, _graph, std::string(), skipper),
   474 	nodeset_reader(*reader, _graph, std::string(), skipper),
   475 	u_edgeset_reader(*reader, _graph, nodeset_reader, 
   475 	uedgeset_reader(*reader, _graph, nodeset_reader, 
   476 			     std::string(), skipper),
   476 			     std::string(), skipper),
   477 	node_reader(*reader, nodeset_reader, std::string()),
   477 	node_reader(*reader, nodeset_reader, std::string()),
   478 	u_edge_reader(*reader, u_edgeset_reader, std::string()),
   478 	uedge_reader(*reader, uedgeset_reader, std::string()),
   479 	attribute_reader(*reader, std::string()) {}
   479 	attribute_reader(*reader, std::string()) {}
   480 
   480 
   481     /// \brief Destruct the graph reader.
   481     /// \brief Destruct the graph reader.
   482     ///
   482     ///
   483     /// Destruct the graph reader.
   483     /// Destruct the graph reader.
   531     /// \brief Give a new undirected edge map reading command to the reader.
   531     /// \brief Give a new undirected edge map reading command to the reader.
   532     ///
   532     ///
   533     /// Give a new undirected edge map reading command to the reader.
   533     /// Give a new undirected edge map reading command to the reader.
   534     template <typename Map>
   534     template <typename Map>
   535     UGraphReader& readUEdgeMap(std::string name, Map& map) { 
   535     UGraphReader& readUEdgeMap(std::string name, Map& map) { 
   536       u_edgeset_reader.readUEdgeMap(name, map);
   536       uedgeset_reader.readUEdgeMap(name, map);
   537       return *this;
   537       return *this;
   538     }
   538     }
   539 
   539 
   540     template <typename Map>
   540     template <typename Map>
   541     UGraphReader& readUEdgeMap(std::string name, const Map& map) { 
   541     UGraphReader& readUEdgeMap(std::string name, const Map& map) { 
   542       u_edgeset_reader.readUEdgeMap(name, map);
   542       uedgeset_reader.readUEdgeMap(name, map);
   543       return *this;
   543       return *this;
   544     }
   544     }
   545 
   545 
   546 
   546 
   547     /// \brief Give a new undirected edge map reading command to the reader.
   547     /// \brief Give a new undirected edge map reading command to the reader.
   548     ///
   548     ///
   549     /// Give a new undirected edge map reading command to the reader.
   549     /// Give a new undirected edge map reading command to the reader.
   550     template <typename ItemReader, typename Map>
   550     template <typename ItemReader, typename Map>
   551     UGraphReader& readUEdgeMap(std::string name, Map& map,
   551     UGraphReader& readUEdgeMap(std::string name, Map& map,
   552                                const ItemReader& ir = ItemReader()) {
   552                                const ItemReader& ir = ItemReader()) {
   553       u_edgeset_reader.readUEdgeMap(name, map, ir);
   553       uedgeset_reader.readUEdgeMap(name, map, ir);
   554       return *this;
   554       return *this;
   555     }
   555     }
   556 
   556 
   557     template <typename ItemReader, typename Map>
   557     template <typename ItemReader, typename Map>
   558     UGraphReader& readUEdgeMap(std::string name, const Map& map,
   558     UGraphReader& readUEdgeMap(std::string name, const Map& map,
   559                                const ItemReader& ir = ItemReader()) {
   559                                const ItemReader& ir = ItemReader()) {
   560       u_edgeset_reader.readUEdgeMap(name, map, ir);
   560       uedgeset_reader.readUEdgeMap(name, map, ir);
   561       return *this;
   561       return *this;
   562     }
   562     }
   563 
   563 
   564     /// \brief Give a new undirected edge map skipping command to the reader.
   564     /// \brief Give a new undirected edge map skipping command to the reader.
   565     ///
   565     ///
   566     /// Give a new undirected edge map skipping command to the reader.
   566     /// Give a new undirected edge map skipping command to the reader.
   567     template <typename ItemReader>
   567     template <typename ItemReader>
   568     UGraphReader& skipUEdgeMap(std::string name,
   568     UGraphReader& skipUEdgeMap(std::string name,
   569 				       const ItemReader& ir = ItemReader()) {
   569 				       const ItemReader& ir = ItemReader()) {
   570       u_edgeset_reader.skipUMap(name, ir);
   570       uedgeset_reader.skipUMap(name, ir);
   571       return *this;
   571       return *this;
   572     }
   572     }
   573 
   573 
   574 
   574 
   575     /// \brief Give a new edge map reading command to the reader.
   575     /// \brief Give a new edge map reading command to the reader.
   576     ///
   576     ///
   577     /// Give a new edge map reading command to the reader.
   577     /// Give a new edge map reading command to the reader.
   578     template <typename Map>
   578     template <typename Map>
   579     UGraphReader& readEdgeMap(std::string name, Map& map) { 
   579     UGraphReader& readEdgeMap(std::string name, Map& map) { 
   580       u_edgeset_reader.readEdgeMap(name, map);
   580       uedgeset_reader.readEdgeMap(name, map);
   581       return *this;
   581       return *this;
   582     }
   582     }
   583 
   583 
   584     template <typename Map>
   584     template <typename Map>
   585     UGraphReader& readEdgeMap(std::string name, const Map& map) { 
   585     UGraphReader& readEdgeMap(std::string name, const Map& map) { 
   586       u_edgeset_reader.readEdgeMap(name, map);
   586       uedgeset_reader.readEdgeMap(name, map);
   587       return *this;
   587       return *this;
   588     }
   588     }
   589 
   589 
   590 
   590 
   591     /// \brief Give a new edge map reading command to the reader.
   591     /// \brief Give a new edge map reading command to the reader.
   592     ///
   592     ///
   593     /// Give a new edge map reading command to the reader.
   593     /// Give a new edge map reading command to the reader.
   594     template <typename ItemReader, typename Map>
   594     template <typename ItemReader, typename Map>
   595     UGraphReader& readEdgeMap(std::string name, Map& map,
   595     UGraphReader& readEdgeMap(std::string name, Map& map,
   596                               const ItemReader& ir = ItemReader()) {
   596                               const ItemReader& ir = ItemReader()) {
   597       u_edgeset_reader.readEdgeMap(name, map, ir);
   597       uedgeset_reader.readEdgeMap(name, map, ir);
   598       return *this;
   598       return *this;
   599     }
   599     }
   600 
   600 
   601     template <typename ItemReader, typename Map>
   601     template <typename ItemReader, typename Map>
   602     UGraphReader& readEdgeMap(std::string name, const Map& map,
   602     UGraphReader& readEdgeMap(std::string name, const Map& map,
   603                               const ItemReader& ir = ItemReader()) {
   603                               const ItemReader& ir = ItemReader()) {
   604       u_edgeset_reader.readEdgeMap(name, map, ir);
   604       uedgeset_reader.readEdgeMap(name, map, ir);
   605       return *this;
   605       return *this;
   606     }
   606     }
   607 
   607 
   608     /// \brief Give a new edge map skipping command to the reader.
   608     /// \brief Give a new edge map skipping command to the reader.
   609     ///
   609     ///
   610     /// Give a new edge map skipping command to the reader.
   610     /// Give a new edge map skipping command to the reader.
   611     template <typename ItemReader>
   611     template <typename ItemReader>
   612     UGraphReader& skipEdgeMap(std::string name,
   612     UGraphReader& skipEdgeMap(std::string name,
   613                               const ItemReader& ir = ItemReader()) {
   613                               const ItemReader& ir = ItemReader()) {
   614       u_edgeset_reader.skipEdgeMap(name, ir);
   614       uedgeset_reader.skipEdgeMap(name, ir);
   615       return *this;
   615       return *this;
   616     }
   616     }
   617 
   617 
   618     /// \brief Give a new labeled node reading command to the reader.
   618     /// \brief Give a new labeled node reading command to the reader.
   619     ///
   619     ///
   625 
   625 
   626     /// \brief Give a new labeled edge reading command to the reader.
   626     /// \brief Give a new labeled edge reading command to the reader.
   627     ///
   627     ///
   628     /// Give a new labeled edge reading command to the reader.
   628     /// Give a new labeled edge reading command to the reader.
   629     UGraphReader& readEdge(std::string name, Edge& edge) {
   629     UGraphReader& readEdge(std::string name, Edge& edge) {
   630       u_edge_reader.readEdge(name, edge);
   630       uedge_reader.readEdge(name, edge);
   631     }
   631     }
   632 
   632 
   633     /// \brief Give a new labeled undirected edge reading command to the
   633     /// \brief Give a new labeled undirected edge reading command to the
   634     /// reader.
   634     /// reader.
   635     ///
   635     ///
   636     /// Give a new labeled undirected edge reading command to the reader.
   636     /// Give a new labeled undirected edge reading command to the reader.
   637     UGraphReader& readUEdge(std::string name, UEdge& edge) {
   637     UGraphReader& readUEdge(std::string name, UEdge& edge) {
   638       u_edge_reader.readUEdge(name, edge);
   638       uedge_reader.readUEdge(name, edge);
   639     }
   639     }
   640 
   640 
   641     /// \brief Give a new attribute reading command.
   641     /// \brief Give a new attribute reading command.
   642     ///
   642     ///
   643     ///  Give a new attribute reading command.
   643     ///  Give a new attribute reading command.
   675     }
   675     }
   676 
   676 
   677 
   677 
   678     /// \brief Returns true if the reader can give back the items by its label.
   678     /// \brief Returns true if the reader can give back the items by its label.
   679     ///
   679     ///
   680     /// \brief Returns true if the reader can give back the items by its label.
   680     /// Returns true if the reader can give back the items by its label.
   681     bool isLabelReader() const {
   681     bool isLabelReader() const {
   682       return nodeset_reader.isLabelReader() && 
   682       return nodeset_reader.isLabelReader() && 
   683         u_edgeset_reader.isLabelReader();
   683         uedgeset_reader.isLabelReader();
   684     }
   684     }
   685 
   685 
   686     /// \brief Gives back the node by its label.
   686     /// \brief Gives back the node by its label.
   687     ///
   687     ///
   688     /// It reads an label from the stream and gives back which node belongs to
   688     /// It reads an label from the stream and gives back which node belongs to
   694     /// \brief Gives back the edge by its label
   694     /// \brief Gives back the edge by its label
   695     ///
   695     ///
   696     /// It reads an label from the stream and gives back which edge belongs to
   696     /// It reads an label from the stream and gives back which edge belongs to
   697     /// it. It is possible only if there was read a "label" named edge map.
   697     /// it. It is possible only if there was read a "label" named edge map.
   698     void readLabel(std::istream& is, Edge& edge) const {
   698     void readLabel(std::istream& is, Edge& edge) const {
   699       return u_edgeset_reader.readLabel(is, edge);
   699       return uedgeset_reader.readLabel(is, edge);
   700     } 
   700     } 
   701 
   701 
   702     /// \brief Gives back the undirected edge by its label.
   702     /// \brief Gives back the undirected edge by its label.
   703     ///
   703     ///
   704     /// It reads an label from the stream and gives back which undirected edge 
   704     /// It reads an label from the stream and gives back which undirected edge 
   705     /// belongs to it. It is possible only if there was read a "label" named 
   705     /// belongs to it. It is possible only if there was read a "label" named 
   706     /// edge map.
   706     /// edge map.
   707     void readLabel(std::istream& is, UEdge& uedge) const {
   707     void readLabel(std::istream& is, UEdge& uedge) const {
   708       return u_edgeset_reader.readLabel(is, uedge);
   708       return uedgeset_reader.readLabel(is, uedge);
   709     } 
   709     } 
   710     
   710     
   711 
   711 
   712   private:
   712   private:
   713 
   713 
   715     bool own_reader;
   715     bool own_reader;
   716 
   716 
   717     DefaultSkipper skipper;
   717     DefaultSkipper skipper;
   718 
   718 
   719     NodeSetReader<Graph, ReaderTraits> nodeset_reader;
   719     NodeSetReader<Graph, ReaderTraits> nodeset_reader;
   720     UEdgeSetReader<Graph, ReaderTraits> u_edgeset_reader;
   720     UEdgeSetReader<Graph, ReaderTraits> uedgeset_reader;
   721 
   721 
   722     NodeReader<Graph> node_reader;
   722     NodeReader<Graph> node_reader;
   723     UEdgeReader<Graph> u_edge_reader;
   723     UEdgeReader<Graph> uedge_reader;
   724     
   724     
   725     AttributeReader<ReaderTraits> attribute_reader;
   725     AttributeReader<ReaderTraits> attribute_reader;
   726   };
   726   };
   727 
   727 
   728 
   728