Solstice::Tree - A basic tree object.


Solstice documentation  | view source Contained in the Solstice distribution.

Index


NAME

Top

Solstice::Tree - A basic tree object.

SYNOPSIS

Top

  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

Top

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

_setParent($parent, $position)

Sets the parent of a child

Modules Used

List (List).

AUTHOR

Top

Catalyst Group, <catalyst@u.washington.edu>

VERSION

Top

$Revision: 2412 $

COPYRIGHT

Top


Solstice documentation  | view source Contained in the Solstice distribution.