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);

Graphviz DOTファイルから配列属性[SIZE]によって不明なプロパティを読み取る方法、またはそのサイズがわからなくても読み取る方法は? たとえば、次のコードは常に間違っています: dp.property("Attribute0", boost::get(&DotVertex::Attribute[0], graph_t))

4

1 に答える 1

3

任意のプロパティ マップを使用できます。ただし、有効なものが必要です。

すべてのプロパティ マップが無効です。ほとんどの場合graph_t、型に名前を付けるためです ( graphviz? を使用)。

最後はメンバーがいないからですAttribute[0]Attribute配列であるのみがあります。したがって、それを使用するには、変換を追加する必要があります。こちらもご覧ください

デモ

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);
}
于 2016-04-12T07:28:08.303 に答える