I have a boost graph with vertex , edge and graph properties. I want to make a copy of boost braph. I copied vertex and edge properties ( using copy_graph) of one boost graph into another one but could not able to copy graph properties.
using BGType = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS,
// Vertex Properties...
vertexProps,
// Edge Propereties...
edgeProps,
// Graph Properties
graphProps>;
I have graph properties :
class graphProps {
public:
explicit graphProps(std::string *name = nullptr) { _name = name ? *name : ""; };
std::string _name;
std::map<std::string, std::tuple<std::vector<schPinInfo *>, // input Pins
std::vector<schPinInfo *>, // inout pins
std::vector<schPinInfo *>> // output pins
>
_modInfo;
std::map<std::string, std::vector<std::string>> _altNames;
std::map<std::string, schSymbol> _modSymbol;
}
struct CustomVertexCopy {
BGType const& g1;
BGType& g2;
void operator()(BGType::vertex_descriptor v1, BGType::vertex_descriptor v2) const {
vertexProps const& p1 = g1[v1];
vertexProps& p2 = g2[v2];
p2._refPtr = p1._refPtr;
p2._moduleName = p1._moduleName;
p2._name = p1._name;
}
};
struct CustomEdgeCopy {
BGType const& g1;
BGType& g2;
void operator()(BGType::edge_descriptor e1, BGType::edge_descriptor e2) const {
g2[e2]._name = g1[e1]._name;
}
};
my copy_graph is like this :
OnClick(BGType* bGraph)
{
// some code
BGType* oldBg = new BGType;
boost::copy_graph(*bGraph, *oldBg,
boost::vertex_copy(CustomVertexCopy{*bGraph,*oldBg})
.edge_copy(CustomEdgeCopy{*bGraph, *oldBg}));
// some code
}
How to copy grap properties ?
Simply put
boost::copy_graphdoesn't support it.just copy assigning it will be fine:
Adapted from your previous question with demo:
Live On Coliru
Prints
Deep Cloning Dynamic Data
What if you expected the
schPinInfoobjects to be deep copied as well? To correctly do object tracking so that repeated pins will not be (de)serialized more than once, I suggest Boost Serialization:Live On Coliru
Printing
Notes:
the assertions all pass - making the deepcloned
schPinInfotangible.the deserialized instanced of
schPinInfoare now leaked, which is why you should not be using raw pointers: