| 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 <boost/graph/adjacency_list.hpp> |
|---|
| 11 | |
|---|
| 12 | using namespace boost; |
|---|
| 13 | |
|---|
| 14 | template < typename Graph > void |
|---|
| 15 | read_graph_file(std::istream & in, Graph & g) |
|---|
| 16 | { |
|---|
| 17 | typedef typename graph_traits < Graph >::vertices_size_type size_type; |
|---|
| 18 | size_type n_vertices; |
|---|
| 19 | in >> n_vertices; // read in number of vertices |
|---|
| 20 | for (size_type i = 0; i < n_vertices; ++i) // Add n vertices to the graph |
|---|
| 21 | add_vertex(g); |
|---|
| 22 | size_type u, v; |
|---|
| 23 | while (in >> u) // Read in pairs of integers as edges |
|---|
| 24 | if (in >> v) |
|---|
| 25 | add_edge(u, v, g); |
|---|
| 26 | else |
|---|
| 27 | break; |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | int |
|---|
| 32 | main() |
|---|
| 33 | { |
|---|
| 34 | typedef adjacency_list < listS, // Store out-edges of each vertex in a std::list |
|---|
| 35 | vecS, // Store vertex set in a std::vector |
|---|
| 36 | directedS // The graph is directed |
|---|
| 37 | > graph_type; |
|---|
| 38 | |
|---|
| 39 | graph_type g; // use default constructor to create empty graph |
|---|
| 40 | std::ifstream file_in("makefile-dependencies.dat"); |
|---|
| 41 | read_graph_file(file_in, g); |
|---|
| 42 | |
|---|
| 43 | assert(num_vertices(g) == 15); |
|---|
| 44 | assert(num_edges(g) == 19); |
|---|
| 45 | return 0; |
|---|
| 46 | } |
|---|