lemon/lemon_reader.h
changeset 2387 317b9a88c350
parent 2368 6b2e8b734ae7
child 2391 14a343be7a5a
equal deleted inserted replaced
29:31bd93628ecd 30:da977104d16e
   531 	_eptr = buf + len;
   531 	_eptr = buf + len;
   532       }
   532       }
   533   
   533   
   534       virtual std::streambuf* setbuf(char *buf, std::streamsize len) {
   534       virtual std::streambuf* setbuf(char *buf, std::streamsize len) {
   535 	if (base()) return 0;
   535 	if (base()) return 0;
   536 	if (buf != 0 && len >= (int)sizeof(small_buf)) {
   536 	if (buf != 0 && len >= int(sizeof(small_buf))) {
   537 	  setb(buf, len);
   537 	  setb(buf, len);
   538 	} else {
   538 	} else {
   539 	  setb(small_buf, sizeof(small_buf));
   539 	  setb(small_buf, sizeof(small_buf));
   540 	}
   540 	}
   541 	setg(0, 0, 0);
   541 	setg(0, 0, 0);
   707 	    if (it->first->header(line)) {
   707 	    if (it->first->header(line)) {
   708               it->second = true;
   708               it->second = true;
   709 	      char buf[2048];
   709 	      char buf[2048];
   710 	      FilterStreamBuf buffer(*is, line_num);
   710 	      FilterStreamBuf buffer(*is, line_num);
   711 	      buffer.pubsetbuf(buf, sizeof(buf));
   711 	      buffer.pubsetbuf(buf, sizeof(buf));
   712 	      std::istream is(&buffer);
   712 	      std::istream ss(&buffer);
   713 	      it->first->read(is);
   713 	      it->first->read(ss);
   714 	      break;
   714 	      break;
   715 	    }
   715 	    }
   716 	  }
   716 	  }
   717 	}
   717 	}
   718         for (it = readers.begin(); it != readers.end(); ++it) {
   718         for (it = readers.begin(); it != readers.end(); ++it) {
   795 
   795 
   796     /// \brief Add a new node map reader command for the reader.
   796     /// \brief Add a new node map reader command for the reader.
   797     ///
   797     ///
   798     /// Add a new node map reader command for the reader.
   798     /// Add a new node map reader command for the reader.
   799     template <typename Map>
   799     template <typename Map>
   800     NodeSetReader& readNodeMap(std::string name, Map& map) {
   800     NodeSetReader& readNodeMap(std::string label, Map& map) {
   801       return _readMap<
   801       return _readMap<
   802 	typename Traits::template Reader<typename Map::Value>, Map,
   802 	typename Traits::template Reader<typename Map::Value>, Map,
   803 	typename _reader_bits::Arg<Map>::Type>(name, map);
   803 	typename _reader_bits::Arg<Map>::Type>(label, map);
   804     }
   804     }
   805 
   805 
   806     template <typename Map>
   806     template <typename Map>
   807     NodeSetReader& readNodeMap(std::string name, const Map& map) {
   807     NodeSetReader& readNodeMap(std::string label, const Map& map) {
   808       return _readMap<
   808       return _readMap<
   809 	typename Traits::template Reader<typename Map::Value>, Map,
   809 	typename Traits::template Reader<typename Map::Value>, Map,
   810 	typename _reader_bits::Arg<Map>::Type>(name, map);
   810 	typename _reader_bits::Arg<Map>::Type>(label, map);
   811     }
   811     }
   812 
   812 
   813     /// \brief Add a new node map reader command for the reader.
   813     /// \brief Add a new node map reader command for the reader.
   814     ///
   814     ///
   815     /// Add a new node map reader command for the reader.
   815     /// Add a new node map reader command for the reader.
   816     template <typename Reader, typename Map>
   816     template <typename ItemReader, typename Map>
   817     NodeSetReader& readNodeMap(std::string name, Map& map, 
   817     NodeSetReader& readNodeMap(std::string label, Map& map, 
   818 			       const Reader& reader = Reader()) {
   818 			       const ItemReader& ir = ItemReader()) {
   819       return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
   819       return _readMap<ItemReader, Map, typename _reader_bits::Arg<Map>::Type>
   820 	(name, map, reader);
   820 	(label, map, ir);
   821     }
   821     }
   822 
   822 
   823     template <typename Reader, typename Map>
   823     template <typename ItemReader, typename Map>
   824     NodeSetReader& readNodeMap(std::string name, const Map& map, 
   824     NodeSetReader& readNodeMap(std::string label, const Map& map, 
   825 			       const Reader& reader = Reader()) {
   825 			       const ItemReader& ir = ItemReader()) {
   826       return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
   826       return _readMap<ItemReader, Map, typename _reader_bits::Arg<Map>::Type>
   827 	(name, map, reader);
   827 	(label, map, ir);
   828     }
   828     }
   829 
   829 
   830   private:
   830   private:
   831 
   831 
   832     template <typename Reader, typename Map, typename MapParameter>
   832     template <typename ItemReader, typename Map, typename MapParameter>
   833     NodeSetReader& _readMap(std::string name, MapParameter map, 
   833     NodeSetReader& _readMap(std::string label, MapParameter map, 
   834 			    const Reader& reader = Reader()) {
   834 			    const ItemReader& ir = ItemReader()) {
   835       checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
   835       checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
   836       checkConcept<_reader_bits::ItemReader<typename Map::Value>, Reader>();
   836       checkConcept<_reader_bits::ItemReader<typename Map::Value>, ItemReader>();
   837       if (readers.find(name) != readers.end()) {
   837       if (readers.find(label) != readers.end()) {
   838 	ErrorMessage msg;
   838 	ErrorMessage msg;
   839 	msg << "Multiple read rule for node map: " << name;
   839 	msg << "Multiple read rule for node map: " << label;
   840 	throw IoParameterError(msg.message());
   840 	throw IoParameterError(msg.message());
   841       }      
   841       }      
   842       readers.insert(
   842       readers.insert(
   843         make_pair(name, new _reader_bits::
   843         make_pair(label, new _reader_bits::
   844 		  MapReader<Node, Map, Reader>(map, reader)));
   844 		  MapReader<Node, Map, ItemReader>(map, ir)));
   845       return *this;
   845       return *this;
   846     }
   846     }
   847 
   847 
   848   public:
   848   public:
   849 
   849 
   850     /// \brief Add a new node map skipper command for the reader.
   850     /// \brief Add a new node map skipper command for the reader.
   851     ///
   851     ///
   852     /// Add a new node map skipper command for the reader.
   852     /// Add a new node map skipper command for the reader.
   853     template <typename Reader>
   853     template <typename ItemReader>
   854     NodeSetReader& skipNodeMap(std::string name, 
   854     NodeSetReader& skipNodeMap(std::string label, 
   855 			   const Reader& reader = Reader()) {
   855                                const ItemReader& ir = ItemReader()) {
   856       if (readers.find(name) != readers.end()) {
   856       if (readers.find(label) != readers.end()) {
   857 	ErrorMessage msg;
   857 	ErrorMessage msg;
   858 	msg << "Multiple read rule for node map: " << name;
   858 	msg << "Multiple read rule for node map: " << label;
   859 	throw IoParameterError(msg.message());
   859 	throw IoParameterError(msg.message());
   860       }
   860       }
   861       readers.insert(make_pair(name, new _reader_bits::
   861       readers.insert(make_pair(label, new _reader_bits::
   862 			       SkipReader<Node, Reader>(reader)));
   862 			       SkipReader<Node, ItemReader>(ir)));
   863       return *this;
   863       return *this;
   864     }
   864     }
   865 
   865 
   866   protected:
   866   protected:
   867 
   867 
   883     /// It reads the content of the section.
   883     /// It reads the content of the section.
   884     virtual void read(std::istream& is) {
   884     virtual void read(std::istream& is) {
   885       std::vector<_reader_bits::MapReaderBase<Node>* > index;
   885       std::vector<_reader_bits::MapReaderBase<Node>* > index;
   886       std::string line;
   886       std::string line;
   887 
   887 
   888       getline(is, line);
   888       {
   889       std::istringstream ls(line);
   889         getline(is, line);
   890       std::string id;
   890         std::istringstream ls(line);
   891       while (ls >> id) {
   891         std::string id;
   892 	typename MapReaders::iterator it = readers.find(id);
   892         while (ls >> id) {
   893 	if (it != readers.end()) {
   893           typename MapReaders::iterator it = readers.find(id);
   894 	  it->second->touch();
   894           if (it != readers.end()) {
   895 	  index.push_back(it->second);
   895             it->second->touch();
   896 	} else {
   896             index.push_back(it->second);
   897 	  index.push_back(&skipper);
   897           } else {
   898 	}
   898             index.push_back(&skipper);
   899 	if (id == "label") {
   899           }
   900 	  inverter.reset(index.back()->getInverter());
   900           if (id == "label") {
   901 	  index.back() = inverter.get();
   901             inverter.reset(index.back()->getInverter());
   902 	}
   902             index.back() = inverter.get();
       
   903           }
       
   904         }
   903       }
   905       }
   904       for (typename MapReaders::iterator it = readers.begin();
   906       for (typename MapReaders::iterator it = readers.begin();
   905 	   it != readers.end(); ++it) {
   907 	   it != readers.end(); ++it) {
   906 	if (!it->second->touched()) {
   908 	if (!it->second->touched()) {
   907 	  ErrorMessage msg;
   909 	  ErrorMessage msg;
   910 	}
   912 	}
   911       }
   913       }
   912       while (getline(is, line)) {	
   914       while (getline(is, line)) {	
   913 	Node node = graph.addNode();
   915 	Node node = graph.addNode();
   914 	std::istringstream ls(line);
   916 	std::istringstream ls(line);
   915 	for (int i = 0; i < (int)index.size(); ++i) {
   917 	for (int i = 0; i < int(index.size()); ++i) {
   916 	  index[i]->read(ls, node);
   918 	  index[i]->read(ls, node);
   917 	}
   919 	}
   918       }
   920       }
   919     }
   921     }
   920 
   922 
  1025 
  1027 
  1026     /// \brief Add a new edge map reader command for the reader.
  1028     /// \brief Add a new edge map reader command for the reader.
  1027     ///
  1029     ///
  1028     /// Add a new edge map reader command for the reader.
  1030     /// Add a new edge map reader command for the reader.
  1029     template <typename Map>
  1031     template <typename Map>
  1030     EdgeSetReader& readEdgeMap(std::string name, Map& map) {
  1032     EdgeSetReader& readEdgeMap(std::string label, Map& map) {
  1031       return _readMap<
  1033       return _readMap<
  1032 	typename Traits::template Reader<typename Map::Value>, Map,
  1034 	typename Traits::template Reader<typename Map::Value>, Map,
  1033 	typename _reader_bits::Arg<Map>::Type>(name, map);
  1035 	typename _reader_bits::Arg<Map>::Type>(label, map);
  1034     }
  1036     }
  1035 
  1037 
  1036     template <typename Map>
  1038     template <typename Map>
  1037     EdgeSetReader& readEdgeMap(std::string name, const Map& map) {
  1039     EdgeSetReader& readEdgeMap(std::string label, const Map& map) {
  1038       return _readMap<
  1040       return _readMap<
  1039 	typename Traits::template Reader<typename Map::Value>, Map,
  1041 	typename Traits::template Reader<typename Map::Value>, Map,
  1040 	typename _reader_bits::Arg<Map>::Type>(name, map);
  1042 	typename _reader_bits::Arg<Map>::Type>(label, map);
  1041     }
  1043     }
  1042 
  1044 
  1043     /// \brief Add a new edge map reader command for the reader.
  1045     /// \brief Add a new edge map reader command for the reader.
  1044     ///
  1046     ///
  1045     /// Add a new edge map reader command for the reader.
  1047     /// Add a new edge map reader command for the reader.
  1046     template <typename Reader, typename Map>
  1048     template <typename ItemReader, typename Map>
  1047     EdgeSetReader& readEdgeMap(std::string name, Map& map, 
  1049     EdgeSetReader& readEdgeMap(std::string label, Map& map, 
  1048 			   const Reader& reader = Reader()) {
  1050                                const ItemReader& ir = ItemReader()) {
  1049       return _readMap<Reader, Map,
  1051       return _readMap<ItemReader, Map,
  1050 	typename _reader_bits::Arg<Map>::Type>(name, map, reader);
  1052 	typename _reader_bits::Arg<Map>::Type>(label, map, ir);
  1051     }
  1053     }
  1052 
  1054 
  1053     template <typename Reader, typename Map>
  1055     template <typename ItemReader, typename Map>
  1054     EdgeSetReader& readEdgeMap(std::string name, const Map& map, 
  1056     EdgeSetReader& readEdgeMap(std::string label, const Map& map, 
  1055 			       const Reader& reader = Reader()) {
  1057 			       const ItemReader& ir = ItemReader()) {
  1056       return _readMap<Reader, Map,
  1058       return _readMap<ItemReader, Map,
  1057 	typename _reader_bits::Arg<Map>::Type>(name, map, reader);
  1059 	typename _reader_bits::Arg<Map>::Type>(label, map, ir);
  1058     }
  1060     }
  1059 
  1061 
  1060   private:
  1062   private:
  1061 
  1063 
  1062     template <typename Reader, typename Map, typename MapParameter>
  1064     template <typename ItemReader, typename Map, typename MapParameter>
  1063     EdgeSetReader& _readMap(std::string name, MapParameter map, 
  1065     EdgeSetReader& _readMap(std::string label, MapParameter map, 
  1064 			    const Reader& reader = Reader()) {
  1066 			    const ItemReader& ir = ItemReader()) {
  1065       checkConcept<concepts::WriteMap<Edge, typename Map::Value>, Map>();
  1067       checkConcept<concepts::WriteMap<Edge, typename Map::Value>, Map>();
  1066       checkConcept<_reader_bits::ItemReader<typename Map::Value>, Reader>();
  1068       checkConcept<_reader_bits::ItemReader<typename Map::Value>, ItemReader>();
  1067       if (readers.find(name) != readers.end()) {
  1069       if (readers.find(label) != readers.end()) {
  1068 	ErrorMessage msg;
  1070 	ErrorMessage msg;
  1069 	msg << "Multiple read rule for edge map: " << name;
  1071 	msg << "Multiple read rule for edge map: " << label;
  1070 	throw IoParameterError(msg.message());
  1072 	throw IoParameterError(msg.message());
  1071       }
  1073       }
  1072       readers.insert(
  1074       readers.insert(
  1073 	make_pair(name, new _reader_bits::
  1075 	make_pair(label, new _reader_bits::
  1074 		  MapReader<Edge, Map, Reader>(map, reader)));
  1076 		  MapReader<Edge, Map, ItemReader>(map, ir)));
  1075       return *this;
  1077       return *this;
  1076     }
  1078     }
  1077 
  1079 
  1078   public:
  1080   public:
  1079 
  1081 
  1080     /// \brief Add a new edge map skipper command for the reader.
  1082     /// \brief Add a new edge map skipper command for the reader.
  1081     ///
  1083     ///
  1082     /// Add a new edge map skipper command for the reader.
  1084     /// Add a new edge map skipper command for the reader.
  1083     template <typename Reader>
  1085     template <typename ItemReader>
  1084     EdgeSetReader& skipEdgeMap(std::string name, 
  1086     EdgeSetReader& skipEdgeMap(std::string label, 
  1085 			       const Reader& reader = Reader()) {
  1087 			       const ItemReader& ir = ItemReader()) {
  1086       if (readers.find(name) != readers.end()) {
  1088       if (readers.find(label) != readers.end()) {
  1087 	ErrorMessage msg;
  1089 	ErrorMessage msg;
  1088 	msg << "Multiple read rule for edge map: " << name;
  1090 	msg << "Multiple read rule for edge map: " << label;
  1089 	throw IoParameterError(msg.message());
  1091 	throw IoParameterError(msg.message());
  1090       }
  1092       }
  1091       readers.insert(make_pair(name, new _reader_bits::
  1093       readers.insert(make_pair(label, new _reader_bits::
  1092 			       SkipReader<Edge, Reader>(reader)));
  1094 			       SkipReader<Edge, ItemReader>(ir)));
  1093       return *this;
  1095       return *this;
  1094     }
  1096     }
  1095 
  1097 
  1096   protected:
  1098   protected:
  1097 
  1099 
  1116 	throw DataFormatError("Cannot find nodeset or label map");
  1118 	throw DataFormatError("Cannot find nodeset or label map");
  1117       }
  1119       }
  1118       std::vector<_reader_bits::MapReaderBase<Edge>* > index;
  1120       std::vector<_reader_bits::MapReaderBase<Edge>* > index;
  1119       std::string line;
  1121       std::string line;
  1120 
  1122 
  1121       getline(is, line);
  1123       {
  1122       std::istringstream ls(line);	
  1124         getline(is, line);
  1123       std::string id;
  1125         std::istringstream ls(line);	
  1124       while (ls >> id) {
  1126         std::string id;
  1125 	typename MapReaders::iterator it = readers.find(id);
  1127         while (ls >> id) {
  1126 	if (it != readers.end()) {
  1128           typename MapReaders::iterator it = readers.find(id);
  1127 	  index.push_back(it->second);
  1129           if (it != readers.end()) {
  1128 	  it->second->touch();
  1130             index.push_back(it->second);
  1129 	} else {
  1131             it->second->touch();
  1130 	  index.push_back(&skipper);
  1132           } else {
  1131 	}
  1133             index.push_back(&skipper);
  1132 	if (id == "label") {
  1134           }
  1133 	  inverter.reset(index.back()->getInverter());
  1135           if (id == "label") {
  1134 	  index.back() = inverter.get();
  1136             inverter.reset(index.back()->getInverter());
  1135 	}
  1137             index.back() = inverter.get();
       
  1138           }
       
  1139         }
  1136       }
  1140       }
  1137       for (typename MapReaders::iterator it = readers.begin();
  1141       for (typename MapReaders::iterator it = readers.begin();
  1138 	   it != readers.end(); ++it) {
  1142 	   it != readers.end(); ++it) {
  1139 	if (!it->second->touched()) {
  1143 	if (!it->second->touched()) {
  1140 	  ErrorMessage msg;
  1144 	  ErrorMessage msg;
  1145       while (getline(is, line)) {	
  1149       while (getline(is, line)) {	
  1146 	std::istringstream ls(line);
  1150 	std::istringstream ls(line);
  1147 	Node from = nodeLabelReader->read(ls);
  1151 	Node from = nodeLabelReader->read(ls);
  1148 	Node to = nodeLabelReader->read(ls);
  1152 	Node to = nodeLabelReader->read(ls);
  1149 	Edge edge = graph.addEdge(from, to);
  1153 	Edge edge = graph.addEdge(from, to);
  1150 	for (int i = 0; i < (int)index.size(); ++i) {
  1154 	for (int i = 0; i < int(index.size()); ++i) {
  1151 	  index[i]->read(ls, edge);
  1155 	  index[i]->read(ls, edge);
  1152 	}
  1156 	}
  1153       }
  1157       }
  1154     }
  1158     }
  1155 
  1159 
  1269 
  1273 
  1270     /// \brief Add a new undirected edge map reader command for the reader.
  1274     /// \brief Add a new undirected edge map reader command for the reader.
  1271     ///
  1275     ///
  1272     /// Add a new edge undirected map reader command for the reader.
  1276     /// Add a new edge undirected map reader command for the reader.
  1273     template <typename Map>
  1277     template <typename Map>
  1274     UEdgeSetReader& readUEdgeMap(std::string name, Map& map) {
  1278     UEdgeSetReader& readUEdgeMap(std::string label, Map& map) {
  1275       return _readMap<
  1279       return _readMap<
  1276 	typename Traits::template Reader<typename Map::Value>, Map, 
  1280 	typename Traits::template Reader<typename Map::Value>, Map, 
  1277 	typename _reader_bits::Arg<Map>::Type>(name, map);
  1281 	typename _reader_bits::Arg<Map>::Type>(label, map);
  1278     }
  1282     }
  1279 
  1283 
  1280     template <typename Map>
  1284     template <typename Map>
  1281     UEdgeSetReader& readUEdgeMap(std::string name, const Map& map) {
  1285     UEdgeSetReader& readUEdgeMap(std::string label, const Map& map) {
  1282       return _readMap<
  1286       return _readMap<
  1283 	typename Traits::template Reader<typename Map::Value>, Map, 
  1287 	typename Traits::template Reader<typename Map::Value>, Map, 
  1284 	typename _reader_bits::Arg<Map>::Type>(name, map);
  1288 	typename _reader_bits::Arg<Map>::Type>(label, map);
  1285     }
  1289     }
  1286 
  1290 
  1287     /// \brief Add a new undirected edge map reader command for the reader.
  1291     /// \brief Add a new undirected edge map reader command for the reader.
  1288     ///
  1292     ///
  1289     /// Add a new edge undirected map reader command for the reader.
  1293     /// Add a new edge undirected map reader command for the reader.
  1290     template <typename Reader, typename Map>
  1294     template <typename ItemReader, typename Map>
  1291     UEdgeSetReader& readUEdgeMap(std::string name, Map& map, 
  1295     UEdgeSetReader& readUEdgeMap(std::string label, Map& map, 
  1292 					 const Reader& reader = Reader()) {
  1296                                  const ItemReader& ir = ItemReader()) {
  1293       return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
  1297       return _readMap<ItemReader, Map, typename _reader_bits::Arg<Map>::Type>
  1294 	(name, map, reader);
  1298 	(label, map, ir);
  1295     }
  1299     }
  1296 
  1300 
  1297     template <typename Reader, typename Map>
  1301     template <typename ItemReader, typename Map>
  1298     UEdgeSetReader& readUEdgeMap(std::string name, const Map& map, 
  1302     UEdgeSetReader& readUEdgeMap(std::string label, const Map& map, 
  1299 					 const Reader& reader = Reader()) {
  1303                                  const ItemReader& ir = ItemReader()) {
  1300       return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type >
  1304       return _readMap<ItemReader, Map, typename _reader_bits::Arg<Map>::Type >
  1301 	(name, map, reader);
  1305 	(label, map, ir);
  1302     }
  1306     }
  1303 
  1307 
  1304   private:
  1308   private:
  1305 
  1309 
  1306     template <typename Reader, typename Map, typename MapParameter>
  1310     template <typename ItemReader, typename Map, typename MapParameter>
  1307     UEdgeSetReader& _readMap(std::string name, MapParameter map,
  1311     UEdgeSetReader& _readMap(std::string label, MapParameter map,
  1308 				 const Reader& reader = Reader()) {
  1312                              const ItemReader& ir = ItemReader()) {
  1309       checkConcept<concepts::WriteMap<UEdge, typename Map::Value>, Map>();
  1313       checkConcept<concepts::WriteMap<UEdge, typename Map::Value>, Map>();
  1310       checkConcept<_reader_bits::ItemReader<typename Map::Value>, Reader>();
  1314       checkConcept<_reader_bits::ItemReader<typename Map::Value>, ItemReader>();
  1311       if (readers.find(name) != readers.end()) {
  1315       if (readers.find(label) != readers.end()) {
  1312 	ErrorMessage msg;
  1316 	ErrorMessage msg;
  1313 	msg << "Multiple read rule for edge map: " << name;
  1317 	msg << "Multiple read rule for edge map: " << label;
  1314 	throw IoParameterError(msg.message());
  1318 	throw IoParameterError(msg.message());
  1315       }
  1319       }
  1316       readers.insert(
  1320       readers.insert(
  1317 	make_pair(name, new _reader_bits::
  1321 	make_pair(label, new _reader_bits::
  1318 		  MapReader<UEdge, Map, Reader>(map, reader)));
  1322 		  MapReader<UEdge, Map, ItemReader>(map, ir)));
  1319       return *this;
  1323       return *this;
  1320     }
  1324     }
  1321 
  1325 
  1322   public:
  1326   public:
  1323 
  1327 
  1324     /// \brief Add a new undirected edge map skipper command for the reader.
  1328     /// \brief Add a new undirected edge map skipper command for the reader.
  1325     ///
  1329     ///
  1326     /// Add a new undirected edge map skipper command for the reader.
  1330     /// Add a new undirected edge map skipper command for the reader.
  1327     template <typename Reader>
  1331     template <typename ItemReader>
  1328     UEdgeSetReader& skipUEdgeMap(std::string name, 
  1332     UEdgeSetReader& skipUEdgeMap(std::string label, 
  1329 					 const Reader& reader = Reader()) {
  1333                                  const ItemReader& ir = ItemReader()) {
  1330       if (readers.find(name) != readers.end()) {
  1334       if (readers.find(label) != readers.end()) {
  1331 	ErrorMessage msg;
  1335 	ErrorMessage msg;
  1332 	msg << "Multiple read rule for node map: " << name;
  1336 	msg << "Multiple read rule for node map: " << label;
  1333 	throw IoParameterError(msg.message());
  1337 	throw IoParameterError(msg.message());
  1334       }
  1338       }
  1335       readers.insert(make_pair(name, new _reader_bits::
  1339       readers.insert(make_pair(label, new _reader_bits::
  1336 			       SkipReader<UEdge, Reader>(reader)));
  1340 			       SkipReader<UEdge, ItemReader>(ir)));
  1337       return *this;
  1341       return *this;
  1338     }
  1342     }
  1339 
  1343 
  1340     /// \brief Add a new directed edge map reader command for the reader.
  1344     /// \brief Add a new directed edge map reader command for the reader.
  1341     ///
  1345     ///
  1342     /// Add a new directed edge map reader command for the reader.
  1346     /// Add a new directed edge map reader command for the reader.
  1343     template <typename Map>
  1347     template <typename Map>
  1344     UEdgeSetReader& readEdgeMap(std::string name, Map& map) {
  1348     UEdgeSetReader& readEdgeMap(std::string label, Map& map) {
  1345       return _readDirMap<
  1349       return _readDirMap<
  1346 	typename Traits::template Reader<typename Map::Value>, Map,
  1350 	typename Traits::template Reader<typename Map::Value>, Map,
  1347 	typename _reader_bits::Arg<Map>::Type>(name, map);
  1351 	typename _reader_bits::Arg<Map>::Type>(label, map);
  1348     }
  1352     }
  1349 
  1353 
  1350     template <typename Map>
  1354     template <typename Map>
  1351     UEdgeSetReader& readEdgeMap(std::string name, const Map& map) {
  1355     UEdgeSetReader& readEdgeMap(std::string label, const Map& map) {
  1352       return _readDirMap<
  1356       return _readDirMap<
  1353 	typename Traits::template Reader<typename Map::Value>, Map,
  1357 	typename Traits::template Reader<typename Map::Value>, Map,
  1354 	typename _reader_bits::Arg<Map>::Type>(name, map);
  1358 	typename _reader_bits::Arg<Map>::Type>(label, map);
  1355     }
  1359     }
  1356 
  1360 
  1357     /// \brief Add a new directed edge map reader command for the reader.
  1361     /// \brief Add a new directed edge map reader command for the reader.
  1358     ///
  1362     ///
  1359     /// Add a new directed edge map reader command for the reader.
  1363     /// Add a new directed edge map reader command for the reader.
  1360     template <typename Reader, typename Map>
  1364     template <typename ItemReader, typename Map>
  1361     UEdgeSetReader& readEdgeMap(std::string name, Map& map, 
  1365     UEdgeSetReader& readEdgeMap(std::string label, Map& map, 
  1362 				    const Reader& reader = Reader()) {
  1366 				    const ItemReader& ir = ItemReader()) {
  1363       return _readDirMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
  1367       return _readDirMap<ItemReader, Map, 
  1364 	(name, map, reader);
  1368         typename _reader_bits::Arg<Map>::Type>(label, map, ir);
  1365     }
  1369     }
  1366 
  1370 
  1367     template <typename Reader, typename Map>
  1371     template <typename ItemReader, typename Map>
  1368     UEdgeSetReader& readEdgeMap(std::string name, const Map& map, 
  1372     UEdgeSetReader& readEdgeMap(std::string label, const Map& map, 
  1369 				    const Reader& reader = Reader()) {
  1373 				    const ItemReader& ir = ItemReader()) {
  1370       return _readDirMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
  1374       return _readDirMap<ItemReader, Map, 
  1371 	(name, map, reader);
  1375         typename _reader_bits::Arg<Map>::Type>(label, map, ir);
  1372     }
  1376     }
  1373 
  1377 
  1374   private:
  1378   private:
  1375 
  1379 
  1376     template <typename Reader, typename Map, typename MapParameter>
  1380     template <typename ItemReader, typename Map, typename MapParameter>
  1377     UEdgeSetReader& _readDirMap(std::string name, MapParameter map,
  1381     UEdgeSetReader& _readDirMap(std::string label, MapParameter map,
  1378 				    const Reader& reader = Reader()) { 
  1382 				    const ItemReader& ir = ItemReader()) { 
  1379       checkConcept<_reader_bits::ItemReader<typename Map::Value>, Reader>();
  1383       checkConcept<_reader_bits::ItemReader<typename Map::Value>, ItemReader>();
  1380       checkConcept<concepts::WriteMap<Edge, typename Map::Value>, Map>();
  1384       checkConcept<concepts::WriteMap<Edge, typename Map::Value>, Map>();
  1381       readUEdgeMap("+" + name, 
  1385       readUEdgeMap("+" + label, 
  1382                    _reader_bits::forwardComposeMap(graph, map), reader);
  1386                    _reader_bits::forwardComposeMap(graph, map), ir);
  1383       readUEdgeMap("-" + name, 
  1387       readUEdgeMap("-" + label, 
  1384                    _reader_bits::backwardComposeMap(graph, map), reader);
  1388                    _reader_bits::backwardComposeMap(graph, map), ir);
  1385       return *this;      
  1389       return *this;      
  1386     }
  1390     }
  1387 
  1391 
  1388   public:
  1392   public:
  1389 
  1393 
  1390     /// \brief Add a new directed edge map skipper command for the reader.
  1394     /// \brief Add a new directed edge map skipper command for the reader.
  1391     ///
  1395     ///
  1392     /// Add a new directed edge map skipper command for the reader.
  1396     /// Add a new directed edge map skipper command for the reader.
  1393     template <typename Reader>
  1397     template <typename ItemReader>
  1394     UEdgeSetReader& skipEdgeMap(std::string name, 
  1398     UEdgeSetReader& skipEdgeMap(std::string label, 
  1395                                 const Reader& reader = Reader()) {
  1399                                 const ItemReader& ir = ItemReader()) {
  1396       skipUEdgeMap("+" + name, reader);
  1400       skipUEdgeMap("+" + label, ir);
  1397       skipUEdgeMap("-" + name, reader);
  1401       skipUEdgeMap("-" + label, ir);
  1398       return *this;
  1402       return *this;
  1399     }
  1403     }
  1400 
  1404 
  1401   protected:
  1405   protected:
  1402 
  1406 
  1421 	throw DataFormatError("Cannot find nodeset or label map");
  1425 	throw DataFormatError("Cannot find nodeset or label map");
  1422       }
  1426       }
  1423       std::vector<_reader_bits::MapReaderBase<UEdge>* > index;
  1427       std::vector<_reader_bits::MapReaderBase<UEdge>* > index;
  1424       std::string line;
  1428       std::string line;
  1425 
  1429 
  1426       getline(is, line);
  1430       {
  1427       std::istringstream ls(line);	
  1431         getline(is, line);
  1428       std::string id;
  1432         std::istringstream ls(line);	
  1429       while (ls >> id) {
  1433         std::string id;
  1430 	typename MapReaders::iterator it = readers.find(id);
  1434         while (ls >> id) {
  1431 	if (it != readers.end()) {
  1435           typename MapReaders::iterator it = readers.find(id);
  1432 	  index.push_back(it->second);
  1436           if (it != readers.end()) {
  1433 	  it->second->touch();
  1437             index.push_back(it->second);
  1434 	} else {
  1438             it->second->touch();
  1435 	  index.push_back(&skipper);
  1439           } else {
  1436 	}
  1440             index.push_back(&skipper);
  1437 	if (id == "label") {
  1441           }
  1438 	  inverter.reset(index.back()->getInverter());
  1442           if (id == "label") {
  1439 	  index.back() = inverter.get();
  1443             inverter.reset(index.back()->getInverter());
  1440 	}
  1444             index.back() = inverter.get();
  1441       }
  1445           }
  1442       for (typename MapReaders::iterator it = readers.begin();
  1446         }
  1443 	   it != readers.end(); ++it) {
  1447         for (typename MapReaders::iterator it = readers.begin();
  1444 	if (!it->second->touched()) {
  1448              it != readers.end(); ++it) {
  1445 	  ErrorMessage msg;
  1449           if (!it->second->touched()) {
  1446 	  msg << "Map not found in file: " << it->first;
  1450             ErrorMessage msg;
  1447 	  throw IoParameterError(msg.message());
  1451             msg << "Map not found in file: " << it->first;
  1448 	}
  1452             throw IoParameterError(msg.message());
       
  1453           }
       
  1454         }
  1449       }
  1455       }
  1450       while (getline(is, line)) {	
  1456       while (getline(is, line)) {	
  1451 	std::istringstream ls(line);
  1457 	std::istringstream ls(line);
  1452 	Node from = nodeLabelReader->read(ls);
  1458 	Node from = nodeLabelReader->read(ls);
  1453 	Node to = nodeLabelReader->read(ls);
  1459 	Node to = nodeLabelReader->read(ls);
  1454 	UEdge edge = graph.addEdge(from, to);
  1460 	UEdge edge = graph.addEdge(from, to);
  1455 	for (int i = 0; i < (int)index.size(); ++i) {
  1461 	for (int i = 0; i < int(index.size()); ++i) {
  1456 	  index[i]->read(ls, edge);
  1462 	  index[i]->read(ls, edge);
  1457 	}
  1463 	}
  1458       }
  1464       }
  1459     }
  1465     }
  1460 
  1466 
  1561   public:
  1567   public:
  1562 
  1568 
  1563     /// \brief Add a node reader command for the NodeReader.
  1569     /// \brief Add a node reader command for the NodeReader.
  1564     ///
  1570     ///
  1565     /// Add a node reader command for the NodeReader.
  1571     /// Add a node reader command for the NodeReader.
  1566     void readNode(const std::string& name, Node& item) {
  1572     void readNode(std::string label, Node& item) {
  1567       if (readers.find(name) != readers.end()) {
  1573       if (readers.find(label) != readers.end()) {
  1568 	ErrorMessage msg;
  1574 	ErrorMessage msg;
  1569 	msg << "Multiple read rule for node: " << name;
  1575 	msg << "Multiple read rule for node: " << label;
  1570 	throw IoParameterError(msg.message());
  1576 	throw IoParameterError(msg.message());
  1571       }
  1577       }
  1572       readers.insert(make_pair(name, _reader_bits::ItemStore<Node>(item)));
  1578       readers.insert(make_pair(label, _reader_bits::ItemStore<Node>(item)));
  1573     }
  1579     }
  1574 
  1580 
  1575   protected:
  1581   protected:
  1576 
  1582 
  1577     /// \brief Gives back true when the SectionReader can process 
  1583     /// \brief Gives back true when the SectionReader can process 
  1674   public:
  1680   public:
  1675 
  1681 
  1676     /// \brief Add an edge reader command for the EdgeReader.
  1682     /// \brief Add an edge reader command for the EdgeReader.
  1677     ///
  1683     ///
  1678     /// Add an edge reader command for the EdgeReader.
  1684     /// Add an edge reader command for the EdgeReader.
  1679     void readEdge(const std::string& name, Edge& item) {
  1685     void readEdge(std::string label, Edge& item) {
  1680       if (readers.find(name) != readers.end()) {
  1686       if (readers.find(label) != readers.end()) {
  1681 	ErrorMessage msg;
  1687 	ErrorMessage msg;
  1682 	msg << "Multiple read rule for edge: " << name;
  1688 	msg << "Multiple read rule for edge: " << label;
  1683 	throw IoParameterError(msg.message());
  1689 	throw IoParameterError(msg.message());
  1684       }
  1690       }
  1685       readers.insert(make_pair(name, _reader_bits::ItemStore<Edge>(item)));
  1691       readers.insert(make_pair(label, _reader_bits::ItemStore<Edge>(item)));
  1686     }
  1692     }
  1687 
  1693 
  1688   protected:
  1694   protected:
  1689 
  1695 
  1690     /// \brief Gives back true when the SectionReader can process 
  1696     /// \brief Gives back true when the SectionReader can process 
  1792   public:
  1798   public:
  1793 
  1799 
  1794     /// \brief Add an undirected edge reader command for the UEdgeReader.
  1800     /// \brief Add an undirected edge reader command for the UEdgeReader.
  1795     ///
  1801     ///
  1796     /// Add an undirected edge reader command for the UEdgeReader.
  1802     /// Add an undirected edge reader command for the UEdgeReader.
  1797     void readUEdge(const std::string& name, UEdge& item) {
  1803     void readUEdge(std::string label, UEdge& item) {
  1798       if (uEdgeReaders.find(name) != uEdgeReaders.end()) {
  1804       if (uEdgeReaders.find(label) != uEdgeReaders.end()) {
  1799 	ErrorMessage msg;
  1805 	ErrorMessage msg;
  1800 	msg << "Multiple read rule for undirected edge: " << name;
  1806 	msg << "Multiple read rule for undirected edge: " << label;
  1801 	throw IoParameterError(msg.message());
  1807 	throw IoParameterError(msg.message());
  1802       }
  1808       }
  1803       uEdgeReaders.insert(make_pair(name, _reader_bits::
  1809       uEdgeReaders.insert(make_pair(label, _reader_bits::
  1804 					ItemStore<UEdge>(item)));
  1810 					ItemStore<UEdge>(item)));
  1805     }
  1811     }
  1806 
  1812 
  1807     /// \brief Add an edge reader command for the UEdgeReader.
  1813     /// \brief Add an edge reader command for the UEdgeReader.
  1808     ///
  1814     ///
  1809     /// Add an edge reader command for the UEdgeReader.
  1815     /// Add an edge reader command for the UEdgeReader.
  1810     void readEdge(const std::string& name, Edge& item) {
  1816     void readEdge(std::string label, Edge& item) {
  1811       if (edgeReaders.find(name) != edgeReaders.end()) {
  1817       if (edgeReaders.find(label) != edgeReaders.end()) {
  1812 	ErrorMessage msg;
  1818 	ErrorMessage msg;
  1813 	msg << "Multiple read rule for edge: " << name;
  1819 	msg << "Multiple read rule for edge: " << label;
  1814 	throw IoParameterError(msg.message());
  1820 	throw IoParameterError(msg.message());
  1815       }
  1821       }
  1816       edgeReaders.insert(make_pair(name, _reader_bits::ItemStore<Edge>(item)));
  1822       edgeReaders.insert(make_pair(label, _reader_bits::ItemStore<Edge>(item)));
  1817     }
  1823     }
  1818 
  1824 
  1819   protected:
  1825   protected:
  1820 
  1826 
  1821     /// \brief Gives back true when the SectionReader can process 
  1827     /// \brief Gives back true when the SectionReader can process 
  1951     }
  1957     }
  1952 
  1958 
  1953     /// \brief Add an attribute reader command for the reader.
  1959     /// \brief Add an attribute reader command for the reader.
  1954     ///
  1960     ///
  1955     /// Add an attribute reader command for the reader.
  1961     /// Add an attribute reader command for the reader.
  1956     template <typename Reader, typename Value>
  1962     template <typename ItemReader, typename Value>
  1957     AttributeReader& readAttribute(const std::string& name, Value& value,
  1963     AttributeReader& readAttribute(std::string label, Value& value,
  1958 				   const Reader& reader = Reader()) {
  1964 				   const ItemReader& ir = ItemReader()) {
  1959       checkConcept<_reader_bits::ItemReader<Value>, Reader>();
  1965       checkConcept<_reader_bits::ItemReader<Value>, ItemReader>();
  1960       if (readers.find(name) != readers.end()) {
  1966       if (readers.find(label) != readers.end()) {
  1961 	ErrorMessage msg;
  1967 	ErrorMessage msg;
  1962 	msg << "Multiple read rule for attribute: " << name;
  1968 	msg << "Multiple read rule for attribute: " << label;
  1963 	throw IoParameterError(msg.message());
  1969 	throw IoParameterError(msg.message());
  1964       }
  1970       }
  1965       readers.insert(make_pair(name, new _reader_bits::
  1971       readers.insert(make_pair(label, new _reader_bits::
  1966 			       ValueReader<Value, Reader>(value, reader)));
  1972 			       ValueReader<Value, ItemReader>(value, ir)));
  1967       return *this;
  1973       return *this;
  1968     }
  1974     }
  1969 
  1975 
  1970   protected:
  1976   protected:
  1971 
  1977