Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/graph/example/default-constructor2.cpp @ 29

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

updated boost from 1_33_1 to 1_34_1

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