[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<vecS, listS, bidirectionalS, property<vertex_index_t, int, VertexProperty> > GraphImpl; // ... }; 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? Nicola

On 12/23/05, Nicola Vitacolonna <vitacolo@dimi.uniud.it> wrote:
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:
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<no_property> { WrapVertexProperty() {} WrapVertexProperty(const no_property&) {}; std::size_t index; // your index property }; This solution isn't quite perfect, unfortunately: algorithms that look for a "vertex_index" property won't find WrapVertexProperty<...>::index, so you'll have to supply vertex index maps to your algorithms or have MyGraphWrapper convert requests for "vertex_index" into requests for &WrapVertexProperty<...>::index. This is on our TODO list to fix, so that bundled properties can integrate more cleanly. Doug
participants (3)
-
Douglas Gregor
-
Johan Oudinet
-
Nicola Vitacolonna