• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  (C) Copyright Francois Faure 2001
2 //  Distributed under the Boost Software License, Version 1.0. (See
3 //  accompanying file LICENSE_1_0.txt or copy at
4 //  http://www.boost.org/LICENSE_1_0.txt)
5 
6 #include <boost/config.hpp>
7 
8 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
9 #error adjacency_list_io.hpp has not been ported to work with VC++
10 #endif
11 
12 #include <boost/graph/adjacency_list_io.hpp>
13 #include <fstream>
14 
15 using namespace boost;
16 
17 //======== my data structure
18 struct MyStruct
19 {
20     double value;
21 };
operator <<(std::ostream & out,const MyStruct & s)22 std::ostream& operator<<(std::ostream& out, const MyStruct& s)
23 {
24     out << s.value << " ";
25     return out;
26 }
operator >>(std::istream & in,MyStruct & s)27 std::istream& operator>>(std::istream& in, MyStruct& s)
28 {
29     in >> s.value;
30     return in;
31 }
32 
33 //======== vertex properties
34 struct n1_t
35 {
36     enum
37     {
38         num = 23063
39     };
40     typedef vertex_property_tag kind;
41 };
42 struct n2_t
43 {
44     enum
45     {
46         num = 23062
47     };
48     typedef vertex_property_tag kind;
49 };
50 struct n3_t
51 {
52     enum
53     {
54         num = 23061
55     };
56     typedef vertex_property_tag kind;
57 };
58 typedef property< n1_t, int,
59     property< n2_t, double, property< n3_t, MyStruct > > >
60     VertexProperty;
61 
62 //====== edge properties
63 struct e1_t
64 {
65     enum
66     {
67         num = 23064
68     };
69     typedef edge_property_tag kind;
70 };
71 typedef property< e1_t, double > EdgeProperty;
72 
73 //===== graph types
74 
75 typedef adjacency_list< vecS, listS, directedS, no_property, no_property >
76     Graph1;
77 
78 typedef adjacency_list< setS, setS, bidirectionalS, VertexProperty,
79     EdgeProperty >
80     Graph2;
81 
main()82 int main()
83 {
84     // read Graph1
85     Graph1 g1;
86     std::ifstream readFile1("data1.txt");
87     readFile1 >> read(g1);
88     std::cout << "graph g1 from file data1.txt:\n" << write(g1) << std::endl;
89 
90     // read Graph2 and all internal properties
91     Graph2 g2;
92     std::ifstream readFile2("data2.txt");
93     readFile2 >> read(g2);
94     std::cout << "graph g2 from file data2.txt:\n" << write(g2) << std::endl;
95 
96     // read Graph2, no property given. Write no property.
97     Graph2 g21;
98     std::ifstream readFile21("data1.txt");
99     readFile21 >> read(g21, no_property(), no_property());
100     std::cout << "graph g21 from file data1.txt:\n"
101               << write(g21, no_property(), no_property()) << std::endl;
102 
103     // read Graph2, incomplete data in a different order. Write it diffently.
104     Graph2 g31;
105     std::ifstream readFile31("data3.txt");
106     typedef property< n3_t, MyStruct, property< n1_t, int > > readNodeProp;
107     readFile31 >> read(g31, readNodeProp(), EdgeProperty());
108     std::cout << "graph g31 from file data3.txt:\n"
109               << write(g31, property< n3_t, MyStruct >(), EdgeProperty())
110               << std::endl;
111 
112     return 0;
113 }
114