5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
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.
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.
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/>.
24 class BasePool extends BaseHubSystem implements Visitable {
26 * A list of pool entries
28 private $poolEntriesInstance = null;
31 * Protected constructor
33 * @param $className Name of the class
36 protected function __construct ($className) {
37 // Call parent constructor
38 parent::__construct($className);
40 // Init the pool entries
41 $this->poolEntriesInstance = ObjectFactory::createObjectByConfiguredName('pool_entries_list_class');
45 * Adds an instance to a pool segment
47 * @param $group Name of the pool group
48 * @param $poolSegment Name of the pool segment
49 * @param $instance An instance of a class we should add to the pool
52 protected final function addInstance ($group, $poolName, Visitable $instance) {
53 // Is the pool group there?
54 if (!$this->poolEntriesInstance->isGroupSet($group)) {
55 // Create the missing pool group
56 $this->poolEntriesInstance->addGroup($group);
59 // Add it to given pool group
60 $this->poolEntriesInstance->addInstance($group, $poolName, $instance);
64 * Adds an entry to the pool
66 * @param $poolEntry The new pool entry we should add
69 protected final function addPoolEntry ($poolEntry) {
70 $this->poolEntriesInstance->addEntry('generic', $poolEntry);
74 * Accepts the visitor to rpocess the visit "request"
76 * @param $visitorInstance An instance of a Visitor class
79 public function accept (Visitor $visitorInstance) {
81 //* DEBUG: */ $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - START');
84 $visitorInstance->visitPool($this);
86 // Get a new iterator instance
87 $iteratorInstance = ObjectFactory::createObjectByConfiguredName($visitorInstance->getVisitorMode() . '_pool_iterator_class', array($this->poolEntriesInstance));
90 $iteratorInstance->rewind();
92 // Visit all registered entries
93 while ($iteratorInstance->valid()) {
95 $poolEntry = $iteratorInstance->current();
97 // Is this entry visitable?
98 if ($poolEntry instanceof Visitable) {
99 // Visit this entry as well
100 print __METHOD__.':'.$poolEntry."\n";
101 $poolEntry->accept($visitorInstance);
103 // Cannot visit this entry
104 $this->partialStub('Pool entry with key ' . $iteratorInstance->key() . ' has improper type ' . gettype($poolEntry) . '.');
107 // Advance to next entry
108 $iteratorInstance->next();
112 //* DEBUG: */ $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - FINISHED');