
Hi, I've a question about Boost Library Graphs. My Boost Graph is defined as: typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS, boost::property< boost::graph_name_t, std::string >, boost::property< boost::vertex_index_t, ClassA* > > Boost_Graph; So, I want to have a pointer to an entity of class ClassA as vertex property "vertex_index". However, when I try to access this property via a property map boost::property_map< Boost_Graph, boost::vertex_index_t >::type vertexNameMap = get( boost::vertex_index, g ); with vertexNameMap[v] (where v is Vertex_Type) the compiler tells me that the property is not of type 'ClassA*' (as I would expect) but of type 'size_t'. Why? I thought that for the definition of boost::property< boost::vertex_index_t, ClassA* > ClassA* is the template value and defines the type of the property "vertex_index". Any ideas how I can manage it to store pointers as vertex property? Regards, Christian -- Psst! Geheimtipp: Online Games kostenlos spielen bei den GMX Free Games! http://games.entertainment.web.de/de/entertainment/games/free

Do you have to use the property map method? I've converted over to bundled properties. Much simpler and intuitive. http://www.boost.org/libs/graph/doc/bundles.html -----Original Message----- From: Christian Sturz [mailto:linuxkaffee@gmx.net] Sent: Friday, February 15, 2008 1:01 AM To: boost-users@lists.boost.org Subject: [Boost-users] Pointers as graph vertex property Hi, I've a question about Boost Library Graphs. My Boost Graph is defined as: typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS, boost::property< boost::graph_name_t, std::string >, boost::property< boost::vertex_index_t, ClassA* > > Boost_Graph; So, I want to have a pointer to an entity of class ClassA as vertex property "vertex_index". However, when I try to access this property via a property map boost::property_map< Boost_Graph, boost::vertex_index_t >::type vertexNameMap = get( boost::vertex_index, g ); with vertexNameMap[v] (where v is Vertex_Type) the compiler tells me that the property is not of type 'ClassA*' (as I would expect) but of type 'size_t'. Why? I thought that for the definition of boost::property< boost::vertex_index_t, ClassA* > ClassA* is the template value and defines the type of the property "vertex_index". Any ideas how I can manage it to store pointers as vertex property? Regards, Christian -- Psst! Geheimtipp: Online Games kostenlos spielen bei den GMX Free Games! http://games.entertainment.web.de/de/entertainment/games/free _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Do you have to use the property map method?
I've converted over to bundled properties. Much simpler and intuitive. http://www.boost.org/libs/graph/doc/bundles.html
Thank you very much. This was a very good hint and works perfect for me. Now I have another problem. Let's say I want to add an edge between two vertices which are just specified by their bundle property (in my case by two pointer to ClassA). How do I find the corresponding vertex descriptors? My current solution looks like: vertex_descriptor_t MyGraph::getVertex( ClassA *a, bool &found ) { typedef pair< vertex_iterator_t, vertex_iterator_t > vertex_range; for( vertex_range i = vertices( myGraph ); i.first != i.second; ++i.first ) { if( myGraph[ *i.first ].pointToA == a ) { found = true; return *i.first; } } found = false; return 0; } [The vertex property is called "pointToA"]. I find this solution not very elegant because 1) I have to iterate over all vertices and check their properties (pointToA) 2) I don't know how to indicate if a vertex could be not found. In my current version I help out with a bool value passed as parameter. Are there any better solutions for searching of vertices based on their properties? Regards, Christian -- Psst! Geheimtipp: Online Games kostenlos spielen bei den GMX Free Games! http://games.entertainment.web.de/de/entertainment/games/free
participants (2)
-
Christian Sturz
-
Ferng, Andrew D