1 //=======================================================================
2 // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
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 //=======================================================================
14 This example appears to be broken and crashes at runtime, see https://github.com/boostorg/graph/issues/148
19 #define _CRT_SECURE_NO_WARNINGS
22 #include <boost/config.hpp>
27 #ifdef BOOST_HAS_UNISTD_H
31 #include <boost/graph/adjacency_list.hpp>
33 using namespace boost
;
35 template < typename Graph
, typename VertexNamePropertyMap
> void
36 read_graph_file(std::istream
& graph_in
, std::istream
& name_in
,
37 Graph
& g
, VertexNamePropertyMap name_map
)
39 typedef typename graph_traits
< Graph
>::vertices_size_type size_type
;
41 typename graph_traits
< Graph
>::vertex_descriptor u
;
42 typename property_traits
< VertexNamePropertyMap
>::value_type name
;
44 graph_in
>> n_vertices
; // read in number of vertices
45 for (size_type i
= 0; i
< n_vertices
; ++i
) { // Add n vertices to the graph
48 put(name_map
, u
, name
); // ** Attach name property to vertex u **
51 while (graph_in
>> src
) // Read in edges
53 add_edge(src
, targ
, g
); // add an edge to the graph
60 main(int argc
, const char** argv
)
62 typedef adjacency_list
< listS
, // Store out-edges of each vertex in a std::list
63 vecS
, // Store vertex set in a std::vector
64 directedS
, // The graph is directed
65 property
< vertex_name_t
, std::string
> // Add a vertex property
68 graph_type g
; // use default constructor to create empty graph
69 std::ifstream
file_in(argc
>= 2 ? argv
[1] : "makefile-dependencies.dat"),
70 name_in(argc
>= 2 ? argv
[1] : "makefile-target-names.dat");
72 std::cerr
<< "** Error: could not open file makefile-target-names.dat"
76 // Obtain internal property map from the graph
77 property_map
< graph_type
, vertex_name_t
>::type name_map
=
79 read_graph_file(file_in
, name_in
, g
, name_map
);
81 // Create storage for last modified times
82 std::vector
< time_t > last_mod_vec(num_vertices(g
));
83 // Create nickname for the property map type
84 typedef iterator_property_map
< std::vector
< time_t >::iterator
,
85 property_map
< graph_type
, vertex_index_t
>::type
, time_t, time_t&> iter_map_t
;
86 // Create last modified time property map
87 iter_map_t
mod_time_map(last_mod_vec
.begin(), get(vertex_index
, g
));
89 property_map
< graph_type
, vertex_name_t
>::type name
= get(vertex_name
, g
);
91 graph_traits
< graph_type
>::vertex_descriptor u
;
92 typedef graph_traits
< graph_type
>::vertex_iterator vertex_iter_t
;
93 std::pair
< vertex_iter_t
, vertex_iter_t
> p
;
94 for (p
= vertices(g
); p
.first
!= p
.second
; ++p
.first
) {
96 if (stat(name
[u
].c_str(), &stat_buf
) != 0)
97 std::cerr
<< "error in stat() for file " << name
[u
] << std::endl
;
98 put(mod_time_map
, u
, stat_buf
.st_mtime
);
101 for (p
= vertices(g
); p
.first
!= p
.second
; ++p
.first
) {
102 std::cout
<< name
[*p
.first
] << " was last modified at "
103 << ctime(&mod_time_map
[*p
.first
]);
105 assert(num_vertices(g
) == 15);
106 assert(num_edges(g
) == 19);