]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/last-mod-time.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / graph / example / last-mod-time.cpp
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
9
10 /*
11 IMPORTANT:
12 ~~~~~~~~~~
13
14 This example appears to be broken and crashes at runtime, see https://github.com/boostorg/graph/issues/148
15
16 */
17
18 #ifdef _MSC_VER
19 #define _CRT_SECURE_NO_WARNINGS
20 #endif
21
22 #include <boost/config.hpp>
23 #include <iostream>
24 #include <fstream>
25 #include <string>
26 #include <ctime>
27 #ifdef BOOST_HAS_UNISTD_H
28 #include <unistd.h>
29 #endif
30 #include <sys/stat.h>
31 #include <boost/graph/adjacency_list.hpp>
32
33 using namespace boost;
34
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)
38 {
39 typedef typename graph_traits < Graph >::vertices_size_type size_type;
40 size_type n_vertices;
41 typename graph_traits < Graph >::vertex_descriptor u;
42 typename property_traits < VertexNamePropertyMap >::value_type name;
43
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
46 u = add_vertex(g);
47 name_in >> name;
48 put(name_map, u, name); // ** Attach name property to vertex u **
49 }
50 size_type src, targ;
51 while (graph_in >> src) // Read in edges
52 if (graph_in >> targ)
53 add_edge(src, targ, g); // add an edge to the graph
54 else
55 break;
56 }
57
58
59 int
60 main(int argc, const char** argv)
61 {
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
66 >graph_type;
67
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");
71 if (!file_in) {
72 std::cerr << "** Error: could not open file makefile-target-names.dat"
73 << std::endl;
74 exit(-1);
75 }
76 // Obtain internal property map from the graph
77 property_map < graph_type, vertex_name_t >::type name_map =
78 get(vertex_name, g);
79 read_graph_file(file_in, name_in, g, name_map);
80
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));
88
89 property_map < graph_type, vertex_name_t >::type name = get(vertex_name, g);
90 struct stat stat_buf;
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) {
95 u = *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);
99 }
100
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]);
104 }
105 assert(num_vertices(g) == 15);
106 assert(num_edges(g) == 19);
107 return 0;
108 }