src/work/deba/graph_io_test.cc
changeset 1037 3eaff8d04171
parent 1036 2f514b5c7122
child 1115 444f69240539
     1.1 --- a/src/work/deba/graph_io_test.cc	Tue Dec 14 19:26:50 2004 +0000
     1.2 +++ b/src/work/deba/graph_io_test.cc	Wed Dec 15 19:56:55 2004 +0000
     1.3 @@ -1,5 +1,10 @@
     1.4  #include <lemon/smart_graph.h>
     1.5 +
     1.6 +#include "map_utils.h"
     1.7 +
     1.8 +
     1.9  #include "graph_reader.h"
    1.10 +#include "graph_writer.h"
    1.11  
    1.12  #include <iostream>
    1.13  #include <fstream>
    1.14 @@ -11,17 +16,30 @@
    1.15    ifstream input("test.lgf");
    1.16    SmartGraph graph;
    1.17    GraphReader<SmartGraph> reader(input, graph);
    1.18 +
    1.19    SmartGraph::NodeMap<int> id(graph);
    1.20    reader.readNodeMap("id", id);
    1.21 +
    1.22    SmartGraph::NodeMap<int> cost(graph);
    1.23    reader.readNodeMap("cost", cost);
    1.24 + 
    1.25    SmartGraph::NodeMap<string> color(graph);
    1.26    reader.readNodeMap("color", color);
    1.27 +
    1.28    SmartGraph::NodeMap<string> description(graph);
    1.29    reader.readNodeMap<QuotedStringReader>("description", description);
    1.30 +
    1.31    SmartGraph::EdgeMap<char> mmap(graph);
    1.32    reader.readEdgeMap("mmap", mmap);
    1.33 +
    1.34    reader.skipEdgeMap<QuotedStringReader>("description");
    1.35 +
    1.36 +  SmartGraph::Node source;
    1.37 +  reader.readNode("source", source);
    1.38 +  
    1.39 +  SmartGraph::Edge newedge;
    1.40 +  reader.readEdge("newedge", newedge);
    1.41 +
    1.42    try {
    1.43      reader.read();
    1.44    } catch (IOException& e) {
    1.45 @@ -36,5 +54,26 @@
    1.46    for (SmartGraph::EdgeIt it(graph); it != INVALID; ++it) {
    1.47      cout << mmap[it] << ' ' << id[graph.source(it)] << ' ' << id[graph.target(it)]  << endl;
    1.48    }
    1.49 +
    1.50 +  cout << id[source] << ' ' << cost[source] << ' ' << color[source] << ' ' << description[source] << endl;
    1.51 +  cout << mmap[newedge] << ' ' << id[graph.source(newedge)] << ' ' << id[graph.target(newedge)]  << endl;
    1.52 +
    1.53 +  ofstream output("copy.lgf");
    1.54 +  GraphWriter<SmartGraph> writer(output, graph);
    1.55 +  
    1.56 +  DescriptorMap<SmartGraph, SmartGraph::Node, SmartGraph::NodeIt, SmartGraph::NodeMap<int> > node_ids(graph);
    1.57 +  
    1.58 +  writer.writeNodeMap("id", node_ids);
    1.59 +  writer.writeNodeMap<QuotedStringWriter>("format", description);
    1.60 +
    1.61 +  DescriptorMap<SmartGraph, SmartGraph::Edge, SmartGraph::EdgeIt, SmartGraph::EdgeMap<int> > edge_ids(graph);
    1.62 +
    1.63 +  writer.writeEdgeMap("id", edge_ids);
    1.64 +  writer.writeEdgeMap("chars", mmap);
    1.65 +  
    1.66 +  writer.writeNode("source", node_ids.inverse()[3]);
    1.67 +  writer.writeEdge("elek", edge_ids.inverse()[6]);
    1.68 +  writer.write();
    1.69 +  
    1.70    return 0;
    1.71  }