Cloning a node

The engine.
Post Reply
jdtoellner
Posts: 71
Joined: Mon Aug 01, 2016 9:45 pm

Cloning a node

Post by jdtoellner »

What's the best way to copy a node?

Under the Introduction to Some Simple Classes: General Copy Functions I read about the clone function. Is that the best way?
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: Cloning a node

Post by shooltz[BayesFusion] »

Try this approach:

Code: Select all

DSL_node *origNode = net.GetNode(hOrig);
int hNew = net.AddNode(origNode->Definition()->GetType(), "ClonedNode");
const DSL_intArray &parents = net.GetParents(hOrig);
for (int i = 0; i < parents.NumItems(); i++)
{
	net.AddArc(parents[i], hNew);
}
net.GetNode(hNew)->Definition()->Clone(*origNode->Definition());
net.GetNode(hNew)->ExtraDefinition()->Clone(*origNode->ExtraDefinition());
For historical reasons, the complete copy requires the "extra definiton" to be cloned along with node definition. This object contains diagnosis-specific data.
jdtoellner
Posts: 71
Joined: Mon Aug 01, 2016 9:45 pm

Re: Cloning a node

Post by jdtoellner »

This is very cool.

I actually wanted to copy a node without the arcs.

Thanks for the post.
Post Reply