5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 * Getter for pool entries instance
47 * @return $poolEntriesInstance An instance for pool entries (list)
49 public final function getPoolEntriesInstance () {
50 return $this->poolEntriesInstance;
54 * Adds an instance to a pool segment
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
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);
68 // Add it to given pool group
69 $this->getPoolEntriesInstance()->addInstance($group, $poolName, $instance);
73 * Adds an entry to the pool
75 * @param $poolEntry The new pool entry we should add
78 protected final function addPoolEntry ($poolEntry) {
79 $this->getPoolEntriesInstance()->addEntry('generic', $poolEntry);
83 * Accepts the visitor to process the visit "request"
85 * @param $visitorInstance An instance of a Visitor class
88 public function accept (Visitor $visitorInstance) {
90 //* DEBUG: */ $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - START');
93 $visitorInstance->visitPool($this);
95 // Get a new iterator instance
96 $iteratorInstance = ObjectFactory::createObjectByConfiguredName($visitorInstance->getVisitorMode() . '_pool_iterator_class', array($this->getPoolEntriesInstance()));
99 $iteratorInstance->rewind();
101 // Visit all registered entries
102 while ($iteratorInstance->valid()) {
104 $poolEntry = $iteratorInstance->current();
106 // Is this entry visitable?
107 if ($poolEntry instanceof Visitable) {
108 // Visit this entry as well
109 $poolEntry->accept($visitorInstance);
111 // Cannot visit this entry
112 $this->partialStub('Pool entry with key ' . $iteratorInstance->key() . ' has improper type ' . gettype($poolEntry) . '.');
115 // Advance to next entry
116 $iteratorInstance->next();
120 //* DEBUG: */ $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - FINISHED');
124 * Gets the array from specified list
126 * @param $list The list identifier we should return
127 * @return $array The requested array
129 protected final function getArrayFromList ($list) {
131 $array = $this->getPoolEntriesInstance()->getArrayFromList($list);