/**
* A general list class
*
- * @author Roland Haeder <webmaster@ship-simu.org>
+ * @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
+ * @link http://www.shipsimu.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
* @return $iteratorInstance An instance of a Iterator class
*/
public function getIterator () {
- // Prepare a default iterator
- $iteratorInstance = ObjectFactory::createObjectByConfiguredName('default_iterator_class', array($this));
+ // Get iterator from here
+ $iteratorInstance = $this->getIteratorInstance();
+
+ // Is the instance set?
+ if (is_null($iteratorInstance)) {
+ // Prepare a default iterator
+ $iteratorInstance = ObjectFactory::createObjectByConfiguredName('default_iterator_class', array($this));
+
+ // Set it here
+ $this->setIteratorInstance($iteratorInstance);
+ } // END - if
// And return it
return $iteratorInstance;
}
/**
- * Checks wether the given group is set
+ * Checks whether the given group is set
*
* @param $groupName Group to check if found in list
- * @return $isset Wether the group is valid
+ * @return $isset Whether the group is valid
*/
public function isGroupSet ($groupName) {
- //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName);
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.': '.$groupName);
return isset($this->listGroups[$groupName]);
}
* @throws ListGroupAlreadyAddedException If the given group is already added
*/
public function addGroup ($groupName) {
- //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . ' - START');
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.': '.$groupName . ' - START');
// Is the group already added?
if ($this->isGroupSet($groupName)) {
// Throw the exception here
// Add the group which is a simple array
$this->listGroups[$groupName] = ObjectFactory::createObjectByConfiguredName('list_group_class');
- //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . ' - FINISHED');
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.': '.$groupName . ' - FINISHED');
}
/**
* Adds the given instance to list group and sub group
*
- * @param $groupName Group to add instance to
- * @param $subGroup Sub group to add instance to
- * @param $instance An instance of Visitable
+ * @param $groupName Group to add instance to
+ * @param $subGroup Sub group to add instance to
+ * @param $visitableInstance An instance of Visitable
* @return void
* @throws NoListGroupException If the given group is not found
*/
- public function addInstance ($groupName, $subGroup, Visitable $instance) {
- //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . '/' . $subGroup . ' - START');
+ public function addInstance ($groupName, $subGroup, Visitable $visitableInstance) {
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.': '.$groupName . '/' . $subGroup . ' - START');
// Is the group there?
if (!$this->isGroupSet($groupName)) {
// Throw the exception here
} // END - if
// Generate the hash
- $hash = $this->generateHash($groupName, $subGroup, $instance);
+ $hash = $this->generateHash($groupName, $subGroup, $visitableInstance);
// Now add it to the group list and hash it
$this->listGroups[$groupName]->addEntry($subGroup, $hash);
// Add the hash to the index
- $this->listIndex[] = $hash;
+ array_push($this->listIndex, $hash);
// Add the instance itself to the list
- $this->listEntries[$hash] = $instance;
- //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . '/' . $subGroup . ' - FINISHED');
+ $this->listEntries[$hash] = $visitableInstance;
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.': '.$groupName . '/' . $subGroup . ' - FINISHED');
}
/**
// Is the list entry set?
if ($this->isHashValid($hash)) {
// Add it
- $array[] = $this->listEntries[$hash];
+ array_push($array, $this->listEntries[$hash]);
//* DEBUG: */ print __METHOD__.": ADDED!\n";
} // END - if
} // END - foreach
* @throws NoListGroupException If the given group is not found
*/
public function addEntry ($groupName, $entry) {
- //* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - START');
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - START');
// Is the group already added?
if (!$this->isGroupSet($groupName)) {
// Throw the exception here
// Generate hash
$hash = $this->generateHash($groupName, $groupName, $entry);
- //* DEBUG: */ $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash);
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-LIST[' . __METHOD__ . ':' . __LINE__ . ']: groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash);
// Add the hash to the index
- $this->listIndex[] = $hash;
- //* DEBUG: */ print $groupName.'/'.count($this->listIndex).chr(10);
+ array_push($this->listIndex, $hash);
+ //* DEBUG: */ print $groupName.'/'.$this->count().chr(10);
// Now add the entry to the list
$this->listEntries[$hash] = $entry;
//* DEBUG: */ print $groupName.'/'.count($this->listEntries).chr(10);
- //* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - FINISHED');
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - FINISHED');
}
/**
* @throws NoListGroupException If the given group is not found
*/
public function removeEntry ($groupName, $entry) {
- //* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - START');
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - START');
// Is the group already added?
if (!$this->isGroupSet($groupName)) {
// Throw the exception here
// Generate hash
$hash = $this->generateHash($groupName, $groupName, $entry);
- //* DEBUG: */ $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash);
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-LIST[' . __METHOD__ . ':' . __LINE__ . ']: groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash);
// Remove it from the list ...
unset($this->listEntries[$hash]);
// ... and hash list as well
unset($this->listIndex[array_search($hash, $this->listIndex)]);
- //* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - FINISHED');
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - FINISHED');
}
/**
} elseif ((is_array($entry)) && (isset($entry['id']))) {
// Supported array found
$entry2 = crc32($entry['id']) . ':' . count($entry);
+ } elseif ((is_array($entry)) && (isset($entry[BasePool::SOCKET_ARRAY_RESOURCE])) && (isset($entry[BasePool::SOCKET_ARRAY_CONN_TYPE]))) {
+ // Is a socket resource array
+ $entry2 = crc32($entry[BasePool::SOCKET_ARRAY_RESOURCE] . ':' . $entry[BasePool::SOCKET_ARRAY_CONN_TYPE]);
} else {
// Unsupported type detected
- $this->debugOutut('[' . __METHOD__ . ':' . __LINE__ . ']: entry type ' . gettype($entry) . ' is unsupported.');
+ self::createDebugInstance(__CLASS__)->debugOutput('BASE-LIST[' . __METHOD__ . ':' . __LINE__ . ']: Entry type ' . gettype($entry) . ' is unsupported.');
// @TODO Extend this somehow?
$entry2 = gettype($entry);
}
/**
- * Checks wether the given hash is valid
+ * Checks whether the given hash is valid
*
* @param $hash The hash we should validate
- * @return $isValid Wether the given hash is valid
+ * @return $isValid Whether the given hash is valid
*/
public final function isHashValid ($hash) {
// Check it
// Get an iterator
$iteratorInstance = $this->listGroups[$groupName]->getIterator();
+ // Rewind the iterator for this round
+ $iteratorInstance->rewind();
+
// Go through all entries
while ($iteratorInstance->valid()) {
// Get key
// ... and the final entry which is the stored instance
$entry = $this->getEntry($entryIndex);
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('LIST: Adding entry ' . $entry . ' ...');
+
// Add it to the list
$entries[$iteratorInstance->current()] = $entry;