1
2 // (C) Copyright Francois Faure, iMAGIS-GRAVIR / UJF, 2001.
3
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7
8 // Revision History:
9 // 03 May 2001 Jeremy Siek
10 // Moved property iterator code to headers.
11 // 02 May 2001 Francois Faure
12 // Initial version.
13
14 #include <boost/graph/adjacency_list_io.hpp>
15 #include <boost/graph/property_iter_range.hpp>
16 #include <fstream>
17 #include <algorithm>
18
19 using namespace boost;
20
21 //======== vertex properties
22 struct toto_t
23 {
24 enum
25 {
26 num = 23063
27 };
28 typedef vertex_property_tag kind;
29 };
30 typedef property< toto_t, double > Toto;
31
32 struct radius_t
33 {
34 enum
35 {
36 num = 23062
37 };
38 typedef vertex_property_tag kind;
39 };
40 typedef property< radius_t, double, Toto > Radius;
41
42 struct mass_t
43 {
44 enum
45 {
46 num = 23061
47 };
48 typedef vertex_property_tag kind;
49 };
50 typedef property< mass_t, int, Radius > Mass;
51
52 //====== edge properties
53 struct stiff_t
54 {
55 enum
56 {
57 num = 23064
58 };
59 typedef edge_property_tag kind;
60 };
61 typedef property< stiff_t, double > Stiff;
62
63 //===== graph type
64 typedef Mass VertexProperty;
65 typedef Stiff EdgeProperty;
66 typedef adjacency_list< vecS, setS, bidirectionalS, VertexProperty,
67 EdgeProperty >
68 Graph;
69
70 //===== utilities
71 struct Print
72 {
operator ()Print73 template < class T > Print& operator()(const T& t)
74 {
75 std::cout << t << " ";
76 return (*this);
77 }
78 };
79
80 template < class T > struct Set
81 {
82 T value;
83
SetSet84 Set(const T& t) : value(t) {}
85
operator ()Set86 Set& operator()(T& t)
87 {
88 t = value;
89 return (*this);
90 }
91 };
92
93 //===== program
main(int argc,char * argv[])94 int main(int argc, char* argv[])
95 {
96 if (argc < 2)
97 {
98 std::cerr << "args: file" << std::endl;
99 return EXIT_FAILURE;
100 }
101
102 std::ifstream readFile(argv[1]);
103
104 Graph graph;
105 readFile >> read(graph);
106 std::cout << write(graph);
107
108 std::cout << "radii:" << std::endl;
109 graph_property_iter_range< Graph, radius_t >::type seqRadius
110 = get_property_iter_range(graph, radius_t());
111 std::for_each(seqRadius.first, seqRadius.second, Print());
112 std::cout << std::endl;
113
114 std::cout << "stiff:" << std::endl;
115 graph_property_iter_range< Graph, stiff_t >::type seqStiff
116 = get_property_iter_range(graph, stiff_t());
117 std::for_each(seqStiff.first, seqStiff.second, Print());
118 std::cout << std::endl;
119
120 seqStiff = get_property_iter_range(graph, stiff_t());
121 std::for_each(seqStiff.first, seqStiff.second, Set< double >(2.4));
122
123 std::cout << "new stiff:" << std::endl;
124 seqStiff = get_property_iter_range(graph, stiff_t());
125 std::for_each(seqStiff.first, seqStiff.second, Print());
126 std::cout << std::endl;
127
128 return 0;
129 }
130