Some changes in the IO and map utilities.
authordeba
Tue, 01 Feb 2005 15:56:37 +0000
changeset 1115444f69240539
parent 1114 eb57527fd183
child 1116 f97e1cbbd453
Some changes in the IO and map utilities.
src/work/deba/graph_io_test.cc
src/work/deba/graph_reader.h
src/work/deba/graph_writer.h
src/work/deba/map_utils.h
     1.1 --- a/src/work/deba/graph_io_test.cc	Tue Feb 01 15:51:22 2005 +0000
     1.2 +++ b/src/work/deba/graph_io_test.cc	Tue Feb 01 15:56:37 2005 +0000
     1.3 @@ -18,27 +18,27 @@
     1.4    GraphReader<SmartGraph> reader(input, graph);
     1.5  
     1.6    SmartGraph::NodeMap<int> id(graph);
     1.7 -  reader.readNodeMap("id", id);
     1.8 +  reader.addNodeMap("id", id);
     1.9  
    1.10    SmartGraph::NodeMap<int> cost(graph);
    1.11 -  reader.readNodeMap("cost", cost);
    1.12 +  reader.addNodeMap("cost", cost);
    1.13   
    1.14    SmartGraph::NodeMap<string> color(graph);
    1.15 -  reader.readNodeMap("color", color);
    1.16 +  reader.addNodeMap("color", color);
    1.17  
    1.18    SmartGraph::NodeMap<string> description(graph);
    1.19 -  reader.readNodeMap<QuotedStringReader>("description", description);
    1.20 +  reader.addNodeMap<QuotedStringReader>("description", description);
    1.21  
    1.22    SmartGraph::EdgeMap<char> mmap(graph);
    1.23 -  reader.readEdgeMap("mmap", mmap);
    1.24 +  reader.addEdgeMap("mmap", mmap);
    1.25  
    1.26    reader.skipEdgeMap<QuotedStringReader>("description");
    1.27  
    1.28    SmartGraph::Node source;
    1.29 -  reader.readNode("source", source);
    1.30 +  reader.addNode("source", source);
    1.31    
    1.32    SmartGraph::Edge newedge;
    1.33 -  reader.readEdge("newedge", newedge);
    1.34 +  reader.addEdge("newedge", newedge);
    1.35  
    1.36    try {
    1.37      reader.read();
    1.38 @@ -47,32 +47,37 @@
    1.39    } catch (Exception e) {
    1.40      cerr << e.what() << endl;
    1.41    }
    1.42 +
    1.43    for (SmartGraph::NodeIt it(graph); it != INVALID; ++it) {
    1.44      cout << cost[it] << ' ' << color[it] << ' ' << description[it] << endl;
    1.45    }
    1.46  
    1.47    for (SmartGraph::EdgeIt it(graph); it != INVALID; ++it) {
    1.48 -    cout << mmap[it] << ' ' << id[graph.source(it)] << ' ' << id[graph.target(it)]  << endl;
    1.49 +    cout << mmap[it] << ' ' << id[graph.source(it)] << ' ' << 
    1.50 +      id[graph.target(it)]  << endl;
    1.51    }
    1.52  
    1.53 -  cout << id[source] << ' ' << cost[source] << ' ' << color[source] << ' ' << description[source] << endl;
    1.54 -  cout << mmap[newedge] << ' ' << id[graph.source(newedge)] << ' ' << id[graph.target(newedge)]  << endl;
    1.55 +  cout << id[source] << ' ' << cost[source] << ' ' <<
    1.56 +    color[source] << ' ' << description[source] << endl;
    1.57 +  cout << mmap[newedge] << ' ' << id[graph.source(newedge)] << 
    1.58 +    ' ' << id[graph.target(newedge)]  << endl;
    1.59  
    1.60    ofstream output("copy.lgf");
    1.61    GraphWriter<SmartGraph> writer(output, graph);
    1.62    
    1.63 -  DescriptorMap<SmartGraph, SmartGraph::Node, SmartGraph::NodeIt, SmartGraph::NodeMap<int> > node_ids(graph);
    1.64 +  DescriptorMap<SmartGraph, SmartGraph::Node, SmartGraph::NodeMap<int> > 
    1.65 +    node_ids(graph);
    1.66    
    1.67 -  writer.writeNodeMap("id", node_ids);
    1.68 -  writer.writeNodeMap<QuotedStringWriter>("format", description);
    1.69 +  writer.addNodeMap("id", node_ids);
    1.70 +  writer.addNodeMap<QuotedStringWriter>("format", description);
    1.71  
    1.72 -  DescriptorMap<SmartGraph, SmartGraph::Edge, SmartGraph::EdgeIt, SmartGraph::EdgeMap<int> > edge_ids(graph);
    1.73 +  IdMap<SmartGraph, SmartGraph::Edge > edge_ids(graph);
    1.74  
    1.75 -  writer.writeEdgeMap("id", edge_ids);
    1.76 -  writer.writeEdgeMap("chars", mmap);
    1.77 +  writer.addEdgeMap("id", edge_ids);
    1.78 +  writer.addEdgeMap("chars", mmap);
    1.79    
    1.80 -  writer.writeNode("source", node_ids.inverse()[3]);
    1.81 -  writer.writeEdge("elek", edge_ids.inverse()[6]);
    1.82 +  writer.addNode("source", node_ids.inverse()[3]);
    1.83 +  //  writer.addEdge("elek", edge_ids.inverse()[6]);
    1.84    writer.write();
    1.85    
    1.86    return 0;
     2.1 --- a/src/work/deba/graph_reader.h	Tue Feb 01 15:51:22 2005 +0000
     2.2 +++ b/src/work/deba/graph_reader.h	Tue Feb 01 15:56:37 2005 +0000
     2.3 @@ -37,6 +37,7 @@
     2.4  
     2.5    class IOException {
     2.6    public:
     2.7 +    virtual ~IOException() {}
     2.8      virtual string what() const = 0;
     2.9    };
    2.10  
    2.11 @@ -55,10 +56,13 @@
    2.12    public:
    2.13      typedef _Exception Exception;
    2.14      StreamException(int _line, Exception _exception) 
    2.15 -      : line_num(_line), Exception(_exception) {}
    2.16 +      : Exception(_exception), line_num(_line) {}
    2.17      virtual int line() const {
    2.18        return line_num;
    2.19      }
    2.20 +
    2.21 +    virtual ~StreamException() {}
    2.22 +
    2.23      virtual std::string what() const {
    2.24        ostringstream os;
    2.25        os << Exception::what() << " in line " << line();
    2.26 @@ -70,7 +74,10 @@
    2.27  
    2.28  
    2.29    // Readers and ReaderTraits
    2.30 -  
    2.31 +  /// \brief Standard ReaderTraits for the GraphReader class.
    2.32 +  ///
    2.33 +  /// 
    2.34 + 
    2.35    struct DefaultReaderTraits {
    2.36  
    2.37      template <typename _Value>
    2.38 @@ -96,7 +103,8 @@
    2.39        char c;
    2.40        value.clear();
    2.41        is >> ws;
    2.42 -      if (!is.get(c) || c != '\"') throw DataFormatException("Quoted string format");
    2.43 +      if (!is.get(c) || c != '\"') 
    2.44 +	throw DataFormatException("Quoted string format");
    2.45        while (is.get(c) && c != '\"') {
    2.46  	if (escaped && c == '\\') {
    2.47  	  value += readEscape(is);
    2.48 @@ -192,17 +200,20 @@
    2.49      typedef _ReaderTraits ReaderTraits;
    2.50      typedef typename ReaderTraits::DefaultReader DefaultReader;
    2.51  
    2.52 -    GraphReader(std::istream& _is, Graph& _graph, const DefaultReader& _reader = DefaultReader()) 
    2.53 +    GraphReader(std::istream& _is, Graph& _graph, 
    2.54 +		const DefaultReader& _reader = DefaultReader()) 
    2.55        : is(_is), graph(_graph), nodeSkipper(_reader), edgeSkipper(_reader) {}
    2.56  
    2.57  
    2.58      ~GraphReader() {
    2.59  
    2.60 -      for (typename NodeMapReaders::iterator it = node_map_readers.begin(); it != node_map_readers.end(); ++it) {
    2.61 +      for (typename NodeMapReaders::iterator it = node_map_readers.begin(); 
    2.62 +	   it != node_map_readers.end(); ++it) {
    2.63  	delete it->second;
    2.64        }
    2.65  
    2.66 -      for (typename EdgeMapReaders::iterator it = edge_map_readers.begin(); it != edge_map_readers.end(); ++it) {
    2.67 +      for (typename EdgeMapReaders::iterator it = edge_map_readers.begin(); 
    2.68 +	   it != edge_map_readers.end(); ++it) {
    2.69  	delete it->second;
    2.70        }
    2.71  
    2.72 @@ -211,69 +222,81 @@
    2.73      // Node map rules
    2.74  
    2.75      template <typename Map>
    2.76 -    GraphReader& readNodeMap(std::string name, Map& map) {
    2.77 -      return readNodeMap<typename ReaderTraits::template Reader<typename Map::Value>, Map>(name, map);
    2.78 +    GraphReader& addNodeMap(std::string name, Map& map) {
    2.79 +      return addNodeMap<typename ReaderTraits::template 
    2.80 +	Reader<typename Map::Value>, Map>(name, map);
    2.81      }
    2.82  
    2.83      template <typename Reader, typename Map>
    2.84 -    GraphReader& readNodeMap(std::string name, Map& map, const Reader& reader = Reader()) {
    2.85 +    GraphReader& addNodeMap(std::string name, Map& map, 
    2.86 +			     const Reader& reader = Reader()) {
    2.87        if (node_map_readers.find(name) != node_map_readers.end()) {
    2.88  	throw Exception() << "Multiple read rule for node map: " << name;
    2.89        }
    2.90 -      node_map_readers.insert(make_pair(name, new MapReader<Node, Map, Reader>(map, reader)));
    2.91 +      node_map_readers.insert(
    2.92 +        make_pair(name, new MapReader<Node, Map, Reader>(map, reader)));
    2.93        return *this;
    2.94      }
    2.95  
    2.96      template <typename Reader>
    2.97 -    GraphReader& skipNodeMap(std::string name, const Reader& reader = Reader()) {
    2.98 +    GraphReader& skipNodeMap(std::string name, 
    2.99 +			     const Reader& reader = Reader()) {
   2.100        if (node_map_readers.find(name) != node_map_readers.end()) {
   2.101  	throw Exception() << "Multiple read rule for node map: " << name;
   2.102        }
   2.103 -      node_map_readers.insert(make_pair(name, new SkipReader<Node, Reader>(reader)));
   2.104 +      node_map_readers.insert(
   2.105 +        make_pair(name, new SkipReader<Node, Reader>(reader)));
   2.106        return *this;
   2.107      }
   2.108  
   2.109      // Edge map rules
   2.110  
   2.111      template <typename Map>
   2.112 -    GraphReader& readEdgeMap(std::string name, Map& map) { 
   2.113 -      return readEdgeMap<typename ReaderTraits::template Reader<typename Map::Value>, Map>(name, map);
   2.114 +    GraphReader& addEdgeMap(std::string name, Map& map) { 
   2.115 +      return addEdgeMap<typename ReaderTraits::template
   2.116 +	Reader<typename Map::Value>, Map>(name, map);
   2.117      }
   2.118  
   2.119  
   2.120      template <typename Reader, typename Map>
   2.121 -    GraphReader& readEdgeMap(std::string name, Map& map, const Reader& reader = Reader()) {
   2.122 +    GraphReader& addEdgeMap(std::string name, Map& map,
   2.123 +			     const Reader& reader = Reader()) {
   2.124        if (edge_map_readers.find(name) != edge_map_readers.end()) {
   2.125  	throw Exception() << "Multiple read rule for edge map: " << name;
   2.126        }
   2.127 -      edge_map_readers.insert(make_pair(name, new MapReader<Edge, Map, Reader>(map, reader)));
   2.128 +      edge_map_readers.insert(
   2.129 +        make_pair(name, new MapReader<Edge, Map, Reader>(map, reader)));
   2.130        return *this;
   2.131      }
   2.132  
   2.133      template <typename Reader>
   2.134 -    GraphReader& skipEdgeMap(std::string name, const Reader& reader = Reader()) {
   2.135 +    GraphReader& skipEdgeMap(std::string name,
   2.136 +			     const Reader& reader = Reader()) {
   2.137        if (edge_map_readers.find(name) != edge_map_readers.end()) {
   2.138  	throw Exception() << "Multiple read rule for edge map: " << name;
   2.139        }
   2.140 -      edge_map_readers.insert(make_pair(name, new SkipReader<Edge, Reader>(reader)));
   2.141 +      edge_map_readers.insert(
   2.142 +        make_pair(name, new SkipReader<Edge, Reader>(reader)));
   2.143        return *this;
   2.144      }
   2.145  
   2.146      // Node rules
   2.147 -    GraphReader& readNode(std::string name, Node& node) {
   2.148 +    GraphReader& addNode(std::string name, Node& node) {
   2.149        if (node_readers.find(name) != node_readers.end()) {
   2.150  	throw Exception() << "Multiple read rule for node";
   2.151        }
   2.152        node_readers.insert(make_pair(name, &node));
   2.153 +      return *this;
   2.154      }
   2.155  
   2.156      // Edge rules
   2.157  
   2.158 -    GraphReader& readEdge(std::string name, Edge& edge) {
   2.159 +    GraphReader& addEdge(std::string name, Edge& edge) {
   2.160        if (edge_readers.find(name) != edge_readers.end()) {
   2.161  	throw Exception() << "Multiple read rule for edge";
   2.162        }
   2.163        edge_readers.insert(make_pair(name, &edge));
   2.164 +      return *this;
   2.165      }
   2.166  
   2.167      void read() {
   2.168 @@ -306,7 +329,8 @@
   2.169  
   2.170      template <typename Item> class InverterBase;
   2.171  
   2.172 -    std::string readNodeSet(int& line_num, auto_ptr<InverterBase<Node> > & nodeInverter) {
   2.173 +    std::string readNodeSet(int& line_num, 
   2.174 +			    auto_ptr<InverterBase<Node> > & nodeInverter) {
   2.175        std::vector<ReaderBase<Node>* > index;
   2.176        {
   2.177  	std::string line = readNotEmptyLine(is, line_num);    
   2.178 @@ -334,7 +358,7 @@
   2.179  	Node node = graph.addNode();
   2.180  	std::istringstream ls(line);
   2.181  	nodeInverter->read(ls, node);
   2.182 -	for (int i = 1; i < index.size(); ++i) {
   2.183 +	for (int i = 1; i < (int)index.size(); ++i) {
   2.184  	  index[i]->read(ls, node);
   2.185  	}
   2.186        }
   2.187 @@ -342,7 +366,8 @@
   2.188      }
   2.189  
   2.190      std::string readEdgeSet(int& line_num, 
   2.191 -		     auto_ptr<InverterBase<Edge> > & edgeInverter, auto_ptr<InverterBase<Node> > & nodeInverter) {
   2.192 +			    auto_ptr<InverterBase<Edge> > & edgeInverter, 
   2.193 +			    auto_ptr<InverterBase<Node> > & nodeInverter) {
   2.194        std::vector<ReaderBase<Edge>*> index;
   2.195        {
   2.196  	std::string line = readNotEmptyLine(is, line_num);    
   2.197 @@ -372,14 +397,15 @@
   2.198  	Node target = nodeInverter->read(ls);
   2.199  	Edge edge = graph.addEdge(source, target);
   2.200  	edgeInverter->read(ls, edge);
   2.201 -	for (int i = 1; i < index.size(); ++i) {
   2.202 +	for (int i = 1; i < (int)index.size(); ++i) {
   2.203  	  index[i]->read(ls, edge);
   2.204  	}
   2.205        }      
   2.206        return line;
   2.207      }
   2.208  
   2.209 -    std::string readNodes(int& line_num, auto_ptr<InverterBase<Node> >& nodeInverter) {
   2.210 +    std::string readNodes(int& line_num, 
   2.211 +			  auto_ptr<InverterBase<Node> >& nodeInverter) {
   2.212        std::string line;
   2.213        while (line = readNotEmptyLine(is, line_num), line[0] != '@') {
   2.214  	std::istringstream ls(line);
   2.215 @@ -393,7 +419,8 @@
   2.216        return line;
   2.217      }
   2.218  
   2.219 -    std::string readEdges(int& line_num, auto_ptr<InverterBase<Edge> >& edgeInverter) {
   2.220 +    std::string readEdges(int& line_num, 
   2.221 +			  auto_ptr<InverterBase<Edge> >& edgeInverter) {
   2.222        std::string line;
   2.223        while (line = readNotEmptyLine(is, line_num), line[0] != '@') {
   2.224  	std::istringstream ls(line);
   2.225 @@ -411,7 +438,7 @@
   2.226        std::string line;
   2.227        while (++line_num, getline(is, line)) {	
   2.228  	int vi = line.find_first_not_of(" \t");
   2.229 -	if (vi != string::npos && line[vi] != '#') {
   2.230 +	if (vi != (int)string::npos && line[vi] != '#') {
   2.231  	  return line.substr(vi);
   2.232  	}
   2.233        }
   2.234 @@ -445,6 +472,8 @@
   2.235        MapReaderInverter(Map& _map, const Reader& _reader) 
   2.236  	: map(_map), reader(_reader) {}
   2.237  
   2.238 +      virtual ~MapReaderInverter() {}
   2.239 +
   2.240        virtual void read(std::istream& is, const Item& item) {
   2.241  	Value value;
   2.242  	reader.read(is, value);
   2.243 @@ -482,6 +511,8 @@
   2.244        SkipReaderInverter(const Reader& _reader) 
   2.245  	: reader(_reader) {}
   2.246  
   2.247 +      virtual ~SkipReaderInverter() {}
   2.248 +
   2.249        virtual void read(std::istream& is, const Item& item) {
   2.250  	Value value;
   2.251  	reader.read(is, value);
   2.252 @@ -514,6 +545,8 @@
   2.253      public:
   2.254        typedef _Item Item;
   2.255  
   2.256 +      //      virtual ~ReaderBase() {}
   2.257 +
   2.258        virtual void read(std::istream& is, const Item& item) = 0;
   2.259        virtual InverterBase<_Item>* getInverter() = 0;
   2.260      };
   2.261 @@ -532,6 +565,7 @@
   2.262        MapReader(Map& _map, const Reader& _reader) 
   2.263  	: map(_map), reader(_reader) {}
   2.264  
   2.265 +      virtual ~MapReader() {}
   2.266  
   2.267        virtual void read(std::istream& is, const Item& item) {
   2.268  	Value value;
   2.269 @@ -555,6 +589,8 @@
   2.270        Reader reader;
   2.271        SkipReader(const Reader& _reader) : reader(_reader) {}
   2.272  
   2.273 +      virtual ~SkipReader() {}
   2.274 +
   2.275        virtual void read(std::istream& is, const Item& item) {
   2.276  	Value value;
   2.277  	reader.read(is, value);
     3.1 --- a/src/work/deba/graph_writer.h	Tue Feb 01 15:51:22 2005 +0000
     3.2 +++ b/src/work/deba/graph_writer.h	Tue Feb 01 15:56:37 2005 +0000
     3.3 @@ -54,11 +54,10 @@
     3.4      QuotedStringWriter(bool _escaped = true) : escaped(_escaped) {}
     3.5  
     3.6      void write(std::ostream& os, const std::string& value) {
     3.7 -      char c;
     3.8        os << "\"";
     3.9        if (escaped) {
    3.10  	ostringstream ls;
    3.11 -	for (int i = 0; i < value.size(); ++i) {
    3.12 +	for (int i = 0; i < (int)value.size(); ++i) {
    3.13  	  writeEscape(ls, value[i]);
    3.14  	}
    3.15  	os << ls.str();
    3.16 @@ -136,12 +135,13 @@
    3.17  
    3.18  
    3.19      ~GraphWriter() {
    3.20 -
    3.21 -      for (typename NodeMapWriters::iterator it = node_map_writers.begin(); it != node_map_writers.end(); ++it) {
    3.22 +      for (typename NodeMapWriters::iterator it = node_map_writers.begin(); 
    3.23 +	   it != node_map_writers.end(); ++it) {
    3.24  	delete it->second;
    3.25        }
    3.26  
    3.27 -      for (typename EdgeMapWriters::iterator it = edge_map_writers.begin(); it != edge_map_writers.end(); ++it) {
    3.28 +      for (typename EdgeMapWriters::iterator it = edge_map_writers.begin();
    3.29 +	   it != edge_map_writers.end(); ++it) {
    3.30  	delete it->second;
    3.31        }
    3.32  
    3.33 @@ -150,29 +150,33 @@
    3.34      // Node map rules
    3.35  
    3.36      template <typename Map>
    3.37 -    GraphWriter& writeNodeMap(std::string name, const Map& map) {
    3.38 -      return writeNodeMap<typename WriterTraits::template Writer<typename Map::Value>, Map>(name, map);
    3.39 +    GraphWriter& addNodeMap(std::string name, const Map& map) {
    3.40 +      return addNodeMap<typename WriterTraits::template Writer<
    3.41 +	typename Map::Value>, Map>(name, map);
    3.42      }
    3.43  
    3.44      template <typename Writer, typename Map>
    3.45 -    GraphWriter& writeNodeMap(std::string name, const Map& map, const Writer& writer = Writer()) {
    3.46 +    GraphWriter& addNodeMap(std::string name, const Map& map, 
    3.47 +			      const Writer& writer = Writer()) {
    3.48        //      if (node_map_writers.find(name) != node_map_writers.end()) {
    3.49 -      //	throw Exception() << "Multiple write rule for node map: " << name;
    3.50 +      //	throw Exception() << "Multiple write rule for node map: " 
    3.51 +      //        << name;
    3.52        //      }
    3.53 -      node_map_writers.push_back(make_pair(name, new MapWriter<Node, Map, Writer>(map, writer)));
    3.54 +      node_map_writers.push_back(
    3.55 +        make_pair(name, new MapWriter<Node, Map, Writer>(map, writer)));
    3.56        return *this;
    3.57      }
    3.58  
    3.59      // Edge map rules
    3.60  
    3.61      template <typename Map>
    3.62 -    GraphWriter& writeEdgeMap(std::string name, const Map& map) { 
    3.63 -      return writeEdgeMap<typename WriterTraits::template Writer<typename Map::Value>, Map>(name, map);
    3.64 +    GraphWriter& addEdgeMap(std::string name, const Map& map) { 
    3.65 +      return addEdgeMap<typename WriterTraits::template Writer<typename Map::Value>, Map>(name, map);
    3.66      }
    3.67  
    3.68  
    3.69      template <typename Writer, typename Map>
    3.70 -    GraphWriter& writeEdgeMap(std::string name, const Map& map, const Writer& writer = Writer()) {
    3.71 +    GraphWriter& addEdgeMap(std::string name, const Map& map, const Writer& writer = Writer()) {
    3.72        //      if (edge_map_writers.find(name) != edge_map_writers.end()) {
    3.73        //	throw Exception() << "Multiple write rule for edge map: " << name;
    3.74        //      }
    3.75 @@ -181,20 +185,22 @@
    3.76      }
    3.77  
    3.78      // Node rules
    3.79 -    GraphWriter& writeNode(std::string name, const Node& node) {
    3.80 +    GraphWriter& addNode(std::string name, const Node& node) {
    3.81        //      if (node_writers.find(name) != node_writers.end()) {
    3.82        //	throw Exception() << "Multiple write rule for node";
    3.83        //      }
    3.84        node_writers.push_back(make_pair(name, node));
    3.85 +      return *this;
    3.86      }
    3.87  
    3.88      // Edge rules
    3.89  
    3.90 -    GraphWriter& writeEdge(std::string name, const Edge& edge) {
    3.91 +    GraphWriter& addEdge(std::string name, const Edge& edge) {
    3.92        //      if (edge_writers.find(name) != edge_writers.end()) {
    3.93        //	throw Exception() << "Multiple write rule for edge";
    3.94        //      }
    3.95        edge_writers.push_back(make_pair(name, edge));
    3.96 +      return *this;
    3.97      }
    3.98  
    3.99      void write() {   
   3.100 @@ -210,12 +216,12 @@
   3.101      void writeNodeSet() {
   3.102        if (node_map_writers.size() == 0) return;
   3.103        os << "@nodeset" << std::endl;
   3.104 -      for (int i = 0; i < node_map_writers.size(); ++i) {
   3.105 +      for (int i = 0; i < (int)node_map_writers.size(); ++i) {
   3.106  	os << node_map_writers[i].first << '\t';
   3.107        } 
   3.108        os << std::endl;
   3.109        for (NodeIt it(graph); it != INVALID; ++it) {
   3.110 -	for (int i = 0; i < node_map_writers.size(); ++i) {
   3.111 +	for (int i = 0; i < (int)node_map_writers.size(); ++i) {
   3.112  	  node_map_writers[i].second->write(os, it);
   3.113  	}
   3.114  	os << std::endl;
   3.115 @@ -230,14 +236,14 @@
   3.116        }
   3.117        os << "@edgeset" << std::endl;
   3.118        os << "\t\t";
   3.119 -      for (int i = 0; i < edge_map_writers.size(); ++i) {
   3.120 +      for (int i = 0; i < (int)edge_map_writers.size(); ++i) {
   3.121  	os << edge_map_writers[i].first << '\t';
   3.122        } 
   3.123        os << std::endl;
   3.124        for (EdgeIt it(graph); it != INVALID; ++it) {
   3.125  	node_map_writers[0].second->write(os, graph.source(it));
   3.126  	node_map_writers[0].second->write(os, graph.target(it));
   3.127 -	for (int i = 0; i < edge_map_writers.size(); ++i) {
   3.128 +	for (int i = 0; i < (int)edge_map_writers.size(); ++i) {
   3.129  	  edge_map_writers[i].second->write(os, it);
   3.130  	}
   3.131  	os << std::endl;
   3.132 @@ -250,7 +256,7 @@
   3.133  	throw Exception() << "Missing node id map";
   3.134        }
   3.135        os << "@nodes" << std::endl;
   3.136 -      for (int i = 0; i < node_writers.size(); ++i) {
   3.137 +      for (int i = 0; i < (int)node_writers.size(); ++i) {
   3.138  	os << node_writers[i].first << '\t';
   3.139  	node_map_writers[0].second->write(os, node_writers[i].second);
   3.140  	os << std::endl;
   3.141 @@ -263,7 +269,7 @@
   3.142  	throw Exception() << "Missing edge id map";
   3.143        }
   3.144        os << "@edges" << std::endl;
   3.145 -      for (int i = 0; i < edge_writers.size(); ++i) {
   3.146 +      for (int i = 0; i < (int)edge_writers.size(); ++i) {
   3.147  	os << edge_writers[i].first << '\t';
   3.148  	edge_map_writers[0].second->write(os, edge_writers[i].second);
   3.149  	os << std::endl;
   3.150 @@ -295,7 +301,6 @@
   3.151  
   3.152  
   3.153        virtual void write(std::ostream& os, const Item& item) {
   3.154 -	Value value;
   3.155  	writer.write(os, map[item]);
   3.156        }
   3.157  
   3.158 @@ -303,10 +308,12 @@
   3.159  
   3.160  
   3.161  
   3.162 -    typedef std::vector< std::pair<std::string, WriterBase<Node>*> > NodeMapWriters;
   3.163 +    typedef std::vector< std::pair<std::string, WriterBase<Node>*> > 
   3.164 +      NodeMapWriters;
   3.165      NodeMapWriters node_map_writers;
   3.166  
   3.167 -    typedef std::vector< std::pair<std::string, WriterBase<Edge>*> > EdgeMapWriters;
   3.168 +    typedef std::vector< std::pair<std::string, WriterBase<Edge>*> > 
   3.169 +      EdgeMapWriters;
   3.170      EdgeMapWriters edge_map_writers;
   3.171  
   3.172      typedef std::vector<std::pair<std::string, Node> > NodeWriters;
     4.1 --- a/src/work/deba/map_utils.h	Tue Feb 01 15:51:22 2005 +0000
     4.2 +++ b/src/work/deba/map_utils.h	Tue Feb 01 15:56:37 2005 +0000
     4.3 @@ -14,7 +14,7 @@
     4.4   *
     4.5   */
     4.6  
     4.7 -///\ingroup gutils
     4.8 +///\ingroup mutils
     4.9  ///\file
    4.10  ///\brief Map utilities.
    4.11  
    4.12 @@ -49,15 +49,15 @@
    4.13      
    4.14      typedef typename _Map::ConstReference ConstReference;
    4.15  
    4.16 -    /// Constructor.
    4.17 -
    4.18 +    /// \brief Constructor.
    4.19 +    ///
    4.20      /// Construct a new InversableMap for the graph.
    4.21      ///
    4.22      InversableMap(const Graph& graph) : Map(graph) {} 
    4.23      
    4.24 -    /// The setter function of the map.
    4.25 -
    4.26 -    /// It sets the map and the inverse map 
    4.27 +    /// \brief The setter function of the map.
    4.28 +    ///
    4.29 +    /// It sets the map and the inverse map to given key-value pair.
    4.30      void set(const Key& key, const Value& val) {
    4.31        Value oldval = Map::operator[](key);
    4.32        typename InverseMap::iterator it = inv_map.find(oldval);
    4.33 @@ -95,27 +95,42 @@
    4.34    };
    4.35  
    4.36  
    4.37 -  // unique, continous, mutable
    4.38 +  
    4.39 +  /// \brief Provides a mutable, continous and unique descriptor for each 
    4.40 +  /// item in the graph.
    4.41 +  ///
    4.42 +  /// The DescriptorMap class provides a mutable, continous and immutable
    4.43 +  /// mapping for each item in the graph.
    4.44 +  ///
    4.45 +  /// \param _Graph The graph class the \c DescriptorMap belongs to.
    4.46 +  /// \param _Item The Item is the Key of the Map. It may be Node, Edge or 
    4.47 +  /// UndirEdge.
    4.48 +  /// \param _Map A ReadWriteMap mapping from the item type to integer.
    4.49  
    4.50    template <
    4.51      typename _Graph,   
    4.52      typename _Item,
    4.53 -    typename _ItemIt,
    4.54      typename _Map
    4.55    >
    4.56    class DescriptorMap : protected _Map {
    4.57 -  public:
    4.58 -    typedef _Graph Graph;
    4.59 +
    4.60      typedef _Item Item;
    4.61 -    typedef _ItemIt ItemIt;
    4.62      typedef _Map Map;
    4.63  
    4.64 +  public:
    4.65 +    /// The graph class of DescriptorMap.
    4.66 +    typedef _Graph Graph;
    4.67  
    4.68 +    /// The key type of DescriptorMap (Node, Edge, UndirEdge).
    4.69      typedef typename _Map::Key Key;
    4.70 +    /// The value type of DescriptorMap.
    4.71      typedef typename _Map::Value Value;
    4.72  
    4.73 -    typedef vector<Item> InverseMap;
    4.74 +    typedef std::vector<Item> InverseMap;
    4.75  
    4.76 +    /// \brief Constructor.
    4.77 +    ///
    4.78 +    /// Constructor for creating descriptor map.
    4.79      DescriptorMap(const Graph& _graph) : Map(_graph) {
    4.80        build();
    4.81      }
    4.82 @@ -134,7 +149,8 @@
    4.83  
    4.84      virtual void build() {
    4.85        Map::build();
    4.86 -      for (ItemIt it(*Map::getGraph()); it != INVALID; ++it) {
    4.87 +      Item it;
    4.88 +      for (getGraph()->first(it); it != INVALID; getGraph()->next(it)) {
    4.89  	Map::set(it, inv_map.size());
    4.90  	inv_map.push_back(it);	
    4.91        }      
    4.92 @@ -145,11 +161,16 @@
    4.93        Map::clear();
    4.94      }
    4.95  
    4.96 +    /// \brief Gives back the \e descriptor of the item.
    4.97 +    ///
    4.98 +    /// Gives back the mutable and unique \e descriptor of the map.
    4.99      int operator[](const Item& item) const {
   4.100        return Map::operator[](item);
   4.101      }
   4.102 -
   4.103      
   4.104 +    /// \brief Gives back the inverse of the map.
   4.105 +    ///
   4.106 +    /// Gives back the inverse of the map.
   4.107      const InverseMap inverse() const {
   4.108        return inv_map;
   4.109      }
   4.110 @@ -157,10 +178,57 @@
   4.111    private:
   4.112      vector<Item> inv_map;
   4.113    };
   4.114 +  
   4.115 +  /// Provides an immutable and unique id for each item in the graph.
   4.116  
   4.117 -  // unique, immutable => IDMap
   4.118 -  
   4.119 -  
   4.120 +  /// The IdMap class provides an unique and immutable mapping for each item
   4.121 +  /// in the graph.
   4.122 +  ///
   4.123 +  template <typename _Graph, typename _Item>
   4.124 +  class IdMap {
   4.125 +  public:
   4.126 +    typedef _Graph Graph;
   4.127 +    typedef int Value;
   4.128 +    typedef _Item Item;
   4.129 +
   4.130 +    /// \brief The class represents the inverse of the map.
   4.131 +    ///
   4.132 +    /// The class represents the inverse of the map.
   4.133 +    /// \see inverse()
   4.134 +    class InverseMap {
   4.135 +    protected:
   4.136 +      InverseMap(const Graph& _graph) : graph(_graph) {}
   4.137 +    public:
   4.138 +      /// \brief Gives back the given item by its id.
   4.139 +      ///
   4.140 +      /// Gives back the given item by its id.
   4.141 +      /// 
   4.142 +      Item operator[](int id) const { return graph->fromId(id, Item());}
   4.143 +    private:
   4.144 +      Graph* graph;
   4.145 +    };
   4.146 +
   4.147 +    /// \brief Constructor.
   4.148 +    ///
   4.149 +    /// Constructor for creating id map.
   4.150 +    IdMap(const Graph& _graph) : graph(&_graph) {}
   4.151 +
   4.152 +    /// \brief Gives back the \e id of the item.
   4.153 +    ///
   4.154 +    /// Gives back the immutable and unique \e id of the map.
   4.155 +    int operator[](const Item& item) const { return graph->id(item);}
   4.156 +
   4.157 +    /// \brief Gives back the inverse of the map.
   4.158 +    ///
   4.159 +    /// Gives back the inverse of the map.
   4.160 +    InverseMap inverse() const { return InverseMap(*graph);} 
   4.161 +
   4.162 +  private:
   4.163 +    const Graph* graph;
   4.164 +
   4.165 +  };
   4.166 +
   4.167 +
   4.168  
   4.169  }
   4.170