Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/graph/test/serialize.cpp @ 47

Last change on this file since 47 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 1.9 KB
Line 
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
20struct vertex_properties {
21  std::string name;
22
23  template<class Archive>
24  void serialize(Archive & ar, const unsigned int version) {
25    ar & BOOST_SERIALIZATION_NVP(name);
26  } 
27};
28
29struct edge_properties {
30  std::string name;
31
32  template<class Archive>
33  void serialize(Archive & ar, const unsigned int version) {
34    ar & BOOST_SERIALIZATION_NVP(name);
35  } 
36};
37
38using namespace boost;
39
40typedef adjacency_list<vecS, vecS, undirectedS, 
41               vertex_properties, edge_properties> Graph;
42
43typedef graph_traits<Graph>::vertex_descriptor vd_type;
44
45
46typedef adjacency_list<vecS, vecS, undirectedS, 
47               vertex_properties> Graph_no_edge_property;
48
49int main()
50{
51  {
52    std::ofstream ofs("./kevin-bacon2.dat");
53    archive::xml_oarchive oa(ofs);
54    Graph g;
55                vertex_properties vp;
56                vp.name = "A";
57                vd_type A = add_vertex( vp, g );
58                vp.name = "B";
59                vd_type B = add_vertex( vp, g );
60
61                edge_properties ep;
62                ep.name = "a";
63                add_edge( A, B, ep, g);
64
65    oa << BOOST_SERIALIZATION_NVP(g);
66
67    Graph_no_edge_property g_n;
68    oa << BOOST_SERIALIZATION_NVP(g_n);
69  }
70
71  {
72    std::ifstream ifs("./kevin-bacon2.dat");
73    archive::xml_iarchive ia(ifs);
74    Graph g;
75    ia >> BOOST_SERIALIZATION_NVP(g);
76
77                if  (!( g[*(vertices( g ).first)].name == "A" )) return -1;
78
79    Graph_no_edge_property g_n;
80    ia >> BOOST_SERIALIZATION_NVP(g_n);
81  }
82  return 0;
83}
Note: See TracBrowser for help on using the repository browser.