1 | |
---|
2 | // (C) Copyright François 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 François 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 | |
---|
20 | using namespace boost; |
---|
21 | |
---|
22 | //======== vertex properties |
---|
23 | struct toto_t { |
---|
24 | enum { num = 23063}; |
---|
25 | typedef vertex_property_tag kind; |
---|
26 | }; |
---|
27 | typedef property< toto_t, double > Toto; |
---|
28 | |
---|
29 | struct radius_t { |
---|
30 | enum { num = 23062}; |
---|
31 | typedef vertex_property_tag kind; |
---|
32 | }; |
---|
33 | typedef property< radius_t, double, Toto > Radius; |
---|
34 | |
---|
35 | struct mass_t { |
---|
36 | enum { num = 23061}; |
---|
37 | typedef vertex_property_tag kind; |
---|
38 | }; |
---|
39 | typedef property< mass_t, int, Radius > Mass; |
---|
40 | |
---|
41 | |
---|
42 | //====== edge properties |
---|
43 | struct stiff_t { |
---|
44 | enum { num = 23064}; |
---|
45 | typedef edge_property_tag kind; |
---|
46 | }; |
---|
47 | typedef property<stiff_t, double> Stiff; |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | //===== graph type |
---|
52 | typedef Mass VertexProperty; |
---|
53 | typedef Stiff EdgeProperty; |
---|
54 | typedef adjacency_list<vecS, setS, bidirectionalS, |
---|
55 | VertexProperty, EdgeProperty> Graph; |
---|
56 | |
---|
57 | |
---|
58 | //===== utilities |
---|
59 | struct Print |
---|
60 | { |
---|
61 | template<class T> |
---|
62 | Print& operator() (const T& t) { |
---|
63 | std::cout << t << " "; |
---|
64 | return (*this); |
---|
65 | } |
---|
66 | }; |
---|
67 | |
---|
68 | template<class T> |
---|
69 | struct Set |
---|
70 | { |
---|
71 | T value; |
---|
72 | |
---|
73 | Set( const T& t ):value(t){} |
---|
74 | |
---|
75 | Set& operator() (T& t) { |
---|
76 | t=value; |
---|
77 | return (*this); |
---|
78 | } |
---|
79 | }; |
---|
80 | |
---|
81 | |
---|
82 | //===== program |
---|
83 | int main(int argc, char* argv[]) |
---|
84 | { |
---|
85 | if (argc < 2) { |
---|
86 | std::cerr<<"args: file"<<std::endl; |
---|
87 | return EXIT_FAILURE; |
---|
88 | } |
---|
89 | |
---|
90 | std::ifstream readFile(argv[1]); |
---|
91 | |
---|
92 | Graph graph; |
---|
93 | readFile >> read( graph ); |
---|
94 | std::cout << write( graph ); |
---|
95 | |
---|
96 | std::cout << "radii:" << std::endl; |
---|
97 | graph_property_iter_range<Graph,radius_t>::type |
---|
98 | seqRadius = get_property_iter_range(graph,radius_t()); |
---|
99 | std::for_each( seqRadius.first, seqRadius.second, Print() ); |
---|
100 | std::cout << std::endl; |
---|
101 | |
---|
102 | std::cout << "stiff:" << std::endl; |
---|
103 | graph_property_iter_range<Graph,stiff_t>::type |
---|
104 | seqStiff = get_property_iter_range(graph, stiff_t()); |
---|
105 | std::for_each( seqStiff.first, seqStiff.second, Print() ); |
---|
106 | std::cout << std::endl; |
---|
107 | |
---|
108 | seqStiff = get_property_iter_range(graph, stiff_t()); |
---|
109 | std::for_each( seqStiff.first, seqStiff.second, Set<double>(2.4) ); |
---|
110 | |
---|
111 | std::cout << "new stiff:" << std::endl; |
---|
112 | seqStiff = get_property_iter_range(graph,stiff_t()); |
---|
113 | std::for_each( seqStiff.first, seqStiff.second, Print() ); |
---|
114 | std::cout << std::endl; |
---|
115 | |
---|
116 | return 0; |
---|
117 | } |
---|