|
||||||
SUMMARY: CHILDREN | PARAMETER | INSTPROC | INSTFILTER | INSTFORWARD | DETAIL: | INSTPROC |
::xotcl::Object
Nodes are arranged in a tree structure
Variables | |||
Name | Default Value | Class | Comment |
nodeName |
::xox::Node |
Methods | |
Name | Comment |
/ {nodeName args}
| Slash method is a recursive method that is used to traverse the Node tree |
addAutoNameNode {node}
| Adds a node as a child of this node and will produce a unique name among the children of this node |
addAutoNameNodeNoConfigureNode {node}
| Used internally |
addNode {node}
| Adds a node as a child of this node |
addNodeNoConfigureNode {node}
| Used internally |
childName {nodeName}
| |
cleanUpNode {}
| Deprecated |
configureNode {}
| Allows a node to configure itself when added to the node tree |
copyNewNode {node}
| |
copyNode {node}
| |
copyNodeInternal {name node}
| |
createAutoNamedChild {class args}
| Creates a new child of this node that is a new instance of class using initialization arguments args |
createAutoNamedChildInternal {class createArgs}
| |
createChild {name class args}
| Create a new object as a child of this element |
createChildInternal {name class createArgs}
| |
createNewChild {class args}
| Better name for createAutoNamedChild |
dumpData {{tabs ""}}
| Returns a formatted string of all the data on this Node |
dumpTreeData {{tabs ""}}
| Returns a formatted string representation of all the data held in this sub tree |
findRoot {}
| Finds the root of the node-tree where this node lives |
fixedName {name}
| |
getAllSubNodes {}
| Returns a list of all nodes that exist in the sub-tree starting with this node |
getNode {nodeName}
| Gets a child of this node that has the nodeName given |
getNodeName {}
| |
hasNode {nodeName}
| Checks for a child with nodeName under this node |
nextName {nodeName}
| Produces the next unique nodeName among the children of this node |
nodeNameFromClass {}
| Create a nodeName from the nodes's class |
nodes {}
| Returns a list of nodes that are children of this node |
parentNode {}
| |
path {}
| Path returns the nodeNames of the nodes from the current node to the root of the tree |
setParentNode {node}
| Sets the parent node for this node |
treeView {{tabs ""}}
| Returns a formatted string that displays the tree node names in this subtree |
Methods from ::xotcl::Object |
#, ., ?, ?code, ?methods, ?object, abstract, copy, coverageFilter, defaultmethod, extractConfigureArg, filterappend, garbageCollect, get#, getClean#, hasclass, init, methodTag, mixinappend, move, profileFilter, self, setParameterDefaults, shell, tclcmd, traceFilter,
|
Instproc Detail |
Slash method is a recursive method that is used to traverse the Node tree. Example: set node [ ::xox::Node new ] $node addNode [ ::xox::Node new ] set subNode [ $node / Node ] Slash uses the nodeNames of the nodes instead of the object handles. Thus meaningful nodeNames can be given to the nodes. The slash method will throw an error if it does not find a node with the correct nodeName.
nodeName
args
::xox::Node instproc / {nodeName args} { regsub -all { } $nodeName {_} nodeName if { [ llength $args ] == 0 } { if { ! [ Object isobject [ my childName $nodeName ] ] } { error "Did not find $nodeName in [ my path ]\n[ my stackTrace ]" } return [ my childName $nodeName ] } if { ! [ Object isobject [ my childName $nodeName ] ] } { error "Did not find $nodeName in [ my path ]\n[ my stackTrace ]" } return [ eval {[ my childName $nodeName]} $args ] }
Adds a node as a child of this node and will produce a unique name among the children of this node.
node
::xox::Node instproc addAutoNameNode {node} { set nodeName [ $node getNodeName ] if { ![ Object isobject [ my childName $nodeName ] ] } { return [ my addNode $node ] } set nodeName [ my nextName [ $node getNodeName ] ] $node nodeName $nodeName return [ my addNode $node ] }
Used internally.
node
::xox::Node instproc addAutoNameNodeNoConfigureNode {node} { set nodeName [ $node getNodeName ] if { ![ Object isobject [ my childName $nodeName ] ] } { return [ my addNodeNoConfigureNode $node ] } set nodeName [ my nextName [ $node getNodeName ] ] $node nodeName $nodeName return [ my addNodeNoConfigureNode $node ] }
Adds a node as a child of this node. The name of the node to be added must be unique among the children of this node.
node
::xox::Node instproc addNode {node} { set node [ my addNodeNoConfigureNode $node ] $node configureNode return $node }
Used internally.
node
::xox::Node instproc addNodeNoConfigureNode {node} { set nodeName [ $node getNodeName ] set childName [ my childName $nodeName ] if { [ Object isobject $childName ] } { if { "$node" != "$childName" } { error "[ my path ] already contains an node named $nodeName\n[my stackTrace ]" } } $node move $childName $childName setParentNode [ self ] return $childName }
nodeName
::xox::Node instproc childName {nodeName} { set nodeName [ my fixedName $nodeName ] return "[ self ]::${nodeName}" }
Deprecated. No replacement.
::xox::Node instproc cleanUpNode {} { }
Allows a node to configure itself when added to the node tree. configureNode is called by addNode or addAutoNameNode and allows a node to lookup information on the tree or change the tree in some way.
::xox::Node instproc configureNode {} { #override this to configure the node when #added to the node tree. }
node
::xox::Node instproc copyNewNode {node} { set name [ namespace tail [ $node info class ] ] set childName [ my childName $name ] if { ! [ Object isobject $childName ] } { return [ my copyNodeInternal $name $node ] } set autoname [ my autoname $name ] return [ my copyNodeInternal $autoname $node ] }
node
::xox::Node instproc copyNode {node} { set nodeName [ $node getNodeName ] return [ my copyNodeInternal $nodeName $node ] }
name
node
::xox::Node instproc copyNodeInternal {name node} { set childName [ my childName $name ] if { [ Object isobject $childName ] } { if { "$node" != "$childName" } { error "[ self ] already contains an node named $name\n[my stackTrace ]" } } $node copy $childName $childName setParentNode [ self ] return $childName }
Creates a new child of this node that is a new instance of class using initialization arguments args.
class
args
::xox::Node instproc createAutoNamedChild {class args} { return [ my createAutoNamedChildInternal $class $args ] }
class
createArgs
::xox::Node instproc createAutoNamedChildInternal {class createArgs} { #my debug $createArgs set name [ namespace tail $class ] if { ! [ Object isobject [ self ]::${name} ] } { return [ my createChildInternal $name $class $createArgs ] } set autoname [ my autoname $name ] return [ my createChildInternal $autoname $class $createArgs ] }
Create a new object as a child of this element.
name
class
args
::xox::Node instproc createChild {name class args} { return [ my createChildInternal $name $class $args ] }
name
class
createArgs
::xox::Node instproc createChildInternal {name class createArgs} { regsub -all { } $name {_} fixedName set child [ my childName $fixedName ] if [ Object isobject $child ] { error "$child has already been created." } #my debug "$name $class $createArgs" eval [ list $class create $child -nodeName $name ] $createArgs $child configureNode return $child }
Better name for createAutoNamedChild
class
args
::xox::Node instproc createNewChild {class args} { return [ my createAutoNamedChildInternal $class $args ] }
Returns a formatted string of all the data on this Node. This is used for debugging the data on this Node. See Also: ::xox::Debugging debug
tabs
- optional, default value: ""
::xox::Node instproc dumpData {{tabs ""}} { set buffer "" foreach var [ my info vars ] { if [ my array exists $var ] { append buffer "$tabs$var: [ my array get $var ]\n" } else { append buffer "$tabs$var: [ my set $var ]\n" } } return $buffer }
Returns a formatted string representation of all the data held in this sub tree. This is used for debugging the structure and data on the sub tree. See Also: ::xox::Debugging debug
tabs
- optional, default value: ""
::xox::Node instproc dumpTreeData {{tabs ""}} { set buffer "\n$tabs[ self ] ([ my info class ])\n" append buffer [ my dumpData $tabs ] foreach node [ my nodes ] { append buffer [ $node dumpTreeData "$tabs\t" ] } return $buffer }
Finds the root of the node-tree where this node lives.
::xox::Node instproc findRoot {} { set current [ self ] while { [ Object isobject [ $current info parent ] ] } { set current [ $current info parent ] } return $current }
name
::xox::Node instproc fixedName {name} { return [ regsub -all { } $name {_} ] }
Returns a list of all nodes that exist in the sub-tree starting with this node.
::xox::Node instproc getAllSubNodes {} { set subNodes [ my nodes ] foreach node [ my nodes ] { set subNodes [ concat $subNodes [ $node getAllSubNodes ] ] } return $subNodes }
Gets a child of this node that has the nodeName given. Returns "" if no child is found with nodeName.
nodeName
::xox::Node instproc getNode {nodeName} { if { [ Object isobject [ my childName $nodeName ] ] } { return [ my childName $nodeName ] } return }
::xox::Node instproc getNodeName {} { my instvar nodeName if [ my exists nodeName ] { return $nodeName } my nodeNameFromClass }
Checks for a child with nodeName under this node. Returns 1 - if found. Returns 0 - if not found.
nodeName
::xox::Node instproc hasNode {nodeName} { if { [ Object isobject [ my childName $nodeName ] ] } { return 1 } return 0 }
Produces the next unique nodeName among the children of this node.
nodeName
::xox::Node instproc nextName {nodeName} { if {! [ Object isobject [ my childName $nodeName ] ] } { return $nodeName } while { [ Object isobject [ my childName $nodeName ] ] } { if [ regexp {(.*?)_(\d+)$} $nodeName dummy text number ] { set nodeName "${text}_[expr {$number + 1}]" } else { set nodeName "${nodeName}_0" } } return $nodeName }
Create a nodeName from the nodes's class. This is used if the nodeName is not yet set.
::xox::Node instproc nodeNameFromClass {} { if { ![ my exists nodeName ] } { return [ namespace tail [ my info class ] ] } return [ my nodeName ] }
Returns a list of nodes that are children of this node.
::xox::Node instproc nodes {} { return [ my info children ] }
::xox::Node instproc parentNode {} { return [ my info parent ] }
Path returns the nodeNames of the nodes from the current node to the root of the tree. The path is return in slash method format. $node path Root / Node / SubNode / ThisNode
::xox::Node instproc path {} { set current [ self ] set path "" set path [ linsert $path 0 [ $current getNodeName ] ] while { [ Object isobject [ $current info parent ] ] } { set current [ $current info parent ] set path [ linsert $path 0 [ $current getNodeName ] / ] } return $path }
Sets the parent node for this node.
node
::xox::Node instproc setParentNode {node} { }
Returns a formatted string that displays the tree node names in this subtree. This is useful for debugging the tree structure. See Also: ::xox::Debugging debug
tabs
- optional, default value: ""
::xox::Node instproc treeView {{tabs ""}} { set buffer "$tabs[ my name ]\n" foreach node [ my nodes ] { append buffer [ $node treeView "$tabs\t" ] } return $buffer }