[BGL] Mixing bundled properties and property lists
Hi,
consider the following (excerpt from a) class wrapper around an
adjacency_list:
using namespace boost;
template <typename VertexProperty = no_property>
class MyGraphWrapper {
private:
typedef adjacency_list
On 12/23/05, Nicola Vitacolonna
I want to store some property (in this case, a vertex index) inside the graph implementation, but at the same time I want to allow the client to specify further properties via the template parameter. May the client use the bundled property mechanism, e.g.
struct Label { std::string lab; }; MyGraphWrapper<Label> g;
My test compiled and it seems to run fine. Is it really possible/safe to mix bundle properties with property lists in this way? Or, is there a way to avoid property lists?
Yes, you can avoid property list thanks to a proxy class from VertexProperty : -=-=-=-=-=-=-=-=-=-=- using namespace boost; template <class Tag> struct VertexProperty : public Tag { typedef int vertex_index_t; Tag& tag() { return *this; } const Tag& tag() const { return *this; } vertex_index_t index_; }; template <class Tag = NoTag> class MyGraphWrapper { private: typedef adjacency_list< vecS, listS, bidirectionalS, VertexProperty<Tag> > GraphImpl; // ... }; I use a similar structure in my project, and it works perfectly. You have to define map from vertex_descriptor to vertex_index in each algorithm, which used a vertex_index property. Cheers, PS: Merry Christmas ;) -- Johan
On Dec 23, 2005, at 8:25 AM, Nicola Vitacolonna wrote:
template <typename VertexProperty = no_property> class MyGraphWrapper { private: typedef adjacency_list
> GraphImpl; // ... }; [snip] My test compiled and it seems to run fine. Is it really possible/ safe to mix bundle properties with property lists in this way?
Yes, this is correct.
Or, is there a way to avoid property lists?
Not cleanly. You could aggregate an index property with the
VertexProperty class (or derive from VertexProperty), e.g.,
template<typename BaseProperty>
struct WrapVertexProperty : public BaseProperty
{
WrapVertexProperty() : BaseProperty() { }
WrapVertexProperty(const BaseProperty& bp) : BaseProperty(bp) { }
std::size_t index; // your index property
};
template<>
struct WrapVertexProperty
participants (3)
-
Douglas Gregor
-
Johan Oudinet
-
Nicola Vitacolonna