Boost logo

Boost Users :

From: Johan Oudinet (johan.oudinet_at_[hidden])
Date: 2005-12-27 04:19:21


On 12/23/05, Nicola Vitacolonna <vitacolo_at_[hidden]> wrote:
>
> 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

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