]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | |
f67539c2 | 2 | // (C) Copyright Francois Faure, iMAGIS-GRAVIR / UJF, 2001. |
7c673cae FG |
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 | |
f67539c2 | 10 | // Moved property iterator code to headers. |
7c673cae FG |
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 | ||
7c673cae FG |
19 | using namespace boost; |
20 | ||
21 | //======== vertex properties | |
f67539c2 TL |
22 | struct toto_t |
23 | { | |
24 | enum | |
25 | { | |
26 | num = 23063 | |
27 | }; | |
28 | typedef vertex_property_tag kind; | |
7c673cae FG |
29 | }; |
30 | typedef property< toto_t, double > Toto; | |
31 | ||
f67539c2 TL |
32 | struct radius_t |
33 | { | |
34 | enum | |
35 | { | |
36 | num = 23062 | |
37 | }; | |
38 | typedef vertex_property_tag kind; | |
7c673cae FG |
39 | }; |
40 | typedef property< radius_t, double, Toto > Radius; | |
41 | ||
f67539c2 TL |
42 | struct mass_t |
43 | { | |
44 | enum | |
45 | { | |
46 | num = 23061 | |
47 | }; | |
48 | typedef vertex_property_tag kind; | |
7c673cae FG |
49 | }; |
50 | typedef property< mass_t, int, Radius > Mass; | |
51 | ||
7c673cae | 52 | //====== edge properties |
f67539c2 TL |
53 | struct stiff_t |
54 | { | |
55 | enum | |
56 | { | |
57 | num = 23064 | |
58 | }; | |
59 | typedef edge_property_tag kind; | |
7c673cae | 60 | }; |
f67539c2 | 61 | typedef property< stiff_t, double > Stiff; |
7c673cae FG |
62 | |
63 | //===== graph type | |
64 | typedef Mass VertexProperty; | |
65 | typedef Stiff EdgeProperty; | |
f67539c2 TL |
66 | typedef adjacency_list< vecS, setS, bidirectionalS, VertexProperty, |
67 | EdgeProperty > | |
68 | Graph; | |
7c673cae FG |
69 | |
70 | //===== utilities | |
71 | struct Print | |
72 | { | |
f67539c2 TL |
73 | template < class T > Print& operator()(const T& t) |
74 | { | |
75 | std::cout << t << " "; | |
76 | return (*this); | |
77 | } | |
7c673cae FG |
78 | }; |
79 | ||
f67539c2 | 80 | template < class T > struct Set |
7c673cae | 81 | { |
f67539c2 | 82 | T value; |
7c673cae | 83 | |
f67539c2 TL |
84 | Set(const T& t) : value(t) {} |
85 | ||
86 | Set& operator()(T& t) | |
87 | { | |
88 | t = value; | |
89 | return (*this); | |
90 | } | |
91 | }; | |
7c673cae FG |
92 | |
93 | //===== program | |
94 | int main(int argc, char* argv[]) | |
95 | { | |
f67539c2 TL |
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; | |
7c673cae | 124 | seqStiff = get_property_iter_range(graph, stiff_t()); |
f67539c2 TL |
125 | std::for_each(seqStiff.first, seqStiff.second, Print()); |
126 | std::cout << std::endl; | |
127 | ||
128 | return 0; | |
7c673cae | 129 | } |