1<?php
2
3/*
4	This file is part of ActiveLink PHP XML Package (www.active-link.com).
5	Copyright (c) 2002-2004 by Zurab Davitiani
6
7	You can contact the author of this software via E-mail at
8	hattrick@mailcan.com
9
10	ActiveLink PHP XML Package is free software; you can redistribute it and/or modify
11	it under the terms of the GNU Lesser General Public License as published by
12	the Free Software Foundation; either version 2.1 of the License, or
13	(at your option) any later version.
14
15	ActiveLink PHP XML Package is distributed in the hope that it will be useful,
16	but WITHOUT ANY WARRANTY; without even the implied warranty of
17	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18	GNU Lesser General Public License for more details.
19
20	You should have received a copy of the GNU Lesser General Public License
21	along with ActiveLink PHP XML Package; if not, write to the Free Software
22	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23*/
24
25/**
26  *	Tree class provides a base for Tree-Branch-Leaf trio
27  *	@class		Tree
28  *	@package	org.active-link.xml
29  *	@author		Zurab Davitiani
30  *	@version	0.4.0
31  *	@see		Branch, Leaf
32  */
33
34class Tree {
35
36	// protected variables
37	var $nodes;
38	var $id = 0;
39
40	/**
41	  *	Constructor for the object
42	  *	@method		Tree
43	  *	@returns	none
44	  */
45	function Tree() {
46		$this->nodes = array();
47	}
48
49	/**
50	  *	Adds given node to the Tree
51	  *	@method		addNode
52	  *	@param		mixed id
53	  *	@param		mixed node
54	  *	@returns	true if successful, false otherwise
55	  */
56	function addNode($id, $node) {
57		$success = true;
58		if($id == -1)
59			$this->nodes[] = $node;
60		else
61			if(isset($this->nodes[$id]))
62				$success = false;
63			else
64				$this->nodes[$id] = $node;
65		return $success;
66	}
67
68	/**
69	  *	Removes all nodes
70	  *	@method		removeAllNodes
71	  *	@returns	none
72	  */
73	function removeAllNodes () {
74		$this->nodes = array();
75	}
76
77	/**
78	  *	Removes specified node from the Tree
79	  *	@method		removeNode
80	  *	@param		mixed id
81	  *	@returns	true if successful, false otherwise
82	  */
83	function removeNode($id) {
84		$success = false;
85		if(isset($this->nodes[$id])) {
86			unset($this->nodes[$id]);
87			$success = true;
88		}
89		return $success;
90	}
91
92}
93
94?>
95