src/lemon/graph_reader.h
changeset 1241 dadc9987c537
parent 1208 f486d30e4e7b
child 1250 30f540067a80
equal deleted inserted replaced
3:77f98de403ac 4:e1c0d9d7605a
    16 
    16 
    17 ///\ingroup gio
    17 ///\ingroup gio
    18 ///\file
    18 ///\file
    19 ///\brief Graph reader.
    19 ///\brief Graph reader.
    20 
    20 
       
    21 #ifndef LEMON_GRAPH_READER_H
       
    22 #define LEMON_GRAPH_READER_H
       
    23 
    21 #include <iostream>
    24 #include <iostream>
    22 #include <sstream>
    25 #include <sstream>
    23 
    26 
    24 #include <map>
    27 #include <map>
    25 #include <vector>
    28 #include <vector>
    26 
    29 
    27 #include <memory>
    30 #include <memory>
    28 
    31 
    29 #include <lemon/error.h>
    32 #include <lemon/error.h>
    30 
    33 
    31 /// \todo fix exceptions
       
    32 
       
    33 
    34 
    34 namespace lemon {
    35 namespace lemon {
    35 
       
    36   // Exceptions
       
    37 
    36 
    38 
    37 
    39   /// \brief Standard ReaderTraits for the GraphReader class.
    38   /// \brief Standard ReaderTraits for the GraphReader class.
    40   ///
    39   ///
    41   /// Standard ReaderTraits for the GraphReader class.
    40   /// Standard ReaderTraits for the GraphReader class.
   227     GraphReader& addNodeMap(std::string name, Map& map, 
   226     GraphReader& addNodeMap(std::string name, Map& map, 
   228 			     const Reader& reader = Reader()) {
   227 			     const Reader& reader = Reader()) {
   229       if (node_map_readers.find(name) != node_map_readers.end()) {
   228       if (node_map_readers.find(name) != node_map_readers.end()) {
   230 	ErrorMessage msg;
   229 	ErrorMessage msg;
   231 	msg << "Multiple read rule for node map: " << name;
   230 	msg << "Multiple read rule for node map: " << name;
   232 	throw IOLogicError(msg.message());
   231 	throw IOParameterError(msg.message());
   233       }
   232       }
   234       node_map_readers.insert(
   233       node_map_readers.insert(
   235         make_pair(name, new MapReader<Node, Map, Reader>(map, reader)));
   234         make_pair(name, new MapReader<Node, Map, Reader>(map, reader)));
   236       return *this;
   235       return *this;
   237     }
   236     }
   243     GraphReader& skipNodeMap(std::string name, 
   242     GraphReader& skipNodeMap(std::string name, 
   244 			     const Reader& reader = Reader()) {
   243 			     const Reader& reader = Reader()) {
   245       if (node_map_readers.find(name) != node_map_readers.end()) {
   244       if (node_map_readers.find(name) != node_map_readers.end()) {
   246 	ErrorMessage msg;
   245 	ErrorMessage msg;
   247 	msg << "Multiple read rule for node map: " << name;
   246 	msg << "Multiple read rule for node map: " << name;
   248 	throw IOLogicError(msg.message());
   247 	throw IOParameterError(msg.message());
   249       }
   248       }
   250       node_map_readers.insert(
   249       node_map_readers.insert(
   251         make_pair(name, new SkipReader<Node, Reader>(reader)));
   250         make_pair(name, new SkipReader<Node, Reader>(reader)));
   252       return *this;
   251       return *this;
   253     }
   252     }
   269     GraphReader& addEdgeMap(std::string name, Map& map,
   268     GraphReader& addEdgeMap(std::string name, Map& map,
   270 			     const Reader& reader = Reader()) {
   269 			     const Reader& reader = Reader()) {
   271       if (edge_map_readers.find(name) != edge_map_readers.end()) {
   270       if (edge_map_readers.find(name) != edge_map_readers.end()) {
   272 	ErrorMessage msg;
   271 	ErrorMessage msg;
   273 	msg << "Multiple read rule for edge map: " << name;
   272 	msg << "Multiple read rule for edge map: " << name;
   274 	throw IOLogicError(msg.message());
   273 	throw IOParameterError(msg.message());
   275       }
   274       }
   276       edge_map_readers.insert(
   275       edge_map_readers.insert(
   277         make_pair(name, new MapReader<Edge, Map, Reader>(map, reader)));
   276         make_pair(name, new MapReader<Edge, Map, Reader>(map, reader)));
   278       return *this;
   277       return *this;
   279     }
   278     }
   285     GraphReader& skipEdgeMap(std::string name,
   284     GraphReader& skipEdgeMap(std::string name,
   286 			     const Reader& reader = Reader()) {
   285 			     const Reader& reader = Reader()) {
   287       if (edge_map_readers.find(name) != edge_map_readers.end()) {
   286       if (edge_map_readers.find(name) != edge_map_readers.end()) {
   288 	ErrorMessage msg;
   287 	ErrorMessage msg;
   289 	msg << "Multiple read rule for edge map: " << name;
   288 	msg << "Multiple read rule for edge map: " << name;
   290 	throw IOLogicError(msg.message());
   289 	throw IOParameterError(msg.message());
   291       }
   290       }
   292       edge_map_readers.insert(
   291       edge_map_readers.insert(
   293         make_pair(name, new SkipReader<Edge, Reader>(reader)));
   292         make_pair(name, new SkipReader<Edge, Reader>(reader)));
   294       return *this;
   293       return *this;
   295     }
   294     }
   299     /// Add a new labeled node reader for the reader.
   298     /// Add a new labeled node reader for the reader.
   300     GraphReader& addNode(std::string name, Node& node) {
   299     GraphReader& addNode(std::string name, Node& node) {
   301       if (node_readers.find(name) != node_readers.end()) {
   300       if (node_readers.find(name) != node_readers.end()) {
   302 	ErrorMessage msg;
   301 	ErrorMessage msg;
   303 	msg << "Multiple read rule for node: " << name;
   302 	msg << "Multiple read rule for node: " << name;
   304 	throw IOLogicError(msg.message());
   303 	throw IOParameterError(msg.message());
   305       }
   304       }
   306       node_readers.insert(make_pair(name, &node));
   305       node_readers.insert(make_pair(name, &node));
   307       return *this;
   306       return *this;
   308     }
   307     }
   309 
   308 
   312     /// Add a new labeled edge reader for the reader.
   311     /// Add a new labeled edge reader for the reader.
   313     GraphReader& addEdge(std::string name, Edge& edge) {
   312     GraphReader& addEdge(std::string name, Edge& edge) {
   314       if (edge_readers.find(name) != edge_readers.end()) {
   313       if (edge_readers.find(name) != edge_readers.end()) {
   315 	ErrorMessage msg;
   314 	ErrorMessage msg;
   316 	msg << "Multiple read rule for edge: " << name;
   315 	msg << "Multiple read rule for edge: " << name;
   317 	throw IOLogicError(msg.message());
   316 	throw IOParameterError(msg.message());
   318       }
   317       }
   319       edge_readers.insert(make_pair(name, &edge));
   318       edge_readers.insert(make_pair(name, &edge));
   320       return *this;
   319       return *this;
   321     }
   320     }
   322 
   321 
   691     GraphReader<Graph> reader(is, g);
   690     GraphReader<Graph> reader(is, g);
   692     reader.run();
   691     reader.run();
   693   }
   692   }
   694 
   693 
   695 }
   694 }
       
   695 
       
   696 #endif