2
int const SIZE=10;
struct DotVertex {
    int Attribute[SIZE];
};

struct DotEdge {
    std::string label;
};

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
        DotVertex, DotEdge> graph_t;

int main() {
    graph_t graphviz;
    boost::dynamic_properties dp(boost::ignore_other_properties);

    dp.property("node_id",     boost::get(&DotVertex::name,        graph_t));
    dp.property("Attribute0", boost::get(&DotVertex::Attribute[0],  graph_t));
    std::ifstream dot("graphnametest2.dot");
     boost::read_graphviz(dot,  graph_t, dp);

How to read unknown properties by an array attribute[SIZE] from a Graphviz DOT file or not even without know its size? For example, the following code is always wrong: dp.property("Attribute0", boost::get(&DotVertex::Attribute[0], graph_t))

sehe
  • 374,641
  • 47
  • 450
  • 633
david
  • 31
  • 3

1 Answers1

3

You can use any property map. But you need a valid one.

All your property maps are invalid. Mostly because graph_t names a type (use graphviz?).

The last one is because there is no member Attribute[0]. There's only Attribute, which is an array. So in order to use it at all you need to add a transformation. See also

DEMO

Live On Coliru

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

int const SIZE=10;

struct DotVertex {
    std::string name;
    int Attribute[SIZE];
};

struct DotEdge {
    std::string label;
};

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, DotVertex, DotEdge> graph_t;

#include <boost/phoenix.hpp>
using boost::phoenix::arg_names::arg1;

int main() {
    graph_t graphviz;
    boost::dynamic_properties dp(boost::ignore_other_properties);

    dp.property("node_id", boost::get(&DotVertex::name, graphviz));
    dp.property("label",   boost::get(&DotEdge::label,  graphviz));

    auto attr_map = boost::get(&DotVertex::Attribute, graphviz);

    for (int i = 0; i<SIZE; ++i)
        dp.property("Attribute" + std::to_string(i), 
           boost::make_transform_value_property_map(arg1[i], attr_map));

    std::ifstream dot("graphnametest2.dot");
    boost::read_graphviz(dot, graphviz, dp);
}
Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • thank you very much for your answer sehe, it's very clear and helpful, however, it left still an important question, that is I have a file .dot which saves several graphs. So I have to read all these unknown properties of these graphs (read not only one graph). I try to define dp for each graph like this: boost::dynamic_properties dp(boost::ignore_other_properties); but it doesn't work, could you gives me some ideas to read these unknown properties of unknown number of graphs? Thank you very much! – david Apr 13 '16 at 05:32
  • No I cannot. Do you know why? Because none of the relevant information is in your question. I'm not a psychic, sorry. – sehe Apr 13 '16 at 09:32