AddAt adds the specified node to the list of children at the specified index and sets its parent pointer. If the specified node had a parent, the specified node is removed from the original parent's list of children.
(idx int, ichild INode)
| 319 | // AddAt adds the specified node to the list of children at the specified index and sets its parent pointer. |
| 320 | // If the specified node had a parent, the specified node is removed from the original parent's list of children. |
| 321 | func (n *Node) AddAt(idx int, ichild INode) *Node { |
| 322 | |
| 323 | // Validate position |
| 324 | if idx < 0 || idx > len(n.children) { |
| 325 | panic("Node.AddAt: invalid position") |
| 326 | } |
| 327 | |
| 328 | setParent(n.GetINode(), ichild) |
| 329 | |
| 330 | // Insert child in the specified position |
| 331 | n.children = append(n.children, nil) |
| 332 | copy(n.children[idx+1:], n.children[idx:]) |
| 333 | n.children[idx] = ichild |
| 334 | |
| 335 | n.Dispatch(OnDescendant, nil) |
| 336 | |
| 337 | return n |
| 338 | } |
| 339 | |
| 340 | // setParent is used by Add and AddAt. |
| 341 | // It verifies that the node is not being added to itself and sets the parent pointer of the specified node. |