MCPcopy
hub / github.com/g3n/engine / setParent

Function setParent

core/node.go:344–355  ·  view source on GitHub ↗

setParent is used by Add and AddAt. It verifies that the node is not being added to itself and sets the parent pointer of the specified node. If the specified node had a parent, the specified node is removed from the original parent's list of children. It does not add the specified node to the list

(parent INode, child INode)

Source from the content-addressed store, hash-verified

342// If the specified node had a parent, the specified node is removed from the original parent's list of children.
343// It does not add the specified node to the list of children.
344func setParent(parent INode, child INode) {
345
346 if parent.GetNode() == child.GetNode() {
347 panic("Node.{Add,AddAt}: object can't be added as a child of itself")
348 }
349 // If the specified node already has a parent,
350 // remove it from the original parent's list of children
351 if child.Parent() != nil {
352 child.Parent().GetNode().Remove(child)
353 }
354 child.GetNode().parent = parent
355}
356
357// ChildAt returns the child at the specified index.
358func (n *Node) ChildAt(idx int) INode {

Callers 2

AddMethod · 0.85
AddAtMethod · 0.85

Calls 3

GetNodeMethod · 0.65
ParentMethod · 0.65
RemoveMethod · 0.45

Tested by

no test coverage detected