* @version 0.0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ class BasePool extends BaseHubSystem implements Visitable { /** * A list of pool entries */ private $poolEntriesInstance = null; /** * Protected constructor * * @param $className Name of the class * @return void */ protected function __construct ($className) { // Call parent constructor parent::__construct($className); // Init the pool entries $this->poolEntriesInstance = ObjectFactory::createObjectByConfiguredName('pool_entries_list_class'); } /** * Getter for pool entries instance * * @return $poolEntriesInstance An instance for pool entries (list) */ public final function getPoolEntriesInstance () { return $this->poolEntriesInstance; } /** * Adds an instance to a pool segment * * @param $group Name of the pool group * @param $poolSegment Name of the pool segment * @param $instance An instance of a class we should add to the pool * @return void */ protected final function addInstance ($group, $poolName, Visitable $instance) { // Is the pool group there? if (!$this->getPoolEntriesInstance()->isGroupSet($group)) { // Create the missing pool group $this->getPoolEntriesInstance()->addGroup($group); } // END - if // Add it to given pool group $this->getPoolEntriesInstance()->addInstance($group, $poolName, $instance); } /** * Adds an entry to the pool * * @param $poolEntry The new pool entry we should add * @return void */ protected final function addPoolEntry ($poolEntry) { $this->getPoolEntriesInstance()->addEntry('pool', $poolEntry); } /** * Accepts the visitor to process the visit "request" * * @param $visitorInstance An instance of a Visitor class * @return void */ public function accept (Visitor $visitorInstance) { // Debug message //* NOISY-DEBUG: */ $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - START'); // Visit this pool $visitorInstance->visitPool($this); // Get a new iterator instance $iteratorInstance = ObjectFactory::createObjectByConfiguredName($visitorInstance->getVisitorMode() . '_pool_iterator_class', array($this->getPoolEntriesInstance())); // Reset the counter $iteratorInstance->rewind(); // Visit all registered entries while ($iteratorInstance->valid()) { // Get current entry $poolEntry = $iteratorInstance->current(); // Is this entry visitable? if ($poolEntry instanceof Visitable) { // Visit this entry as well $poolEntry->accept($visitorInstance); } else { // Cannot visit this entry $this->partialStub('Pool entry with key ' . $iteratorInstance->key() . ' has improper type ' . gettype($poolEntry) . '.'); } // Advance to next entry $iteratorInstance->next(); } // END - while // Debug message //* NOISY-DEBUG: */ $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - FINISHED'); } /** * Gets the array from specified list * * @param $list The list identifier we should return * @return $array The requested array */ protected final function getArrayFromList ($list) { // Get the array $array = $this->getPoolEntriesInstance()->getArrayFromList($list); // Return it return $array; } } // [EOF] ?>