| 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 | |
|---|
| 21 | using namespace boost; |
|---|
| 22 | |
|---|
| 23 | //======== vertex properties |
|---|
| 24 | struct toto_t { |
|---|
| 25 | enum { num = 23063}; |
|---|
| 26 | typedef vertex_property_tag kind; |
|---|
| 27 | }; |
|---|
| 28 | typedef property< toto_t, double > Toto; |
|---|
| 29 | |
|---|
| 30 | struct radius_t { |
|---|
| 31 | enum { num = 23062}; |
|---|
| 32 | typedef vertex_property_tag kind; |
|---|
| 33 | }; |
|---|
| 34 | typedef property< radius_t, double, Toto > Radius; |
|---|
| 35 | |
|---|
| 36 | struct mass_t { |
|---|
| 37 | enum { num = 23061}; |
|---|
| 38 | typedef vertex_property_tag kind; |
|---|
| 39 | }; |
|---|
| 40 | typedef property< mass_t, int, Radius > Mass; |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | //====== edge properties |
|---|
| 44 | struct stiff_t { |
|---|
| 45 | enum { num = 23064}; |
|---|
| 46 | typedef edge_property_tag kind; |
|---|
| 47 | }; |
|---|
| 48 | typedef property<stiff_t, double> Stiff; |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | //===== graph type |
|---|
| 53 | typedef Mass VertexProperty; |
|---|
| 54 | typedef Stiff EdgeProperty; |
|---|
| 55 | typedef adjacency_list<vecS, setS, bidirectionalS, |
|---|
| 56 | VertexProperty, EdgeProperty> Graph; |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | //===== utilities |
|---|
| 60 | struct Print |
|---|
| 61 | { |
|---|
| 62 | template<class T> |
|---|
| 63 | Print& operator() (const T& t) { |
|---|
| 64 | std::cout << t << " "; |
|---|
| 65 | return (*this); |
|---|
| 66 | } |
|---|
| 67 | }; |
|---|
| 68 | |
|---|
| 69 | template<class T> |
|---|
| 70 | struct 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 |
|---|
| 84 | int 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 | } |
|---|