In the previous code, you might have wondered where name came from; it is a property map. In the terminology of the BGL, a property map is an object that maps from a set of keys to a corresponding set of values. For example, here you want to look up the name of a vertex. There are a number of ways to construct a property map, which can be broken down into two categories: internal property maps and external property maps. An internal property map is managed by the graph object, whereas an external property map is created outside the graph.
Here you will learn how to create the name property map external to the graph. The basic idea is that you will store the names in a std::vector and use the index of each vertex to offset the vector. Where does this vertex index come from? It, too, is obtained via a property map. It so happens that the variant of adjacency_list being used here has an internal property map for converting from a vertex to the corresponding indexan integer in the range [0,N-1), where N is the number of vertices in the graph. The type of index property map type is obtained using the property_map traits class, and the index property map object is returned by the get function, which takes as parameters a tag to identify the property and the graph object. The name property map object is then constructed using the iterator_property_map class, which is an adaptor that turns any RandomAccessIterator into a property map. The last step is to fill in the values for the name property map, which you can do using the contents of the name2vertex map.
·Construct the name property mapÒ∫ typedef property_map<file_dep_graph, vertex_index_t>::type IndexMap; IndexMap index = get(vertex_index, G); std::vector<std::string> name_vec(num_vertices(G)); iterator_property_map<std::vector<std::string>::iterator, IndexMap> name(name_vec.begin(), index); std::map<std::string, vertex_descriptor>::iterator I; for (i = name2vertex.begin(); i != name2vertex.end(); ++i) name[i->second] = i->first;