| 1 | #include <boost/graph/adjacency_list.hpp>
|
|---|
| 2 | #include "graphml.hpp"
|
|---|
| 3 | #include <fstream>
|
|---|
| 4 |
|
|---|
| 5 | using namespace std;
|
|---|
| 6 | using namespace boost;
|
|---|
| 7 |
|
|---|
| 8 | struct VertexProps
|
|---|
| 9 | {
|
|---|
| 10 | string string_prop;
|
|---|
| 11 | int int_prop;
|
|---|
| 12 | long long_prop;
|
|---|
| 13 | bool bool_prop;
|
|---|
| 14 | float float_prop;
|
|---|
| 15 | double double_prop;
|
|---|
| 16 | };
|
|---|
| 17 |
|
|---|
| 18 | int main(int argc, char** argv)
|
|---|
| 19 | {
|
|---|
| 20 |
|
|---|
| 21 | typedef adjacency_list<vecS,vecS,directedS,
|
|---|
| 22 | VertexProps,
|
|---|
| 23 | property<edge_weight_t,double> > graph_t;
|
|---|
| 24 | graph_t g;
|
|---|
| 25 | dynamic_properties dp;
|
|---|
| 26 | dp.property("string_prop",get(&VertexProps::string_prop,g));
|
|---|
| 27 | dp.property("int_prop",get(&VertexProps::int_prop,g));
|
|---|
| 28 | dp.property("long_prop",get(&VertexProps::long_prop,g));
|
|---|
| 29 | dp.property("bool_prop",get(&VertexProps::bool_prop,g));
|
|---|
| 30 | dp.property("float_prop",get(&VertexProps::float_prop,g));
|
|---|
| 31 | dp.property("double_prop",get(&VertexProps::double_prop,g));
|
|---|
| 32 | dp.property("weight",get(edge_weight_t(),g));
|
|---|
| 33 |
|
|---|
| 34 | ifstream ifile("reader-test.xml");
|
|---|
| 35 | read_graphml(ifile, g, dp);
|
|---|
| 36 | ifile.close();
|
|---|
| 37 |
|
|---|
| 38 | assert(num_vertices(g) == 9);
|
|---|
| 39 | assert(num_edges(g) == 9);
|
|---|
| 40 | assert(g[vertex(2,g)].string_prop == "foo");
|
|---|
| 41 | assert(g[vertex(2,g)].int_prop == 100);
|
|---|
| 42 | assert(g[vertex(2,g)].long_prop == 3);
|
|---|
| 43 | assert(g[vertex(2,g)].bool_prop == true);
|
|---|
| 44 | assert(g[vertex(2,g)].float_prop == 1.5);
|
|---|
| 45 | assert(g[vertex(2,g)].double_prop == 1.1);
|
|---|
| 46 |
|
|---|
| 47 | graph_traits<graph_t>::vertex_iterator v, v_end;
|
|---|
| 48 | for (tie(v,v_end) = vertices(g); v != v_end; ++v)
|
|---|
| 49 | {
|
|---|
| 50 | if (*v == vertex(2,g))
|
|---|
| 51 | continue;
|
|---|
| 52 | assert(g[*v].string_prop == "default");
|
|---|
| 53 | assert(g[*v].int_prop == 42);
|
|---|
| 54 | assert(g[*v].long_prop == 42);
|
|---|
| 55 | assert(g[*v].bool_prop == false);
|
|---|
| 56 | assert(g[*v].float_prop == 0.0);
|
|---|
| 57 | assert(g[*v].double_prop == 0.0);
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | assert(get(edge_weight_t(), g, edge(vertex(0,g),vertex(1,g),g).first) == 0.0);
|
|---|
| 61 | assert(get(edge_weight_t(), g, edge(vertex(1,g),vertex(2,g),g).first) == 0.8);
|
|---|
| 62 |
|
|---|
| 63 | ofstream ofile("writer-test.xml");
|
|---|
| 64 | write_graphml(ofile, g, dp);
|
|---|
| 65 | ofile.close();
|
|---|
| 66 |
|
|---|
| 67 | graph_t g2;
|
|---|
| 68 | dynamic_properties dp2;
|
|---|
| 69 | dp2.property("string_prop",get(&VertexProps::string_prop,g2));
|
|---|
| 70 | dp2.property("int_prop",get(&VertexProps::int_prop,g2));
|
|---|
| 71 | dp2.property("long_prop",get(&VertexProps::long_prop,g2));
|
|---|
| 72 | dp2.property("bool_prop",get(&VertexProps::bool_prop,g2));
|
|---|
| 73 | dp2.property("float_prop",get(&VertexProps::float_prop,g2));
|
|---|
| 74 | dp2.property("double_prop",get(&VertexProps::double_prop,g2));
|
|---|
| 75 | dp2.property("weight",get(edge_weight_t(),g2));
|
|---|
| 76 | ifile.open("writer-test.xml");
|
|---|
| 77 | read_graphml(ifile, g2, dp2);
|
|---|
| 78 | ifile.close();
|
|---|
| 79 |
|
|---|
| 80 | assert(num_vertices(g) == num_vertices(g2));
|
|---|
| 81 | assert(num_edges(g) == num_edges(g2));
|
|---|
| 82 |
|
|---|
| 83 | for (tie(v,v_end) = vertices(g); v != v_end; ++v)
|
|---|
| 84 | {
|
|---|
| 85 | assert(g[*v].string_prop == g2[*v].string_prop);
|
|---|
| 86 | assert(g[*v].int_prop == g2[*v].int_prop);
|
|---|
| 87 | assert(g[*v].long_prop == g2[*v].long_prop);
|
|---|
| 88 | assert(g[*v].bool_prop == g2[*v].bool_prop);
|
|---|
| 89 | assert(g[*v].float_prop == g2[*v].float_prop);
|
|---|
| 90 | assert(g[*v].double_prop == g2[*v].double_prop);
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | graph_traits<graph_t>::edge_iterator e, e_end;
|
|---|
| 94 | for (tie(e,e_end) = edges(g); e != e_end; ++e)
|
|---|
| 95 | assert(get(edge_weight_t(), g, *e) == get(edge_weight_t(), g2, *e));
|
|---|
| 96 |
|
|---|
| 97 | return 0;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|