src/work/deba/graph_io_test.cc
changeset 1207 8117169c9049
parent 1037 3eaff8d04171
child 1210 f02396423239
equal deleted inserted replaced
2:445c7bfec199 3:a410d17efa3b
    16   ifstream input("test.lgf");
    16   ifstream input("test.lgf");
    17   SmartGraph graph;
    17   SmartGraph graph;
    18   GraphReader<SmartGraph> reader(input, graph);
    18   GraphReader<SmartGraph> reader(input, graph);
    19 
    19 
    20   SmartGraph::NodeMap<int> id(graph);
    20   SmartGraph::NodeMap<int> id(graph);
    21   reader.readNodeMap("id", id);
    21   reader.addNodeMap("id", id);
    22 
    22 
    23   SmartGraph::NodeMap<int> cost(graph);
    23   SmartGraph::NodeMap<int> cost(graph);
    24   reader.readNodeMap("cost", cost);
    24   reader.addNodeMap("cost", cost);
    25  
    25  
    26   SmartGraph::NodeMap<string> color(graph);
    26   SmartGraph::NodeMap<string> color(graph);
    27   reader.readNodeMap("color", color);
    27   reader.addNodeMap("color", color);
    28 
    28 
    29   SmartGraph::NodeMap<string> description(graph);
    29   SmartGraph::NodeMap<string> description(graph);
    30   reader.readNodeMap<QuotedStringReader>("description", description);
    30   reader.addNodeMap<QuotedStringReader>("description", description);
    31 
    31 
    32   SmartGraph::EdgeMap<char> mmap(graph);
    32   SmartGraph::EdgeMap<char> mmap(graph);
    33   reader.readEdgeMap("mmap", mmap);
    33   reader.addEdgeMap("mmap", mmap);
    34 
    34 
    35   reader.skipEdgeMap<QuotedStringReader>("description");
    35   reader.skipEdgeMap<QuotedStringReader>("description");
    36 
    36 
    37   SmartGraph::Node source;
    37   SmartGraph::Node source;
    38   reader.readNode("source", source);
    38   reader.addNode("source", source);
    39   
    39   
    40   SmartGraph::Edge newedge;
    40   SmartGraph::Edge newedge;
    41   reader.readEdge("newedge", newedge);
    41   reader.addEdge("newedge", newedge);
    42 
    42 
    43   try {
    43   try {
    44     reader.read();
    44     reader.read();
    45   } catch (IOException& e) {
    45   } catch (IOException& e) {
    46     cerr << e.what() << endl;
    46     cerr << e.what() << endl;
    47   } catch (Exception e) {
    47   } catch (Exception e) {
    48     cerr << e.what() << endl;
    48     cerr << e.what() << endl;
    49   }
    49   }
       
    50 
    50   for (SmartGraph::NodeIt it(graph); it != INVALID; ++it) {
    51   for (SmartGraph::NodeIt it(graph); it != INVALID; ++it) {
    51     cout << cost[it] << ' ' << color[it] << ' ' << description[it] << endl;
    52     cout << cost[it] << ' ' << color[it] << ' ' << description[it] << endl;
    52   }
    53   }
    53 
    54 
    54   for (SmartGraph::EdgeIt it(graph); it != INVALID; ++it) {
    55   for (SmartGraph::EdgeIt it(graph); it != INVALID; ++it) {
    55     cout << mmap[it] << ' ' << id[graph.source(it)] << ' ' << id[graph.target(it)]  << endl;
    56     cout << mmap[it] << ' ' << id[graph.source(it)] << ' ' << 
       
    57       id[graph.target(it)]  << endl;
    56   }
    58   }
    57 
    59 
    58   cout << id[source] << ' ' << cost[source] << ' ' << color[source] << ' ' << description[source] << endl;
    60   cout << id[source] << ' ' << cost[source] << ' ' <<
    59   cout << mmap[newedge] << ' ' << id[graph.source(newedge)] << ' ' << id[graph.target(newedge)]  << endl;
    61     color[source] << ' ' << description[source] << endl;
       
    62   cout << mmap[newedge] << ' ' << id[graph.source(newedge)] << 
       
    63     ' ' << id[graph.target(newedge)]  << endl;
    60 
    64 
    61   ofstream output("copy.lgf");
    65   ofstream output("copy.lgf");
    62   GraphWriter<SmartGraph> writer(output, graph);
    66   GraphWriter<SmartGraph> writer(output, graph);
    63   
    67   
    64   DescriptorMap<SmartGraph, SmartGraph::Node, SmartGraph::NodeIt, SmartGraph::NodeMap<int> > node_ids(graph);
    68   DescriptorMap<SmartGraph, SmartGraph::Node, SmartGraph::NodeMap<int> > 
       
    69     node_ids(graph);
    65   
    70   
    66   writer.writeNodeMap("id", node_ids);
    71   writer.addNodeMap("id", node_ids);
    67   writer.writeNodeMap<QuotedStringWriter>("format", description);
    72   writer.addNodeMap<QuotedStringWriter>("format", description);
    68 
    73 
    69   DescriptorMap<SmartGraph, SmartGraph::Edge, SmartGraph::EdgeIt, SmartGraph::EdgeMap<int> > edge_ids(graph);
    74   IdMap<SmartGraph, SmartGraph::Edge > edge_ids(graph);
    70 
    75 
    71   writer.writeEdgeMap("id", edge_ids);
    76   writer.addEdgeMap("id", edge_ids);
    72   writer.writeEdgeMap("chars", mmap);
    77   writer.addEdgeMap("chars", mmap);
    73   
    78   
    74   writer.writeNode("source", node_ids.inverse()[3]);
    79   writer.addNode("source", node_ids.inverse()[3]);
    75   writer.writeEdge("elek", edge_ids.inverse()[6]);
    80   //  writer.addEdge("elek", edge_ids.inverse()[6]);
    76   writer.write();
    81   writer.write();
    77   
    82   
    78   return 0;
    83   return 0;
    79 }
    84 }