198 /// |
198 /// |
199 /// \code |
199 /// \code |
200 /// GraphReader<ListGraph> reader(std::cin, graph); |
200 /// GraphReader<ListGraph> reader(std::cin, graph); |
201 /// \endcode |
201 /// \endcode |
202 /// |
202 /// |
203 /// The \c addNodeMap() function reads a map from the \c \@nodeset section. |
203 /// The \c readNodeMap() function reads a map from the \c \@nodeset section. |
204 /// If there is a map that you do not want to read from the file and there is |
204 /// If there is a map that you do not want to read from the file and there is |
205 /// whitespace in the string represenation of the values then you should |
205 /// whitespace in the string represenation of the values then you should |
206 /// call the \c skipNodeMap() template member function with proper |
206 /// call the \c skipNodeMap() template member function with proper |
207 /// parameters. |
207 /// parameters. |
208 /// |
208 /// |
209 /// \code |
209 /// \code |
210 /// reader.addNodeMap("x-coord", xCoordMap); |
210 /// reader.readNodeMap("x-coord", xCoordMap); |
211 /// reader.addNodeMap("y-coord", yCoordMap); |
211 /// reader.readNodeMap("y-coord", yCoordMap); |
212 /// |
212 /// |
213 /// reader.addNodeMap<QuotedStringReader>("label", labelMap); |
213 /// reader.readNodeMap<QuotedStringReader>("label", labelMap); |
214 /// reader.skipNodeMap<QuotedStringReader>("description"); |
214 /// reader.skipNodeMap<QuotedStringReader>("description"); |
215 /// |
215 /// |
216 /// reader.addNodeMap("color", colorMap); |
216 /// reader.readNodeMap("color", colorMap); |
217 /// \endcode |
217 /// \endcode |
218 /// |
218 /// |
219 /// With the \c addEdgeMap() member function you can give an edge map |
219 /// With the \c readEdgeMap() member function you can give an edge map |
220 /// reading command similar to the NodeMaps. |
220 /// reading command similar to the NodeMaps. |
221 /// |
221 /// |
222 /// \code |
222 /// \code |
223 /// reader.addEdgeMap("weight", weightMap); |
223 /// reader.readEdgeMap("weight", weightMap); |
224 /// reader.addEdgeMap("label", labelMap); |
224 /// reader.readEdgeMap("label", labelMap); |
225 /// \endcode |
225 /// \endcode |
226 /// |
226 /// |
227 /// With \c addNode() and \c addEdge() functions you can read labeled Nodes |
227 /// With \c readNode() and \c readEdge() functions you can read labeled Nodes |
228 /// and Edges. |
228 /// and Edges. |
229 /// |
229 /// |
230 /// \code |
230 /// \code |
231 /// reader.addNode("source", sourceNode); |
231 /// reader.readNode("source", sourceNode); |
232 /// reader.addNode("target", targetNode); |
232 /// reader.readNode("target", targetNode); |
233 /// |
233 /// |
234 /// reader.addEdge("observed", edge); |
234 /// reader.readEdge("observed", edge); |
235 /// \endcode |
235 /// \endcode |
236 /// |
236 /// |
237 /// After you give all read commands you must call the \c run() member |
237 /// After you give all read commands you must call the \c run() member |
238 /// function, which execute all the commands. |
238 /// function, which execute all the commands. |
239 /// |
239 /// |
283 |
283 |
284 /// \brief Add a new node map reader command for the reader. |
284 /// \brief Add a new node map reader command for the reader. |
285 /// |
285 /// |
286 /// Add a new node map reader command for the reader. |
286 /// Add a new node map reader command for the reader. |
287 template <typename Map> |
287 template <typename Map> |
288 GraphReader& addNodeMap(std::string name, Map& map) { |
288 GraphReader& readNodeMap(std::string name, Map& map) { |
289 return addNodeMap<typename ReaderTraits::template |
289 return readNodeMap<typename ReaderTraits::template |
290 Reader<typename Map::Value>, Map>(name, map); |
290 Reader<typename Map::Value>, Map>(name, map); |
291 } |
291 } |
292 |
292 |
293 /// \brief Add a new node map reader command for the reader. |
293 /// \brief Add a new node map reader command for the reader. |
294 /// |
294 /// |
295 /// Add a new node map reader command for the reader. |
295 /// Add a new node map reader command for the reader. |
296 template <typename Reader, typename Map> |
296 template <typename Reader, typename Map> |
297 GraphReader& addNodeMap(std::string name, Map& map, |
297 GraphReader& readNodeMap(std::string name, Map& map, |
298 const Reader& reader = Reader()) { |
298 const Reader& reader = Reader()) { |
299 if (node_map_readers.find(name) != node_map_readers.end()) { |
299 if (node_map_readers.find(name) != node_map_readers.end()) { |
300 ErrorMessage msg; |
300 ErrorMessage msg; |
301 msg << "Multiple read rule for node map: " << name; |
301 msg << "Multiple read rule for node map: " << name; |
302 throw IOParameterError(msg.message()); |
302 throw IOParameterError(msg.message()); |
324 |
324 |
325 /// \brief Add a new edge map reader command for the reader. |
325 /// \brief Add a new edge map reader command for the reader. |
326 /// |
326 /// |
327 /// Add a new edge map reader command for the reader. |
327 /// Add a new edge map reader command for the reader. |
328 template <typename Map> |
328 template <typename Map> |
329 GraphReader& addEdgeMap(std::string name, Map& map) { |
329 GraphReader& readEdgeMap(std::string name, Map& map) { |
330 return addEdgeMap<typename ReaderTraits::template |
330 return readEdgeMap<typename ReaderTraits::template |
331 Reader<typename Map::Value>, Map>(name, map); |
331 Reader<typename Map::Value>, Map>(name, map); |
332 } |
332 } |
333 |
333 |
334 |
334 |
335 /// \brief Add a new edge map reader command for the reader. |
335 /// \brief Add a new edge map reader command for the reader. |
336 /// |
336 /// |
337 /// Add a new edge map reader command for the reader. |
337 /// Add a new edge map reader command for the reader. |
338 template <typename Reader, typename Map> |
338 template <typename Reader, typename Map> |
339 GraphReader& addEdgeMap(std::string name, Map& map, |
339 GraphReader& readEdgeMap(std::string name, Map& map, |
340 const Reader& reader = Reader()) { |
340 const Reader& reader = Reader()) { |
341 if (edge_map_readers.find(name) != edge_map_readers.end()) { |
341 if (edge_map_readers.find(name) != edge_map_readers.end()) { |
342 ErrorMessage msg; |
342 ErrorMessage msg; |
343 msg << "Multiple read rule for edge map: " << name; |
343 msg << "Multiple read rule for edge map: " << name; |
344 throw IOParameterError(msg.message()); |
344 throw IOParameterError(msg.message()); |
365 } |
365 } |
366 |
366 |
367 /// \brief Add a new labeled node reader for the reader. |
367 /// \brief Add a new labeled node reader for the reader. |
368 /// |
368 /// |
369 /// Add a new labeled node reader for the reader. |
369 /// Add a new labeled node reader for the reader. |
370 GraphReader& addNode(std::string name, Node& node) { |
370 GraphReader& readNode(std::string name, Node& node) { |
371 if (node_readers.find(name) != node_readers.end()) { |
371 if (node_readers.find(name) != node_readers.end()) { |
372 ErrorMessage msg; |
372 ErrorMessage msg; |
373 msg << "Multiple read rule for node: " << name; |
373 msg << "Multiple read rule for node: " << name; |
374 throw IOParameterError(msg.message()); |
374 throw IOParameterError(msg.message()); |
375 } |
375 } |
378 } |
378 } |
379 |
379 |
380 /// \brief Add a new labeled edge reader for the reader. |
380 /// \brief Add a new labeled edge reader for the reader. |
381 /// |
381 /// |
382 /// Add a new labeled edge reader for the reader. |
382 /// Add a new labeled edge reader for the reader. |
383 GraphReader& addEdge(std::string name, Edge& edge) { |
383 GraphReader& readEdge(std::string name, Edge& edge) { |
384 if (edge_readers.find(name) != edge_readers.end()) { |
384 if (edge_readers.find(name) != edge_readers.end()) { |
385 ErrorMessage msg; |
385 ErrorMessage msg; |
386 msg << "Multiple read rule for edge: " << name; |
386 msg << "Multiple read rule for edge: " << name; |
387 throw IOParameterError(msg.message()); |
387 throw IOParameterError(msg.message()); |
388 } |
388 } |
752 template<typename Graph, typename CapacityMap, typename CostMap> |
752 template<typename Graph, typename CapacityMap, typename CostMap> |
753 void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, |
753 void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, |
754 typename Graph::Node &s, typename Graph::Node &t, |
754 typename Graph::Node &s, typename Graph::Node &t, |
755 CostMap& cost) { |
755 CostMap& cost) { |
756 GraphReader<Graph> reader(is, g); |
756 GraphReader<Graph> reader(is, g); |
757 reader.addEdgeMap("capacity", capacity); |
757 reader.readEdgeMap("capacity", capacity); |
758 reader.addEdgeMap("cost", cost); |
758 reader.readEdgeMap("cost", cost); |
759 reader.addNode("source", s); |
759 reader.readNode("source", s); |
760 reader.addNode("target", t); |
760 reader.readNode("target", t); |
761 reader.run(); |
761 reader.run(); |
762 } |
762 } |
763 |
763 |
764 /// \brief Read a graph from the input. |
764 /// \brief Read a graph from the input. |
765 /// |
765 /// |
771 /// \param t The target node. |
771 /// \param t The target node. |
772 template<typename Graph, typename CapacityMap> |
772 template<typename Graph, typename CapacityMap> |
773 void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, |
773 void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, |
774 typename Graph::Node &s, typename Graph::Node &t) { |
774 typename Graph::Node &s, typename Graph::Node &t) { |
775 GraphReader<Graph> reader(is, g); |
775 GraphReader<Graph> reader(is, g); |
776 reader.addEdgeMap("capacity", capacity); |
776 reader.readEdgeMap("capacity", capacity); |
777 reader.addNode("source", s); |
777 reader.readNode("source", s); |
778 reader.addNode("target", t); |
778 reader.readNode("target", t); |
779 reader.run(); |
779 reader.run(); |
780 } |
780 } |
781 |
781 |
782 /// \brief Read a graph from the input. |
782 /// \brief Read a graph from the input. |
783 /// |
783 /// |
788 /// \param s The source node. |
788 /// \param s The source node. |
789 template<typename Graph, typename CapacityMap> |
789 template<typename Graph, typename CapacityMap> |
790 void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, |
790 void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, |
791 typename Graph::Node &s) { |
791 typename Graph::Node &s) { |
792 GraphReader<Graph> reader(is, g); |
792 GraphReader<Graph> reader(is, g); |
793 reader.addEdgeMap("capacity", capacity); |
793 reader.readEdgeMap("capacity", capacity); |
794 reader.addNode("source", s); |
794 reader.readNode("source", s); |
795 reader.run(); |
795 reader.run(); |
796 } |
796 } |
797 |
797 |
798 /// \brief Read a graph from the input. |
798 /// \brief Read a graph from the input. |
799 /// |
799 /// |
802 /// \param g The graph. |
802 /// \param g The graph. |
803 /// \param capacity The capacity map. |
803 /// \param capacity The capacity map. |
804 template<typename Graph, typename CapacityMap> |
804 template<typename Graph, typename CapacityMap> |
805 void readGraph(std::istream& is, Graph &g, CapacityMap& capacity) { |
805 void readGraph(std::istream& is, Graph &g, CapacityMap& capacity) { |
806 GraphReader<Graph> reader(is, g); |
806 GraphReader<Graph> reader(is, g); |
807 reader.addEdgeMap("capacity", capacity); |
807 reader.readEdgeMap("capacity", capacity); |
808 reader.run(); |
808 reader.run(); |
809 } |
809 } |
810 |
810 |
811 /// \brief Read a graph from the input. |
811 /// \brief Read a graph from the input. |
812 /// |
812 /// |