]> git.mxchange.org Git - hub.git/blob - application/hub/main/pools/class_BasePool.php
Removed old-lost comments, moved two class instances around:
[hub.git] / application / hub / main / pools / class_BasePool.php
1 <?php
2 /**
3  * A general pool class
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24 class BasePool extends BaseHubSystem implements Visitable {
25         /**
26          * A list of pool entries
27          */
28         private $poolEntriesInstance = null;
29
30         /**
31          * Protected constructor
32          *
33          * @param       $className      Name of the class
34          * @return      void
35          */
36         protected function __construct ($className) {
37                 // Call parent constructor
38                 parent::__construct($className);
39
40                 // Init the pool entries
41                 $this->poolEntriesInstance = ObjectFactory::createObjectByConfiguredName('pool_entries_list_class');
42         }
43
44         /**
45          * Getter for pool entries instance
46          *
47          * @return      $poolEntriesInstance    An instance for pool entries (list)
48          */
49         public final function getPoolEntriesInstance () {
50                 return $this->poolEntriesInstance;
51         }
52
53         /**
54          * Adds an instance to a pool segment
55          *
56          * @param       $group                  Name of the pool group
57          * @param       $poolSegment    Name of the pool segment
58          * @param       $instance               An instance of a class we should add to the pool
59          * @return      void
60          */
61         protected final function addInstance ($group, $poolName, Visitable $instance) {
62                 // Is the pool group there?
63                 if (!$this->getPoolEntriesInstance()->isGroupSet($group)) {
64                         // Create the missing pool group
65                         $this->getPoolEntriesInstance()->addGroup($group);
66                 } // END - if
67
68                 // Add it to given pool group
69                 $this->getPoolEntriesInstance()->addInstance($group, $poolName, $instance);
70         }
71
72         /**
73          * Adds an entry to the pool
74          *
75          * @param       $poolEntry      The new pool entry we should add
76          * @return      void
77          */
78         protected final function addPoolEntry ($poolEntry) {
79                 $this->getPoolEntriesInstance()->addEntry('pool', $poolEntry);
80         }
81
82         /**
83          * Accepts the visitor to process the visit "request"
84          *
85          * @param       $visitorInstance        An instance of a Visitor class
86          * @return      void
87          */
88         public function accept (Visitor $visitorInstance) {
89                 // Debug message
90                 //* NOISY-DEBUG: */ $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - START');
91
92                 // Visit this pool
93                 $visitorInstance->visitPool($this);
94
95                 // Get a new iterator instance
96                 $iteratorInstance = ObjectFactory::createObjectByConfiguredName($visitorInstance->getVisitorMode() . '_pool_iterator_class', array($this->getPoolEntriesInstance()));
97
98                 // Reset the counter
99                 $iteratorInstance->rewind();
100
101                 // Visit all registered entries
102                 while ($iteratorInstance->valid()) {
103                         // Get current entry
104                         $poolEntry = $iteratorInstance->current();
105
106                         // Is this entry visitable?
107                         if ($poolEntry instanceof Visitable) {
108                                 // Visit this entry as well
109                                 $poolEntry->accept($visitorInstance);
110                         } else {
111                                 // Cannot visit this entry
112                                 $this->partialStub('Pool entry with key ' . $iteratorInstance->key() . ' has improper type ' . gettype($poolEntry) . '.');
113                         }
114
115                         // Advance to next entry
116                         $iteratorInstance->next();
117                 } // END - while
118
119                 // Debug message
120                 //* NOISY-DEBUG: */ $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - FINISHED');
121         }
122
123         /**
124          * Gets the array from specified list
125          *
126          * @param       $list   The list identifier we should return
127          * @return      $array  The requested array
128          */
129         protected final function getArrayFromList ($list) {
130                 // Get the array
131                 $array = $this->getPoolEntriesInstance()->getArrayFromList($list);
132
133                 // Return it
134                 return $array;
135         }
136 }
137
138 // [EOF]
139 ?>