Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/graph/example/accum-compile-times.cpp @ 33

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

updated boost from 1_33_1 to 1_34_1

File size: 3.4 KB
Line 
1//=======================================================================
2// Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
3//
4// Distributed under the Boost Software License, Version 1.0. (See
5// accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7//=======================================================================
8#include <boost/config.hpp>
9#include <fstream>
10#include <iostream>
11#include <numeric>
12#include <iterator>
13#include <string>
14#include <boost/graph/adjacency_list.hpp>
15#include <boost/graph/property_iter_range.hpp>
16
17namespace std
18{
19  template < typename T >
20  std::istream& operator >> (std::istream& in, std::pair < T, T > &p)
21  {
22    in >> p.first >> p.second;
23    return in;
24  }
25}
26
27namespace boost
28{
29  enum vertex_compile_cost_t { vertex_compile_cost };
30  BOOST_INSTALL_PROPERTY(vertex, compile_cost);
31}
32
33using namespace boost;
34
35typedef adjacency_list< listS, // Store out-edges of each vertex in a std::list
36  listS,                       // Store vertex set in a std::list
37  directedS,                   // The file dependency graph is directed
38  // vertex properties
39  property < vertex_name_t, std::string,
40  property < vertex_compile_cost_t, float,
41  property < vertex_distance_t, float,
42  property < vertex_color_t, default_color_type > > > >,
43  // an edge property
44  property < edge_weight_t, float > >
45  file_dep_graph2;
46
47typedef graph_traits<file_dep_graph2>::vertex_descriptor vertex_t;
48typedef graph_traits<file_dep_graph2>::edge_descriptor edge_t;
49
50int
51main()
52{
53  std::ifstream file_in("makefile-dependencies.dat");
54  typedef graph_traits<file_dep_graph2>::vertices_size_type size_type;
55  size_type n_vertices;
56  file_in >> n_vertices;        // read in number of vertices
57#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
58  // std::istream_iterator causes trouble with VC++
59  std::vector<vertex_t> id2vertex;
60  file_dep_graph2 g;
61  for (std::size_t i = 0; i < n_vertices; ++i)
62    id2vertex.push_back(add_vertex(g));
63  std::pair<size_type, size_type> p;
64  while (file_in >> p) 
65    add_edge(id2vertex[p.first], id2vertex[p.second], g);
66#else
67  std::istream_iterator<std::pair<size_type, size_type> >
68    input_begin(file_in), input_end;
69  file_dep_graph2 g(input_begin, input_end, n_vertices);
70#endif
71
72  typedef property_map < file_dep_graph2, vertex_name_t >::type name_map_t;
73  typedef property_map < file_dep_graph2, vertex_compile_cost_t >::type
74    compile_cost_map_t;
75  typedef property_map <file_dep_graph2, vertex_distance_t >::type
76    distance_map_t;
77  typedef property_map <file_dep_graph2, vertex_color_t >::type
78    color_map_t;
79
80  name_map_t name_map = get(vertex_name, g);
81  compile_cost_map_t compile_cost_map = get(vertex_compile_cost, g);
82  distance_map_t distance_map = get(vertex_distance, g);
83  color_map_t color_map = get(vertex_color, g);
84
85  std::ifstream name_in("makefile-target-names.dat");
86  std::ifstream compile_cost_in("target-compile-costs.dat");
87  graph_traits < file_dep_graph2 >::vertex_iterator vi, vi_end;
88  for (tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) {
89    name_in >> name_map[*vi];
90    compile_cost_in >> compile_cost_map[*vi];
91  }
92
93  graph_property_iter_range < file_dep_graph2,
94    vertex_compile_cost_t >::iterator ci, ci_end;
95  tie(ci, ci_end) = get_property_iter_range(g, vertex_compile_cost);
96  std::cout << "total (sequential) compile time: "
97    << std::accumulate(ci, ci_end, 0.0) << std::endl;
98
99  return 0;
100}
101
Note: See TracBrowser for help on using the repository browser.