Hi Shufei,
On 3/1/07, Shufei Fan 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::type
nm = get(&Node::mode, *colGraph);//node mode
I think the type of the property map should be:
boost::property_map::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
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
struct property_map
{
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::value),
typename traits::vertex_descriptor,
typename traits::edge_descriptor>::type
descriptor;
typedef typename mpl::if_c<(detail::is_vertex_bundle::value),
vertex_bundled,
edge_bundled>::type
actual_bundle;
public:
typedef bundle_property_map type;
typedef bundle_property_map
const_type;
};
};
int main(){
using namespace boost;
using namespace std;
typedef boost::adjacency_list Graph;
Graph colGraph(3);
colGraph[vertex(0, colGraph)].mode[0] = 1.01;
typedef double (Node::* ptrToNodeMode)[3];
boost::property_map::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;
}
}
}