Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/graph/example/property_iterator.cpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 2.7 KB
Line 
1
2// (C) Copyright François Faure, iMAGIS-GRAVIR / UJF, 2001. Permission
3// to copy, use, modify, sell and distribute this software is granted
4// provided this copyright notice appears in all copies. This software
5// is provided "as is" without express or implied warranty, and with
6// no claim as to its suitability for any purpose.
7
8
9// Revision History:
10// 03 May 2001   Jeremy Siek
11//      Moved property iterator code to headers.
12// 02 May 2001   François Faure
13//     Initial version.
14
15#include <boost/graph/adjacency_list_io.hpp>
16#include <boost/graph/property_iter_range.hpp>
17#include <fstream>
18#include <algorithm>
19
20
21using namespace boost;
22
23//======== vertex properties
24struct toto_t {
25  enum { num = 23063};
26  typedef vertex_property_tag kind;
27};
28typedef property< toto_t, double > Toto;
29
30struct radius_t {
31  enum { num = 23062};
32  typedef vertex_property_tag kind;
33};
34typedef property< radius_t, double, Toto > Radius;
35
36struct mass_t {
37  enum { num = 23061};
38  typedef vertex_property_tag kind;
39};
40typedef property< mass_t, int, Radius > Mass;
41
42
43//====== edge properties
44struct stiff_t {
45  enum { num = 23064};
46  typedef edge_property_tag kind;
47};
48typedef property<stiff_t, double> Stiff;
49
50
51
52//===== graph type
53typedef Mass VertexProperty;
54typedef Stiff EdgeProperty;
55typedef adjacency_list<vecS, setS, bidirectionalS, 
56  VertexProperty, EdgeProperty> Graph;
57
58
59//===== utilities
60struct Print
61{
62  template<class T>
63  Print& operator() (const T& t) {
64    std::cout << t << " "; 
65    return (*this);
66  }
67};
68
69template<class T>
70struct Set
71{
72  T value;
73 
74  Set( const T& t ):value(t){}
75 
76  Set& operator() (T& t) {
77    t=value; 
78    return (*this);
79  }
80};
81
82
83//===== program
84int main(int argc, char* argv[])
85{
86  if (argc < 2) {
87    std::cerr<<"args: file"<<std::endl; 
88    return EXIT_FAILURE;
89  }
90 
91  std::ifstream readFile(argv[1]);
92 
93  Graph graph;
94  readFile >> read( graph );
95  std::cout << write( graph );
96 
97  std::cout << "radii:" << std::endl;
98  graph_property_iter_range<Graph,radius_t>::type
99    seqRadius = get_property_iter_range(graph,radius_t());
100  std::for_each( seqRadius.first, seqRadius.second, Print() ); 
101  std::cout << std::endl;
102 
103  std::cout << "stiff:" << std::endl;
104  graph_property_iter_range<Graph,stiff_t>::type
105    seqStiff = get_property_iter_range(graph, stiff_t());
106  std::for_each( seqStiff.first, seqStiff.second, Print() ); 
107  std::cout << std::endl;
108 
109  seqStiff = get_property_iter_range(graph, stiff_t());
110  std::for_each( seqStiff.first, seqStiff.second, Set<double>(2.4) );
111 
112  std::cout << "new stiff:" << std::endl;
113  seqStiff = get_property_iter_range(graph,stiff_t());
114  std::for_each( seqStiff.first, seqStiff.second, Print() ); 
115  std::cout << std::endl;
116 
117  return 0;
118}
Note: See TracBrowser for help on using the repository browser.