|
Boost Users : |
Subject: [Boost-users] [Graph] troubles with pointer properties
From: Paolo Fogliaroni (paolo_at_[hidden])
Date: 2011-10-10 22:00:08
Hello everyone,
my first post here, so I hope not to miss some mailing list rule.
I'm experiencing some problems in using graph internal properties.
I have to generate a graph from a database and I need to differentiate nodes
in my graph,
namely I will have 2 different node categories, say cat1_node and cat2_node.
Each category should have its own property attached.
Ex: say N1 is a cat1_node and N2 is a cat2_node. I want N1 to have a "name"
(string)
property while N2 a "length" (int) property and both have a "label" (string)
property.
To achieve this I though I could use inheritance in the following manner:
//FATHER PROPERTY CLASS
class generic_vertex_property{
public:
generic_vertex_property(){type = 0;}
int type;
std::string label;
};
//SON PROPERTY CLASS
class cat1_property: public generic_vertex_property{
public:
std::string name;
};
//SON PROPERTY CLASS
class cat2_property: public generic_vertex_property{
public:
int length;
};
In this way, I though, I can define my graph something like:
typedef adjacency_list< vecS, vecS, directedS, property<vertex_p_t,
generic_vertex_property*> > Graph;
and add new vertices like:
cat1_property *v1 = new cat1_property();
cat2_property *v2 = new cat2_property();
v1->label = "v1_label";
v1->name = "v1_name";
v2->label = "v2_label";
v2->length = 10;
add_vertex(VertexProperty(v1),G);
add_vertex(VertexProperty(v2),G);
This actually compiles and runs without errors.
The problem comes when I try to access the verteces through a property_map,
like:
vertex_p_map_t vertex_p_map = get(vertex_p, G); //where vertex_p_map_t and
vertex_p have been define before
Indeed from such get function I have objects of
type generic_vertex_property,
thus, when trying to access a property of the sone classes I got this
compile error:
error: class generic_vertex_property has no member named name
I hope I was clear enough, if necessary I can also send the full code.
In the meanwhile here are my questions:
Is it possible to do what I want to do?
Is there a way to get a property map with the "original" object types (as
inserted)?
Do you have some good websites with practical examples, code snippets and so
on about BGL?
Last question comes as, in my opinion, the reference manual is quite
complete, but
1) lot of examples are not compiling ( look like they have not been updated
to the last boost version)
2) examples are usually very basic and it is very hard to get the general
rules behind it.
hope someone can help me out with this.
bests,
Paolo
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net