I have already asked a question on how to write dynamic properties to a DOT file. And its works fine. Now when I try to read the DOT file and build my Graph I am getting some exception. Basically I followed a similar way like writing, to read the DOT file. Below is what I have tried :
I have a Map class, that uses the Cell class as vertices and Cell class uses a separate CellProperty class for setting and getting all the Cell properties. Please refer to the linked question to have an idea about the whole class structure.
boost::dynamic_properties mPropertiesR(boost::ignore_other_properties);
mPropertiesR.property("ID", boost::get(boost::vertex_index, mGraph));
auto valueNavigable = boost::make_transform_value_property_map(
[](Cell &cell) { return cell.GetProperty<bool>("Navigable", false); }, boost::get(boost::vertex_bundle, mGraph));
mPropertiesR.property("Navigable", valueNavigable);
std::ifstream fin(mGraphFilePath.c_str());
std::string const &node_id = "node_id";
boost::read_graphviz(fin, mGraph, mPropertiesR, "node_id");
boost::graph_traits<Graph>::vertex_iterator vi, vi_end, next;
boost::tie(vi, vi_end) = boost::vertices(mGraph);
for (next = vi; vi != vi_end; vi = next) {
// cell.GetProperty() is a templated method the takes a default parameter, thus passing "false" bool parameter which returns the "Navigable" cell property
std::cout<< ": The Navigable property set to :" << mGraph[*next].GetProperty<bool>("Navigable", false);
++next;
}
The code above compiles but I get an exception :
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::dynamic_const_put_error> >'
what(): Attempt to put a value into a const property map:
Aborted (core dumped)
The GetProperty() method uses the CellProperty class to get the property values of each cell. Here is how the GetProperty() method looks like:
template <class T>
T GetProperty(std::string pPropertyName, T pDefaultValue = T()) {
try {
T propertyValue = boost::lexical_cast<T>( mCellProperty.GetPropertyString(pPropertyName, boost::lexical_cast<std::string>(pDefaultValue)));
return propertyValue;
} catch (...) {
std::cout<< ": Unknown exception thrown while getting cell property value :'" << pPropertyName << "'";
}
return pDefaultValue;
}
What I want is to retrieve the vertex properties in the Graph, which I read from the DOT file, like the "Navigable" property and so on. I cant figure out, what exactly I am doing wrong. Please help me. Thanks in advance !