9 |
14 |
10 int main() { |
15 int main() { |
11 ifstream input("test.lgf"); |
16 ifstream input("test.lgf"); |
12 SmartGraph graph; |
17 SmartGraph graph; |
13 GraphReader<SmartGraph> reader(input, graph); |
18 GraphReader<SmartGraph> reader(input, graph); |
|
19 |
14 SmartGraph::NodeMap<int> id(graph); |
20 SmartGraph::NodeMap<int> id(graph); |
15 reader.readNodeMap("id", id); |
21 reader.readNodeMap("id", id); |
|
22 |
16 SmartGraph::NodeMap<int> cost(graph); |
23 SmartGraph::NodeMap<int> cost(graph); |
17 reader.readNodeMap("cost", cost); |
24 reader.readNodeMap("cost", cost); |
|
25 |
18 SmartGraph::NodeMap<string> color(graph); |
26 SmartGraph::NodeMap<string> color(graph); |
19 reader.readNodeMap("color", color); |
27 reader.readNodeMap("color", color); |
|
28 |
20 SmartGraph::NodeMap<string> description(graph); |
29 SmartGraph::NodeMap<string> description(graph); |
21 reader.readNodeMap<QuotedStringReader>("description", description); |
30 reader.readNodeMap<QuotedStringReader>("description", description); |
|
31 |
22 SmartGraph::EdgeMap<char> mmap(graph); |
32 SmartGraph::EdgeMap<char> mmap(graph); |
23 reader.readEdgeMap("mmap", mmap); |
33 reader.readEdgeMap("mmap", mmap); |
|
34 |
24 reader.skipEdgeMap<QuotedStringReader>("description"); |
35 reader.skipEdgeMap<QuotedStringReader>("description"); |
|
36 |
|
37 SmartGraph::Node source; |
|
38 reader.readNode("source", source); |
|
39 |
|
40 SmartGraph::Edge newedge; |
|
41 reader.readEdge("newedge", newedge); |
|
42 |
25 try { |
43 try { |
26 reader.read(); |
44 reader.read(); |
27 } catch (IOException& e) { |
45 } catch (IOException& e) { |
28 cerr << e.what() << endl; |
46 cerr << e.what() << endl; |
29 } catch (Exception e) { |
47 } catch (Exception e) { |
34 } |
52 } |
35 |
53 |
36 for (SmartGraph::EdgeIt it(graph); it != INVALID; ++it) { |
54 for (SmartGraph::EdgeIt it(graph); it != INVALID; ++it) { |
37 cout << mmap[it] << ' ' << id[graph.source(it)] << ' ' << id[graph.target(it)] << endl; |
55 cout << mmap[it] << ' ' << id[graph.source(it)] << ' ' << id[graph.target(it)] << endl; |
38 } |
56 } |
|
57 |
|
58 cout << id[source] << ' ' << cost[source] << ' ' << color[source] << ' ' << description[source] << endl; |
|
59 cout << mmap[newedge] << ' ' << id[graph.source(newedge)] << ' ' << id[graph.target(newedge)] << endl; |
|
60 |
|
61 ofstream output("copy.lgf"); |
|
62 GraphWriter<SmartGraph> writer(output, graph); |
|
63 |
|
64 DescriptorMap<SmartGraph, SmartGraph::Node, SmartGraph::NodeIt, SmartGraph::NodeMap<int> > node_ids(graph); |
|
65 |
|
66 writer.writeNodeMap("id", node_ids); |
|
67 writer.writeNodeMap<QuotedStringWriter>("format", description); |
|
68 |
|
69 DescriptorMap<SmartGraph, SmartGraph::Edge, SmartGraph::EdgeIt, SmartGraph::EdgeMap<int> > edge_ids(graph); |
|
70 |
|
71 writer.writeEdgeMap("id", edge_ids); |
|
72 writer.writeEdgeMap("chars", mmap); |
|
73 |
|
74 writer.writeNode("source", node_ids.inverse()[3]); |
|
75 writer.writeEdge("elek", edge_ids.inverse()[6]); |
|
76 writer.write(); |
|
77 |
39 return 0; |
78 return 0; |
40 } |
79 } |