[BGL] property_map for or with bundled properties
Hi,
I was trying to use an iterator_property_map with bundled properties and ran
into difficulties. For those having thought about that, I want to post my
solution and also address a question.
Let's start with the solution:
Imagine, one uses bundled properties and has defined the following
EdgeProperty:
struct EdgeProperty{
int edge_index;
}
and
typedef adjacency_list<...> Graph;
Whether this makes sense or not may also be discussed but is not important for
the demonstration purposes.
So if you now want to define an iterator_property_map that is based on the
edge_index, it get's IMHO a bit more complicated than using internal
properties:
typedef property_map
On Fri, 12 Nov 2010, Cedric Laczny wrote:
Hi,
I was trying to use an iterator_property_map with bundled properties and ran into difficulties. For those having thought about that, I want to post my solution and also address a question.
Let's start with the solution: Imagine, one uses bundled properties and has defined the following EdgeProperty: struct EdgeProperty{ int edge_index; } and typedef adjacency_list<...> Graph;
Whether this makes sense or not may also be discussed but is not important for the demonstration purposes.
So if you now want to define an iterator_property_map that is based on the edge_index, it get's IMHO a bit more complicated than using internal properties: typedef property_map
::type EdgeIndexMap; EdgeIndexMap e_index = get(&EdgeProperty::edge_index,g); std::vector< int > flag_vec(num_edges(g), 0); // Create the external property map iterator_property_map< std::vector< int >::iterator, EdgeIndexMap > flags(flag_vec.begin(), e_index); versus an example using vertex_index that is automatically created when using vecS for the vertices: typedef property_map
::type VertexIndexMap; VertexIndexMap v_index = get(vertex_index, g); std::vector< int > flag_vec(num_vertices(g), 0); // Create the external property map iterator_property_map< std::vector< int >::iterator, VertexIndexMap > flags(flag_vec.begin(), v_index); So far for the solution.
I have also a question in this place: What does the "EdgeProperty::*" exactly do? The EdgeProperty is of course the bundle, but what about the "::*" is this some sort of RegEx for "all attributes of this bundle"? I looked at the code in properties.hpp and was able to generally understand the idea, but it did not become clear to me why the "::*" is needed.
"int EdgeProperty::*" is a C++ type (a pointer to member variable) that is a pointer to an int member of the class EdgeProperty. As a bundled property, a variable of that type can point to any bundled property of type int within a graph whose edge bundle type is EdgeProperty. -- Jeremiah Willcock
participants (2)
-
Cedric Laczny
-
Jeremiah Willcock