1 | // Copyright (C) 2006 Trustees of Indiana University |
2 | // |
3 | // Distributed under the Boost Software License, Version 1.0. |
4 | // (See accompanying file LICENSE_1_0.txt or copy at |
5 | // http://www.boost.org/LICENSE_1_0.txt) |
6 | |
7 | #include <boost/config.hpp> |
8 | #include <iostream> |
9 | #include <fstream> |
10 | #include <string> |
11 | #include <boost/tuple/tuple.hpp> |
12 | #include <boost/graph/adjacency_list.hpp> |
13 | #include <boost/graph/visitors.hpp> |
14 | #include <boost/graph/breadth_first_search.hpp> |
15 | #include <map> |
16 | #include <boost/graph/adj_list_serialize.hpp> |
17 | #include <boost/archive/xml_iarchive.hpp> |
18 | #include <boost/archive/xml_oarchive.hpp> |
19 | |
20 | struct vertex_properties |
21 | { |
22 | std::string name; |
23 | |
24 | template < class Archive > |
25 | void serialize(Archive& ar, const unsigned int /*version*/) |
26 | { |
27 | ar& BOOST_SERIALIZATION_NVP(name); |
28 | } |
29 | }; |
30 | |
31 | struct edge_properties |
32 | { |
33 | std::string name; |
34 | |
35 | template < class Archive > |
36 | void serialize(Archive& ar, const unsigned int /*version*/) |
37 | { |
38 | ar& BOOST_SERIALIZATION_NVP(name); |
39 | } |
40 | }; |
41 | |
42 | using namespace boost; |
43 | |
44 | typedef adjacency_list< vecS, vecS, undirectedS, vertex_properties, |
45 | edge_properties > |
46 | Graph; |
47 | |
48 | typedef graph_traits< Graph >::vertex_descriptor vd_type; |
49 | |
50 | typedef adjacency_list< vecS, vecS, undirectedS, vertex_properties > |
51 | Graph_no_edge_property; |
52 | |
53 | int main() |
54 | { |
55 | { |
56 | std::ofstream ofs("./kevin-bacon2.dat" ); |
57 | archive::xml_oarchive oa(ofs); |
58 | Graph g; |
59 | vertex_properties vp; |
60 | vp.name = "A" ; |
61 | vd_type A = add_vertex(p: vp, g_&: g); |
62 | vp.name = "B" ; |
63 | vd_type B = add_vertex(p: vp, g_&: g); |
64 | |
65 | edge_properties ep; |
66 | ep.name = "a" ; |
67 | add_edge(u: A, v: B, p: ep, g_&: g); |
68 | |
69 | oa << BOOST_SERIALIZATION_NVP(g); |
70 | |
71 | Graph_no_edge_property g_n; |
72 | oa << BOOST_SERIALIZATION_NVP(g_n); |
73 | } |
74 | |
75 | { |
76 | std::ifstream ifs("./kevin-bacon2.dat" ); |
77 | archive::xml_iarchive ia(ifs); |
78 | Graph g; |
79 | ia >> BOOST_SERIALIZATION_NVP(g); |
80 | |
81 | if (!(g[*(vertices(g_: g).first)].name == "A" )) |
82 | return -1; |
83 | |
84 | Graph_no_edge_property g_n; |
85 | ia >> BOOST_SERIALIZATION_NVP(g_n); |
86 | } |
87 | return 0; |
88 | } |
89 | |