2012-06-24 10:44:24 +00:00
< ? php
2012-07-08 16:11:25 +00:00
abstract class Parentum extends Node {
2012-06-25 13:03:14 +00:00
/*---------------------------
This class allows external access to the child - node list .
Use the NodeIterator to iterate through the list since
the numeric array keys might have gaps due to node removals !
2012-07-01 18:04:01 +00:00
Once init () has been called , an AVLTree is used to support the
functions removeChild () and findChild () . init () must be called
before adding any nodes !
2012-06-25 13:03:14 +00:00
---------------------------*/
2012-07-08 16:11:25 +00:00
protected $nodes ;
2012-07-01 18:04:01 +00:00
2012-07-08 16:11:25 +00:00
function Parentum () {
parent :: __construct ();
$this -> nodes = new DLL (); // Doubly Linked List
2012-07-01 18:04:01 +00:00
}
2012-06-25 13:03:14 +00:00
2012-07-01 18:04:01 +00:00
abstract protected function makeChild ( $args ); // overwriteable child generator; allows to define child type (eg.: admin classes that inherit from base class)
2012-06-25 13:03:14 +00:00
2012-07-08 16:11:25 +00:00
function isEmpty () {
return $this -> nodes -> isEmpty ();
2012-06-25 13:03:14 +00:00
}
2012-07-09 17:10:44 +00:00
function addChild ( $data , $b = null ) {
$this -> nodes -> addNode ( $data , $b );
2012-06-25 13:03:14 +00:00
}
2012-07-08 16:11:25 +00:00
function removeChild ( $id ) {
$this -> nodes -> removeNode ( $id );
2012-06-25 13:03:14 +00:00
}
2012-08-20 15:41:46 +00:00
function getChildByID ( $id ) { // returns a DLL node
2012-07-08 16:11:25 +00:00
return $this -> nodes -> findNode ( $id );
2012-06-25 13:03:14 +00:00
}
2012-08-20 15:41:46 +00:00
function getChildDataByID ( $id ) { // returns the actual content of the found DLL node
2012-07-08 16:11:25 +00:00
$tmp = $this -> getChildByID ( $id );
if ( $tmp != null ) {
return $tmp -> data ;
2012-06-25 13:03:14 +00:00
}
return null ;
}
2012-07-08 16:11:25 +00:00
function getIterator () {
return $this -> nodes -> getIterator ();
2012-06-25 13:03:14 +00:00
}
2012-06-24 10:44:24 +00:00
}
?>