| NORSYS SOFTWARE © 2007 | NETICA API | C VERSION 3.25

nodelist_bn* CopyNodes_bn ( | const nodelist_bn* nodes, net_bn* new_net, const char* control )

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.

In future, control will allow you to control what gets copied. For now, pass NULL.

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.

The user fields (SetNodeUserField_bn) of each node in nodes will be copied to the corresponding newly created nodes, but the user data (SetNodeUserData_bn) will not (they will each be set to NULL).

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 CopyNet_bn.

Version:

In version 3.05 and later.
Earlier versions had a function called DuplicateNodes_bn that did not have the control parameter.

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
CopyNet_bn |  | Duplicates the entire net

Example:

    The following function is available in NeticaEx.c:
    // 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 = CopyNodes_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:

    The following function is available in NeticaEx.c:
    // Handy functions to duplicate a single node.
    //
    node_bn* DuplicateNode (node_bn* node, net_bn* new_net){
        node_bn* new_node;
        nodelist_bn* nodes    = NewNodeList2_bn (1, GetNodeNet_bn (node));
        nodelist_bn* newnodes = NewNodeList2_bn (1, new_net);
        SetNthNode_bn (nodes, 0, node);
        newnodes = CopyNodes_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));
    }