File: property_iterator.cpp

package info (click to toggle)
boost 1.33.1-10
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 100,948 kB
  • ctags: 145,103
  • sloc: cpp: 573,492; xml: 49,055; python: 15,626; ansic: 13,588; sh: 2,099; yacc: 858; makefile: 660; perl: 427; lex: 111; csh: 6
file content (118 lines) | stat: -rw-r--r-- 2,731 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

// (C) Copyright Franois Faure, iMAGIS-GRAVIR / UJF, 2001. Permission
// to copy, use, modify, sell and distribute this software is granted
// provided this copyright notice appears in all copies. This software
// is provided "as is" without express or implied warranty, and with
// no claim as to its suitability for any purpose.


// Revision History:
// 03 May 2001   Jeremy Siek
//      Moved property iterator code to headers. 
// 02 May 2001   Franois Faure
//     Initial version.

#include <boost/graph/adjacency_list_io.hpp>
#include <boost/graph/property_iter_range.hpp>
#include <fstream>
#include <algorithm>


using namespace boost;

//======== vertex properties
struct toto_t {
  enum { num = 23063};
  typedef vertex_property_tag kind;
};
typedef property< toto_t, double > Toto;

struct radius_t {
  enum { num = 23062};
  typedef vertex_property_tag kind;
};
typedef property< radius_t, double, Toto > Radius;

struct mass_t {
  enum { num = 23061};
  typedef vertex_property_tag kind;
};
typedef property< mass_t, int, Radius > Mass;


//====== edge properties
struct stiff_t {
  enum { num = 23064};
  typedef edge_property_tag kind;
};
typedef property<stiff_t, double> Stiff;



//===== graph type
typedef Mass VertexProperty;
typedef Stiff EdgeProperty;
typedef adjacency_list<vecS, setS, bidirectionalS, 
  VertexProperty, EdgeProperty> Graph;


//===== utilities
struct Print
{
  template<class T>
  Print& operator() (const T& t) {
    std::cout << t << " "; 
    return (*this);
  }
};

template<class T>
struct Set
{
  T value;
  
  Set( const T& t ):value(t){}
  
  Set& operator() (T& t) {
    t=value; 
    return (*this);
  }
};


//===== program
int main(int argc, char* argv[])
{
  if (argc < 2) {
    std::cerr<<"args: file"<<std::endl; 
    return EXIT_FAILURE;
  }
  
  std::ifstream readFile(argv[1]);
  
  Graph graph;
  readFile >> read( graph );
  std::cout << write( graph );
  
  std::cout << "radii:" << std::endl;
  graph_property_iter_range<Graph,radius_t>::type 
    seqRadius = get_property_iter_range(graph,radius_t());
  std::for_each( seqRadius.first, seqRadius.second, Print() ); 
  std::cout << std::endl;
  
  std::cout << "stiff:" << std::endl;
  graph_property_iter_range<Graph,stiff_t>::type
    seqStiff = get_property_iter_range(graph, stiff_t());
  std::for_each( seqStiff.first, seqStiff.second, Print() ); 
  std::cout << std::endl;
  
  seqStiff = get_property_iter_range(graph, stiff_t());
  std::for_each( seqStiff.first, seqStiff.second, Set<double>(2.4) );
  
  std::cout << "new stiff:" << std::endl;
  seqStiff = get_property_iter_range(graph,stiff_t());
  std::for_each( seqStiff.first, seqStiff.second, Print() ); 
  std::cout << std::endl;
  
  return 0;
}