• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 namespace std
18 {
19 template < typename T >
operator >>(std::istream & in,std::pair<T,T> & p)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 
27 namespace boost
28 {
29 enum vertex_compile_cost_t
30 {
31     vertex_compile_cost
32 };
33 BOOST_INSTALL_PROPERTY(vertex, compile_cost);
34 }
35 
36 using namespace boost;
37 
38 typedef adjacency_list< listS, // Store out-edges of each vertex in a std::list
39     listS, // Store vertex set in a std::list
40     directedS, // The file dependency graph is directed
41     // vertex properties
42     property< vertex_name_t, std::string,
43         property< vertex_compile_cost_t, float,
44             property< vertex_distance_t, float,
45                 property< vertex_color_t, default_color_type > > > >,
46     // an edge property
47     property< edge_weight_t, float > >
48     file_dep_graph2;
49 
50 typedef graph_traits< file_dep_graph2 >::vertex_descriptor vertex_t;
51 typedef graph_traits< file_dep_graph2 >::edge_descriptor edge_t;
52 
main(int argc,const char ** argv)53 int main(int argc, const char** argv)
54 {
55     std::ifstream file_in(argc >= 2 ? argv[1] : "makefile-dependencies.dat");
56     typedef graph_traits< file_dep_graph2 >::vertices_size_type size_type;
57     size_type n_vertices;
58     file_in >> n_vertices; // read in number of vertices
59 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
60     // std::istream_iterator causes trouble with VC++
61     std::vector< vertex_t > id2vertex;
62     file_dep_graph2 g;
63     for (std::size_t i = 0; i < n_vertices; ++i)
64         id2vertex.push_back(add_vertex(g));
65     std::pair< size_type, size_type > p;
66     while (file_in >> p)
67         add_edge(id2vertex[p.first], id2vertex[p.second], g);
68 #else
69     std::istream_iterator< std::pair< size_type, size_type > > input_begin(
70         file_in),
71         input_end;
72     file_dep_graph2 g(input_begin, input_end, n_vertices);
73 #endif
74 
75     typedef property_map< file_dep_graph2, vertex_name_t >::type name_map_t;
76     typedef property_map< file_dep_graph2, vertex_compile_cost_t >::type
77         compile_cost_map_t;
78 
79     name_map_t name_map = get(vertex_name, g);
80     compile_cost_map_t compile_cost_map = get(vertex_compile_cost, g);
81 
82     std::ifstream name_in(argc >= 3 ? argv[2] : "makefile-target-names.dat");
83     std::ifstream compile_cost_in(
84         argc >= 4 ? argv[3] : "target-compile-costs.dat");
85     graph_traits< file_dep_graph2 >::vertex_iterator vi, vi_end;
86     for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
87     {
88         name_in >> name_map[*vi];
89         compile_cost_in >> compile_cost_map[*vi];
90     }
91 
92     graph_property_iter_range< file_dep_graph2,
93         vertex_compile_cost_t >::iterator ci,
94         ci_end;
95     boost::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