NAME
Solstice::Tree - A basic tree object.
SYNOPSIS
use Tree;
my $tree = new Tree;
my $child1 = new Tree;
$tree->addChild($child1);
$count = $tree->getChildCount();
my @children = $tree->getChildren();
my $child = $tree->getChild(0);
my $parent = $tree->getParent();
my $child2 = new Tree;
$tree->addChild($child2);
$tree->removeChild(1);
my $boolean = $tree->isRoot();
my $boolean = $tree->isLeaf();
my $uniquelabelstring = $tree->getLabel();
$child1->setValue("sample text");
$child2->setValue(\$objectref);
$tree->setValue("root");
$tree->destroy();
DESCRIPTION
Provides a set of functionality for manipulating trees.
Export
No symbols exported.
Methods
- new()
-
Constructor, creates a new tree object.
- getParent()
-
Returns the parent of a child
- getChildren()
-
Returns an array of all children
- childExists($position)
-
Returns TRUE if a child exists at the passed $position, FALSE otherwise
- addChild($child [, $position])
-
This will add a child to the tree, at optional $position. Returns 1 on success, and thanks to List, dies on error.
- removeChild($position, $return_tree)
-
This will remove a child, taking a flag on whether to return the tree that the child is the root of. If the tree is not wanted, it will be destroyed.
- addChildren($list)
- removeChildren()
-
Remove all children from this tree
- moveChild($oldposition, $newposition)
-
This will move a child from one position to another in the tree. Does not wrap, i will return 0 and do nothing if the old or new position is out of range. Fixes positions, then uses List operations. Returns 1 on success.
- destroy()
-
Recursively destroys a tree, depth-first.
- getChildCount()
-
Returns the size of the children list.
- getTotalChildCount()
-
Returns the size of all children recursively down the list.
- getChild($position)
-
Returns the child at position n in the list.
- getPosition()
-
Returns the position of the node, relative to it's siblings.
- getRoot()
-
Recursively crawls up the tree until it hits the root, then returns it.
- isRoot()
-
Returns a boolean describing whether the current tree node is the root.
- isLeaf()
-
Returns a boolean describing whether the current tree node is a leaf.
- isFirstChild()
-
Returns a boolean describing whether the current tree node is the first child.
- isLastChild()
-
Returns a boolean describing whether the current tree node is the last child.
- getLabel()
-
Recursively goes up the tree and gets a unique text string
- setValue($value)
-
Sets the 'value' of this node.
- getValue()
-
Gets the 'value' of this node.
Private Methods
Modules Used
List.
AUTHOR
Catalyst Group, <catalyst@u.washington.edu>
VERSION
$Revision: 2412 $
COPYRIGHT
Copyright 1998-2007 Office of Learning Technologies, University of Washington
Licensed under the Educational Community License, Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.opensource.org/licenses/ecl1.php
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.