OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / include / mos / class / tree.php
1 <?php
2 /**
3  * @version             $Id:tree.php 6961 2007-03-15 16:06:53Z tcp $
4  * @package             Joomla.Framework
5  * @subpackage  Base
6  * @copyright   Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
7  * @license             GNU/GPL, see LICENSE.php
8  * Joomla! is free software. This version may have been modified pursuant to the
9  * GNU General Public License, and as distributed it includes or is derivative
10  * of works licensed under the GNU General Public License or other free or open
11  * source software licenses. See COPYRIGHT.php for copyright notices and
12  * details.
13  */
14
15 // Check to ensure this file is within the rest of the framework
16 //defined('JPATH_BASE') or die();
17
18 /**
19  * Tree Class.
20  *
21  * @package     Joomla.Framework
22  * @subpackage  Base
23  * @since               1.5
24  */
25 class JTree extends JObject
26 {
27         /**
28          * Root node
29          */
30         var $_root = null;
31
32         /**
33          * Current working node
34          */
35         var $_current = null;
36
37         function __construct()
38         {
39                 $this->_root = new JNode('ROOT');
40                 $this->_current = & $this->_root;
41         }
42
43         function addChild(&$node, $setCurrent = false)
44         {
45                 $this->_current->addChild($node);
46                 if ($setCurrent) {
47                         $this->_current =& $node;
48                 }
49         }
50
51         function getParent()
52         {
53                 $this->_current =& $this->_current->getParent();
54         }
55
56         function reset()
57         {
58                 $this->_current =& $this->_root;
59         }
60 }
61
62 /**
63  * Tree Node Class.
64  *
65  * @package     Joomla.Framework
66  * @subpackage  Base
67  * @since               1.5
68  */
69 class JNode extends JObject
70 {
71         /**
72          * Parent node
73          */
74         var $_parent = null;
75
76         /**
77          * Array of Children
78          */
79         var $_children = array();
80
81         function __construct()
82         {
83                 return true;
84         }
85
86         function addChild( &$node )
87         {
88                 $node->setParent($this);
89                 $this->_children[] = & $node;
90         }
91
92         function &getParent()
93         {
94                 return $this->_parent;
95         }
96
97         function setParent( &$node )
98         {
99                 $this->_parent = & $node;
100         }
101
102         function hasChildren()
103         {
104                 return count($this->_children);
105         }
106
107         function &getChildren()
108         {
109                 return $this->_children;
110         }
111 }