![]() |
NORSYS SOFTWARE © 2002 | NETICA API | C   VERSION   2.15  |
nodelist_bn* DuplicateNodes_bn ( | const nodelist_bn* nodes, net_bn* new_net ) |
Duplicates nodes, putting them in the net new_net. It is okay if new_net is the same as the net they are already in. All of nodes must be in the same net to start with.
A new list of the duplicated nodes will be returned. You should free the list when done with it (e.g. with DeleteNodeList_bn), which won't effect the duplicated nodes. The order of the new list will correspond with the order of the old list. The old list, and the nodes it refers to, will not be modified.
All connectivity strictly between the duplicated nodes will be maintained during the duplication. Parents of duplicated nodes that aren't also being duplicated will result in disconnected links, if the nodes are being duplicated into a different net.
If a duplicated node has the same name as a node already in new_net, then the name of the duplicated node will be modified by adding a numeric suffix to its name (or changing its numeric suffix if it already has one).
If you wish to duplicate a single node, see the "DuplicateNode" example below. If you wish to duplicate a whole net, see "DuplicateNet" below.
Version:
See also:
DupNodeList_bn | Just duplicates the list, but not the nodes | |
NewNode_bn | Creates a new node in a net | |
DeleteNode_bn | Removes a node from its net and frees it |
Example:
// This transfers nodes from the net they are in to new_net, // and returns a new list of the new nodes in the same order as they // appeared in nodes. The old list nodes is deleted. // // In the process each node in nodes is deleted, and a new one created, // so be sure you don't have any dangling pointers to the old nodes. // nodelist_bn* TransferNodes (nodelist_bn* nodes, net_bn* new_net){ int nn, num_nodes = LengthNodeList_bn (nodes); nodelist_bn* new_nodes = DuplicateNodes_bn (nodes, new_net); for (nn = 0; nn < num_nodes; ++nn) DeleteNode_bn (NthNode_bn (nodes, nn)); DeleteNodeList_bn (nodes); // because its full of invalid pointers return new_nodes; }Example 2:
// Handy functions to duplicate a single node // node_bn* DuplicateNode (node_bn* node, net_bn* new_net){ node_bn* new_node; nodelist_bn* newnodes,* nodes = NewNodeList_bn (1, env); SetNthNode_bn (nodes, 0, node); newnodes = DuplicateNodes_bn (nodes, new_net); new_node = NthNode_bn (newnodes, 0); DeleteNodeList_bn (nodes); DeleteNodeList_bn (newnodes); return new_node; } node_bn* DupNode (node_bn* node){ return DuplicateNode (node, GetNodeNet_bn (node)); }Example 3:
// // Duplicates a whole net net_bn* DuplicateNet (net_bn* net, const char* new_name){ nodelist_bn *elim_order, *new_order; net_bn* new_net = NewNet_bn (new_name, env); nodelist_bn* new_nodes = DuplicateNodes_bn (GetNetNodes_bn (net), new_net); DeleteNodeList_bn (new_nodes); elim_order = GetNetElimOrder_bn (net); new_order = MapNodeList (elim_order, new_net); // Defined in NeticaEx.c SetNetElimOrder_bn (new_net, new_order); DeleteNodeList_bn (new_order); SetNetAutoUpdate_bn (new_net, GetNetAutoUpdate_bn (net)); SetNetTitle_bn (new_net, GetNetTitle_bn (net)); SetNetComment_bn (new_net, GetNetComment_bn (net)); SetNetUserData_bn (new_net, 0, GetNetUserData_bn (net, 0)); // May not want return new_net; }