Boost logo

Boost Users :

From: Stephan Diederich (stephan.diederich_at_[hidden])
Date: 2007-03-02 04:56:26


Hi Shufei,

On 3/1/07, Shufei Fan <fansf_at_[hidden]> wrote:
>
> I defined an double array inside bundled vertex property, and have trouble
> finding ways of accessing it.
>
Neither can I find any where in the document an example on it. Your input
> will
> be much appreciated!

Don't worry, there seems to be no example ;)
Second, there seems to be no way of accesssing it. But this is what I did:

[snipped declarations]

struct Node
> {
> // this is hard to access
> double mode[3];
> int test;
> };
>
> compiler error here:
> boost::property_map<Graph, double Node::*>::type
> nm = get(&Node::mode, *colGraph);//node mode

I think the type of the property map should be:
boost::property_map<Graph, double (Node::*) [3]>::type
(the brackets around the pointer to member are important)

[snipped other errors]

But with that property_map declaration the specialization for the (bundled)
property map doesn't work. So I wrote a new one for arrays.
I'm not really sure if that is the correct way, but at least it works ;)
Maybe we can get Doug (who made the bundled properties) to comment on this.

Your complete example:

#include <iostream>
#include <boost/graph/adjacency_list.hpp>

struct Node
{
  // this was hard to access
  double mode[3];
    int test;
};
struct Edge
{
  //no problem access them
  double nPixels;
  unsigned short nTh;
};

//new specialization of property_map for bundles with arrays
namespace boost{
    template <typename Graph, typename T, typename Bundle, unsigned int
Size>
  struct property_map<Graph, T (Bundle::*) [Size]>
  {
private:
    typedef graph_traits<Graph> traits;
    typedef typename Graph::vertex_bundled vertex_bundled;
    typedef typename Graph::edge_bundled edge_bundled;
    typedef typename mpl::if_c<(detail::is_vertex_bundle<vertex_bundled,
edge_bundled, Bundle>::value),
            typename traits::vertex_descriptor,
            typename traits::edge_descriptor>::type
      descriptor;
    typedef typename mpl::if_c<(detail::is_vertex_bundle<vertex_bundled,
edge_bundled, Bundle>::value),
            vertex_bundled,
            edge_bundled>::type
      actual_bundle;

public:
            typedef bundle_property_map<Graph, descriptor, actual_bundle,
T[Size]> type;
    typedef bundle_property_map<const Graph, descriptor, actual_bundle,
const T[Size]>
      const_type;
  };

};

int main(){
    using namespace boost;
    using namespace std;
    typedef boost::adjacency_list<boost::vecS, boost::vecS,
boost::bidirectionalS,Node, Edge> Graph;

    Graph colGraph(3);
    colGraph[vertex(0, colGraph)].mode[0] = 1.01;

    typedef double (Node::* ptrToNodeMode)[3];
    boost::property_map<Graph, ptrToNodeMode>::type nm = get(&Node::mode,
colGraph);

    Graph::vertex_iterator vit,vend;
    for(tie(vit, vend) = vertices(colGraph); vit != vend; ++vit){
        for(unsigned int i = 0; i < 3; ++i){
                cout << nm[*vit][i] << endl;
        }
    }
}



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