::xox
Class Node

Heritage:
::xotcl::Object
Direct Known Subclasses:
::xounit::TestCase, ::xounit::TestResult, ::xounit::TestSuite, ::xox::Environment,

Associated Test:
::xox::test::TestNode

Class Node
superclass ::xotcl::Object,
Nodes are arranged in a tree structure
Variables
NameDefault ValueClassComment
nodeName    ::xox::Node
 
 
Methods
NameComment
/ {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

/

Description:
 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.
Arguments:
Code:
  ::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 ]
   
}

addAutoNameNode

Description:
 Adds a node as a child of this node and will produce
 a unique name among the children of this node.
Arguments:
Code:
  ::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 ]
   
}

addAutoNameNodeNoConfigureNode

Description:
 Used internally.
Arguments:
Code:
  ::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 ]
   
}

addNode

Description:
 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.
Arguments:
Code:
  ::xox::Node instproc addNode {node}  {
   

       set node [ my addNodeNoConfigureNode $node ]

       $node configureNode
       return $node
   
}

addNodeNoConfigureNode

Description:
 Used internally.
Arguments:
Code:
  ::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
   
}

childName

Description:
 
Arguments:
Code:
  ::xox::Node instproc childName {nodeName}  {
   

       set nodeName [ my fixedName $nodeName ]

       return "[ self ]::${nodeName}"
   
}

cleanUpNode

Description:
 Deprecated. No replacement.
Code:
  ::xox::Node instproc cleanUpNode {}  {
   

   
}

configureNode

Description:
 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.
Code:
  ::xox::Node instproc configureNode {}  {
   

        #override this to configure the node when 
        #added to the node tree.
   
}

copyNewNode

Description:
 
Arguments:
Code:
  ::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 ]
   
}

copyNode

Description:
 
Arguments:
Code:
  ::xox::Node instproc copyNode {node}  {
   

       set nodeName [ $node getNodeName ]

       return [ my copyNodeInternal $nodeName $node ]
   
}

copyNodeInternal

Description:
 
Arguments:
Code:
  ::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
   
}

createAutoNamedChild

Description:
 Creates a new child of this node that is a new
 instance of class using initialization arguments args.
Arguments:
Code:
  ::xox::Node instproc createAutoNamedChild {class args}  {
   

       return [ my createAutoNamedChildInternal $class $args ]
   
}

createAutoNamedChildInternal

Description:
 
Arguments:
Code:
  ::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 ]
   
}

createChild

Description:
 Create a new object as a child of this element.
Arguments:
Code:
  ::xox::Node instproc createChild {name class args}  {
   

       return [ my createChildInternal $name $class $args ] 
   
}

createChildInternal

Description:
 
Arguments:
Code:
  ::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
   
}

createNewChild

Description:
 Better name for createAutoNamedChild
Arguments:
Code:
  ::xox::Node instproc createNewChild {class args}  {
   

       return [ my createAutoNamedChildInternal $class $args ]
   
}

dumpData

Description:
 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
Arguments:
Code:
  ::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
   
}

dumpTreeData

Description:
 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
Arguments:
Code:
  ::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
   
}

findRoot

Description:
 Finds the root of the node-tree where this node lives.
Code:
  ::xox::Node instproc findRoot {}  {
   

        set current [ self ]

        while { [ Object isobject [ $current info parent ] ] } {

            set current [ $current info parent ]
        }

        return $current
   
}

fixedName

Description:
 
Arguments:
Code:
  ::xox::Node instproc fixedName {name}  {
   

       return [ regsub -all { } $name {_} ]
   
}

getAllSubNodes

Description:
 Returns a list of all nodes that exist in the sub-tree starting
 with this node.
Code:
  ::xox::Node instproc getAllSubNodes {}  {
   

       set subNodes [ my nodes ]

       foreach node [ my nodes ] {

           set subNodes [ concat $subNodes [ $node getAllSubNodes ] ]

       }

       return $subNodes
   
}

getNode

Description:
 Gets a child of this node that has the nodeName given.
 Returns "" if no child is found with nodeName.
Arguments:
Code:
  ::xox::Node instproc getNode {nodeName}  {
   

       if { [ Object isobject [ my childName $nodeName ] ] } { 
           return [ my childName $nodeName ]
       }

       return 
   
}

getNodeName

Description:
 
Code:
  ::xox::Node instproc getNodeName {}  {
   

       my instvar nodeName

       if [ my exists nodeName ] {

           return $nodeName
       }

       my nodeNameFromClass 
   
}

hasNode

Description:
 Checks for a child with nodeName under this node.

 Returns 1 - if found.
 Returns 0 - if not found.
Arguments:
Code:
  ::xox::Node instproc hasNode {nodeName}  {
   

       if { [ Object isobject [ my childName $nodeName ] ] } { 
           return 1
       }

       return 0
   
}

nextName

Description:
 Produces the next unique nodeName among the children
 of this node.
Arguments:
Code:
  ::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
   
}

nodeNameFromClass

Description:
 Create a nodeName from the nodes's class.  
 This is used if the nodeName is not yet set.
Code:
  ::xox::Node instproc nodeNameFromClass {}  {
   

        if { ![ my exists nodeName ] } {
            return [ namespace tail [ my info class ] ]
        }
        return [ my nodeName ]
   
}

nodes

Description:
 Returns a list of nodes that are children of this node.
Code:
  ::xox::Node instproc nodes {}  {
   

       return [ my info children ]
   
}

parentNode

Description:
 
Code:
  ::xox::Node instproc parentNode {}  {
   

       return [ my info parent ]
   
}

path

Description:
 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
Code:
  ::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
   
}

setParentNode

Description:
 Sets the parent node for this node.
Arguments:
Code:
  ::xox::Node instproc setParentNode {node}  {
   

   
}

treeView

Description:
 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
Arguments:
Code:
  ::xox::Node instproc treeView {{tabs ""}}  {
   

       set buffer "$tabs[ my name ]\n"
       foreach node [ my nodes ] {
           append buffer [ $node treeView "$tabs\t" ]
       }

       return $buffer
   
}