Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 15 Jul 2017 21:05:39 +0000 (23:05 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 15 Jul 2017 21:05:39 +0000 (23:05 +0200)
- added experimental (maybe not working) iterator for registries
- callbackInstance is now generic

Signed-off-by: Roland Häder <roland@mxchange.org>
13 files changed:
framework/config/class_FrameworkConfiguration.php
framework/main/classes/class_BaseFrameworkSystem.php
framework/main/classes/iterator/class_BaseIterator.php
framework/main/classes/iterator/registry/class_RegistryIterator.php
framework/main/classes/lists/class_BaseList.php
framework/main/classes/registry/class_BaseRegistry.php
framework/main/interfaces/class_FrameworkInterface.php
framework/main/interfaces/iterator/class_SeekableWritableFileIterator.php [deleted file]
framework/main/interfaces/iterator/file/.htaccess [new file with mode: 0644]
framework/main/interfaces/iterator/file/class_SeekableWritableFileIterator.php [new file with mode: 0644]
framework/main/interfaces/iterator/registry/.htaccess [new file with mode: 0644]
framework/main/interfaces/iterator/registry/class_IteratableRegistry.php [new file with mode: 0644]
framework/main/interfaces/registry/class_Register.php

index 15894ff..17c456e 100644 (file)
@@ -49,6 +49,11 @@ class FrameworkConfiguration implements Registerable {
         */
        private static $configInstance = NULL;
 
+       /**
+        * Call-back instance (unused)
+        */
+       private $callbackInstance = NULL;
+
        // Some constants for the configuration system
        const EXCEPTION_CONFIG_KEY_IS_EMPTY           = 0x130;
        const EXCEPTION_CONFIG_KEY_WAS_NOT_FOUND      = 0x131;
@@ -446,4 +451,14 @@ class FrameworkConfiguration implements Registerable {
                return $equals;
        }
 
+       /**
+        * Setter for call-back instance
+        *
+        * @param       $callbackInstance       An instance of a FrameworkInterface class
+        * @return      void
+        */
+       public function setCallbackInstance (FrameworkInterface $callbackInstance) {
+               $this->callbackInstance = $callbackInstance;
+       }
+
 }
index 69bcba9..322bd28 100644 (file)
@@ -263,6 +263,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        private $registryInstance = NULL;
 
        /**
+        * Call-back instance
+        */
+       private $callbackInstance = NULL;
+
+       /**
         * Thousands separator
         */
        private $thousands = '.'; // German
@@ -1552,6 +1557,25 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        }
 
        /**
+        * Setter for call-back instance
+        *
+        * @param       $callbackInstance       An instance of a FrameworkInterface class
+        * @return      void
+        */
+       public final function setCallbackInstance (FrameworkInterface $callbackInstance) {
+               $this->callbackInstance = $callbackInstance;
+       }
+
+       /**
+        * Getter for call-back instance
+        *
+        * @return      $callbackInstance       An instance of a FrameworkInterface class
+        */
+       protected final function getCallbackInstance () {
+               return $this->callbackInstance;
+       }
+
+       /**
         * Setter for command name
         *
         * @param       $commandName    Last validated command name
index a51da23..da5d648 100644 (file)
@@ -5,6 +5,9 @@ namespace CoreFramework\Iterator;
 // Import framework stuff
 use CoreFramework\Object\BaseFrameworkSystem;
 
+// Import SPL stuff
+use \Iterator;
+
 /**
  * A general iterator
  *
@@ -27,7 +30,7 @@ use CoreFramework\Object\BaseFrameworkSystem;
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-class BaseIterator extends BaseFrameworkSystem {
+abstract class BaseIterator extends BaseFrameworkSystem implements Iterator {
        /**
         * Protected constructor
         *
index 522ad93..66538f5 100644 (file)
@@ -3,11 +3,15 @@
 namespace CoreFramework\Iterator\Registry;
 
 // Import framework stuff
+use CoreFramework\Generic\FrameworkInterface;
+use CoreFramework\Generic\NullPointerException;
 use CoreFramework\Iterator\BaseIterator;
 use CoreFramework\Registry\Register;
+use CoreFramework\Registry\Registerable;
+use CoreFramework\Registry\Sub\SubRegistry;
 
 // Import SPL stuff
-use \Iterator;
+use \LogicException;
 
 /**
  * A Registry iterator
@@ -31,7 +35,22 @@ use \Iterator;
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-class RegistryIterator extends BaseIterator implements Iterator {
+class RegistryIterator extends BaseIterator implements IteratableRegistry {
+       /**
+        * All found registry keys
+        */
+       private $registryKeys = array();
+
+       /**
+        * Current array key
+        */
+       private $key = NULL;
+
+       /**
+        * Valid status (default: not valid)
+        */
+       private $valid = FALSE;
+
        /**
         * Protected constructor
         *
@@ -60,6 +79,121 @@ class RegistryIterator extends BaseIterator implements Iterator {
        }
 
        /**
+        * Initializes this iterator by scanning over the registry for all keys.
+        *
+        * @param       $callbackInstance       An instance of a FrameworkInterface class to call back (optional)
+        * @param       $criteriaKey            Criteria key (optional)
+        * @param       $criteriaMethod         Method to call back (optional)
+        * @return      void
+        * @throws      LogicException  If a registry entry does not implement Registerable
+        * @throws      NullPointerException    If criteriaKey or criteriaMethod is not set but a call-back instance is set
+        */
+       public function initIterator (FrameworkInterface $callbackInstance = NULL, $criteriaKey = NULL, $criteriaMethod = NULL) {
+               // Is the call-back instance set?
+               if ($callbackInstance instanceof FrameworkInterface) {
+                       // Then also criteria key and method name must be given
+                       if (is_null($criteriaKey)) {
+                               // Throw NPE
+                               throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+                       } elseif (is_null($criteriaMethod)) {
+                               // Throw NPE
+                               throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+                       }
+
+                       // Set all
+                       $iteratorInstance->setCallbackInstance($callbackInstance);
+                       $iteratorInstance->setCriteriaKey($criteriaKey);
+               } // END - if
+
+               // Get generic registry entries from it
+               $entries = $this->getRegistryInstance()->getGenericRegistry();
+
+               // Init registry keys array
+               $this->registryKeys['generic'] = array();
+
+               // Anything in there?
+               if (count($entries) > 0) {
+                       // Debugging:
+                       /* DEBUG-DIE: */ die(sprintf('[%s:%d]: entries=%s', __METHOD__, __LINE__, print_r($entries, TRUE)));
+               } // END - if
+
+               // Get instance registry entries from it
+               $entries = $this->getRegistryInstance()->getInstanceRegistry();
+
+               // Init registry keys array
+               $this->registryKeys['instance'] = array();
+
+               // Anything in there?
+               if (count($entries) > 0) {
+                       // Then run over all
+                       foreach ($entries as $key => $entry) {
+                               // Debug message
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('REGISTRY-ITERATOR[instance]: key=%s,entry[]=%s', $key, gettype($entry)));
+
+                               // Is it 'socket_registry' ?
+                               if ($key == 'socket_registry') {
+                                       // Skip this entry
+                                       continue;
+                               } // END - if
+
+                               // Is it an instance of a sub-registry?
+                               if ($entry instanceof SubRegistry) {
+                                       // Get iterator from this instance
+                                       $iteratorInstance = $entry->getIterator();
+
+                                       // Debugging:
+                                       //* DEBUG-DIE: */ die(sprintf('[%s:%d]: key=%s,iteratorInstance=%s', __METHOD__, __LINE__, $key, print_r($iteratorInstance, TRUE)));
+
+                                       // Get all keys
+                                       $keys = $iteratorInstance->getRegistryKeys();
+
+                                       // Should be there
+                                       if (!isset($keys['instance'])) {
+                                               // Should not happen
+                                               throw new LogicException(sprintf('key=%s,keys[instance] is not set.', $key));
+                                       } // END - if
+
+                                       // Add all sub-registry keys to this registry keys array
+                                       $this->registryKeys['instance'][$key] = $keys['instance'];
+
+                                       // Debug message
+                                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('REGISTRY-ITERATOR[instance]: key=%s,keys=%s', $key, print_r($this->registryKeys['instance'][$key], TRUE)));
+
+                                       // Skip below code
+                                       continue;
+                               } elseif (!($entry instanceof Registerable)) {
+                                       // Not registerable?!
+                                       throw new LogicException(sprintf('entry[]=%s does not implement Registerable.', gettype($entry)));
+                               } elseif (is_null($this->key)) {
+                                       // Debug message
+                                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('REGISTRY-ITERATOR[instance]: Setting key=%s ...', $key));
+
+                                       // Init key/valid
+                                       $this->key = $key;
+                                       $this->valid = TRUE;
+                               }
+
+                               // Debugging:
+                               //* DEBUG-DIE: */ die(sprintf('[%s:%d]: key=%s,entry=%s', __METHOD__, __LINE__, $key, print_r($entry, TRUE)));
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('REGISTRY-ITERATOR[instance]: key=%s,entry[]=%s - Adding ...', $key, gettype($entry)));
+
+                               // Add key to array
+                               $this->registryKeys['instance'][$key] = array();
+                       } // END - foreach
+               } // END - if
+       }
+
+       /**
+        * Getter for all registry keys (array)
+        *
+        * @return      $registryKeys   Registry keys
+        */
+       public final function getRegistryKeys () {
+               // Return it
+               return $this->registryKeys;
+       }
+
+       /**
         * Getter for current value from group or generic
         *
         * @return      $current        Current value in iteration
@@ -80,13 +214,8 @@ class RegistryIterator extends BaseIterator implements Iterator {
         * @return      $key    Current key in iteration
         */
        public function key () {
-               // Default is null
-               $key = null;
-
-               $this->partialStub('Please implement this method.');
-
                // Return it
-               return $key;
+               return $this->key;
        }
 
        /**
@@ -104,16 +233,18 @@ class RegistryIterator extends BaseIterator implements Iterator {
         * @return      void
         */
        public function rewind () {
-               $this->partialStub('Please implement this method.');
+               // Debugging:
+               /* DEBUG-DIE: */ die(sprintf('[%s:%d]: this->key(%d)[%s]=%s,this->valid=%d,this->registryKeys=%s', __METHOD__, __LINE__, strlen($this->key()), gettype($this->key()), $this->key(), intval($this->valid()), print_r($this->registryKeys, TRUE)));
        }
 
        /**
         * Checks wether the current entry is valid (not at the end of the list)
         *
-        * @return      void
+        * @return      $valid  Whether the current key is still valid
         */
        public function valid () {
-               $this->partialStub('Please implement this method.');
+               // Return flag
+               return $this->valid;
        }
 
 }
index dfe9803..965c9b8 100644 (file)
@@ -41,11 +41,6 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab
        const EXCEPTION_INVALID_HASH        = 0xf22;
 
        /**
-        * Call-back instance
-        */
-       private $callbackInstance = NULL;
-
-       /**
         * List groups array
         */
        private $listGroups = array();
@@ -72,16 +67,6 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab
        }
 
        /**
-        * Setter for call-back instance
-        *
-        * @param       $callbackInstance       An instance of a FrameworkInterface class
-        * @return      void
-        */
-       public final function setCallbackInstance (FrameworkInterface $callbackInstance) {
-               $this->callbackInstance = $callbackInstance;
-       }
-
-       /**
         * Getter for iterator instance from this list
         *
         * @return      $iteratorInstance       An instance of a Iterator class
@@ -319,12 +304,12 @@ class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countab
                } elseif ((is_array($entry)) && (isset($entry['id']))) {
                        // Supported array found
                        $entry2 = crc32($entry['id']) . ':' . count($entry);
-               } elseif (($this->callbackInstance instanceof FrameworkInterface) && (method_exists($this->callbackInstance, 'generateListHashFromEntry'))) {
+               } elseif (($this->getCallbackInstance() instanceof FrameworkInterface) && (method_exists($this->getCallbackInstance(), 'generateListHashFromEntry'))) {
                        // Call it instead
-                       $entry2 = $this->callbackInstance->generateListHashFromEntry($entry);
+                       $entry2 = $this->getCallbackInstance()->generateListHashFromEntry($entry);
                } else {
                        // Unsupported type detected
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST[' . __METHOD__ . ':' . __LINE__ . ']: Entry type ' . gettype($entry) . ' is unsupported (this->callbackInstance=' . $this->callbackInstance . ').');
+                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST[' . __METHOD__ . ':' . __LINE__ . ']: Entry type ' . gettype($entry) . ' is unsupported (this->callbackInstance=' . $this->getCallbackInstance() . ').');
 
                        // At least take all keys from array
                        $entry2 = gettype($entry) . ':' . implode(':', array_keys($entry));
index 7c79ce3..e6be0bf 100644 (file)
@@ -54,8 +54,8 @@ class BaseRegistry extends BaseFrameworkSystem implements Register, Registerable
                parent::__construct($className);
 
                // Init generic arrays
-               $this->initGenericArrayGroup('raw', 'generic');
-               $this->initGenericArrayGroup('raw', 'instance');
+               $this->initGenericArrayGroup('registry', 'generic');
+               $this->initGenericArrayGroup('registry', 'instance');
        }
 
        /**
@@ -64,8 +64,20 @@ class BaseRegistry extends BaseFrameworkSystem implements Register, Registerable
         * @return      $iteratorInstance       An instance of a Iterator class
         */
        public function getIterator () {
-               // Instance + return it
-               return ObjectFactory::createObjectByConfiguredName('registry_iterator_class', array($this));
+               // Is it set?
+               if (is_null($this->getIteratorInstance())) {
+                       // Then instance it
+                       $iteratorInstance = ObjectFactory::createObjectByConfiguredName('registry_iterator_class', array($this));
+
+                       // ... and set it here
+                       $this->setIteratorInstance($iteratorInstance);
+               } else {
+                       // Use set iterator
+                       $iteratorInstance = $this->getIteratorInstance();
+               }
+
+               // Return it
+               return $iteratorInstance;
        }
 
        /**
@@ -94,6 +106,15 @@ class BaseRegistry extends BaseFrameworkSystem implements Register, Registerable
        }
 
        /**
+        * Getter for whole generic registry
+        *
+        * @return      $instanceRegistry       The whole generic registry array
+        */
+       public final function getGenericRegistry () {
+               return $this->getGenericSubArray('registry', 'generic');
+       }
+
+       /**
         * Getter for whole instance registry
         *
         * @return      $instanceRegistry       The whole instance registry array
@@ -115,7 +136,7 @@ class BaseRegistry extends BaseFrameworkSystem implements Register, Registerable
                assert(!is_array($key));
 
                // Push it
-               $this->pushValueToGenericArrayKey('raw', 'generic', $key, $value);
+               $this->pushValueToGenericArrayKey('registry', 'generic', $key, $value);
        }
 
        /**
@@ -128,12 +149,12 @@ class BaseRegistry extends BaseFrameworkSystem implements Register, Registerable
                assert(!is_array($key));
 
                // Default is whole array
-               $entries = $this->getGenericArray('raw');
+               $entries = $this->getGenericArray('registry');
 
                // Is $key set?
                if (!is_null($key)) {
                        // Then use this entry
-                       $entries = $this->getGenericArrayKey('raw', 'generic', $key);
+                       $entries = $this->getGenericArrayKey('registry', 'generic', $key);
                } // END - if
 
                // Return the array
index 909832f..cb52f26 100644 (file)
@@ -46,6 +46,14 @@ interface FrameworkInterface {
        function isFieldSet ($fieldName);
 
        /**
+        * Setter for call-back instance
+        *
+        * @param       $callbackInstance       An instance of a FrameworkInterface class
+        * @return      void
+        */
+       function setCallbackInstance (FrameworkInterface $callbackInstance);
+
+       /**
         * Checks whether an object equals this object. You should overwrite this
         * method to implement own equality checks
         *
diff --git a/framework/main/interfaces/iterator/class_SeekableWritableFileIterator.php b/framework/main/interfaces/iterator/class_SeekableWritableFileIterator.php
deleted file mode 100644 (file)
index 45f49c6..0000000
+++ /dev/null
@@ -1,192 +0,0 @@
-<?php
-// Own namespace
-namespace CoreFramework\Iterator\Filesystem;
-
-// Import SPL stuff
-use \SeekableIterator;
-
-/**
- * An interface for seekable iterators which also allow to write to the file
- * in different ways.
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core 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 <http://www.gnu.org/licenses/>.
- */
-interface SeekableWritableFileIterator extends SeekableIterator {
-       /**
-        * Seeks to given position
-        *
-        * @param       $seekPosition   Seek position in file
-        * @return      $status                 Status of this operation
-        */
-       function seek ($seekPosition);
-
-       /**
-        * Size of file stack
-        *
-        * @return      $size   Size (in bytes) of file
-        */
-       function size ();
-
-       /**
-        * Reads given amount of bytes from file.
-        *
-        * @param       $bytes  Amount of bytes to read
-        * @return      $data   Data read from file
-        */
-       function read ($bytes);
-
-       /**
-        * Analyzes entries in index file. This will count all found (and valid)
-        * entries, mark invalid as damaged and count gaps ("fragmentation"). If
-        * only gaps are found, the file is considered as "virgin" (no entries).
-        *
-        * @return      void
-        */
-       function analyzeFile ();
-
-       /**
-        * Checks whether the file header is initialized
-        *
-        * @return      $isInitialized  Whether the file header is initialized
-        */
-       function isFileHeaderInitialized ();
-
-       /**
-        * Creates the assigned file
-        *
-        * @return      void
-        */
-       function createFileHeader ();
-
-       /**
-        * Pre-allocates file (if enabled) with some space for later faster write access.
-        *
-        * @param       $type   Type of the file
-        * @return      void
-        */
-       function preAllocateFile ($type);
-
-       /**
-        * Initializes counter for valid entries, arrays for damaged entries and
-        * an array for gap seek positions. If you call this method on your own,
-        * please re-analyze the file structure. So you are better to call
-        * analyzeFile() instead of this method.
-        *
-        * @return      void
-        */
-       function initCountersGapsArray ();
-
-       /**
-        * Getter for header size
-        *
-        * @return      $totalEntries   Size of file header
-        */
-       function getHeaderSize ();
-
-       /**
-        * Setter for header size
-        *
-        * @param       $headerSize             Size of file header
-        * @return      void
-        */
-       function setHeaderSize ($headerSize);
-
-       /**
-        * Getter for header array
-        *
-        * @return      $totalEntries   Size of file header
-        */
-       function getHeader ();
-
-       /**
-        * Setter for header
-        *
-        * @param       $header         Array for a file header
-        * @return      void
-        */
-       function setHeader (array $header);
-
-       /**
-        * Updates seekPosition attribute from file to avoid to much access on file.
-        *
-        * @return      void
-        */
-       function updateSeekPosition ();
-
-       /**
-        * Getter for total entries
-        *
-        * @return      $totalEntries   Total entries in this file
-        */
-       function getCounter ();
-
-       /**
-        * "Getter" for file size
-        *
-        * @return      $fileSize       Size of currently loaded file
-        */
-       function getFileSize ();
-
-       /**
-        * Writes data at given position
-        *
-        * @param       $seekPosition   Seek position
-        * @param       $data                   Data to be written
-        * @param       $flushHeader    Whether to flush the header (default: flush)
-        * @return      void
-        */
-       function writeData ($seekPosition, $data, $flushHeader = true);
-
-       /**
-        * Getter for seek position
-        *
-        * @return      $seekPosition   Current seek position (stored here in object)
-        */
-       function getSeekPosition ();
-
-       /**
-        * Writes given value to the file and returns a hash and gap position for it
-        *
-        * @param       $groupId        Group identifier
-        * @param       $value          Value to be added to the stack
-        * @return      $data           Hash and gap position
-        */
-       function writeValueToFile ($groupId, $value);
-
-       /**
-        * Writes given raw data to the file and returns a gap position and length
-        *
-        * @param       $groupId        Group identifier
-        * @param       $hash           Hash from encoded value
-        * @param       $encoded        Encoded value to be written to the file
-        * @return      $data           Gap position and length of the raw data
-        */
-       function writeDataToFreeGap ($groupId, $hash, $encoded);
-
-       /**
-        * Searches for next suitable gap the given length of data can fit in
-        * including padding bytes.
-        *
-        * @param       $length                 Length of raw data
-        * @return      $seekPosition   Found next gap's seek position
-        */
-       function searchNextGap ($length);
-
-}
diff --git a/framework/main/interfaces/iterator/file/.htaccess b/framework/main/interfaces/iterator/file/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/framework/main/interfaces/iterator/file/class_SeekableWritableFileIterator.php b/framework/main/interfaces/iterator/file/class_SeekableWritableFileIterator.php
new file mode 100644 (file)
index 0000000..45f49c6
--- /dev/null
@@ -0,0 +1,192 @@
+<?php
+// Own namespace
+namespace CoreFramework\Iterator\Filesystem;
+
+// Import SPL stuff
+use \SeekableIterator;
+
+/**
+ * An interface for seekable iterators which also allow to write to the file
+ * in different ways.
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core 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 <http://www.gnu.org/licenses/>.
+ */
+interface SeekableWritableFileIterator extends SeekableIterator {
+       /**
+        * Seeks to given position
+        *
+        * @param       $seekPosition   Seek position in file
+        * @return      $status                 Status of this operation
+        */
+       function seek ($seekPosition);
+
+       /**
+        * Size of file stack
+        *
+        * @return      $size   Size (in bytes) of file
+        */
+       function size ();
+
+       /**
+        * Reads given amount of bytes from file.
+        *
+        * @param       $bytes  Amount of bytes to read
+        * @return      $data   Data read from file
+        */
+       function read ($bytes);
+
+       /**
+        * Analyzes entries in index file. This will count all found (and valid)
+        * entries, mark invalid as damaged and count gaps ("fragmentation"). If
+        * only gaps are found, the file is considered as "virgin" (no entries).
+        *
+        * @return      void
+        */
+       function analyzeFile ();
+
+       /**
+        * Checks whether the file header is initialized
+        *
+        * @return      $isInitialized  Whether the file header is initialized
+        */
+       function isFileHeaderInitialized ();
+
+       /**
+        * Creates the assigned file
+        *
+        * @return      void
+        */
+       function createFileHeader ();
+
+       /**
+        * Pre-allocates file (if enabled) with some space for later faster write access.
+        *
+        * @param       $type   Type of the file
+        * @return      void
+        */
+       function preAllocateFile ($type);
+
+       /**
+        * Initializes counter for valid entries, arrays for damaged entries and
+        * an array for gap seek positions. If you call this method on your own,
+        * please re-analyze the file structure. So you are better to call
+        * analyzeFile() instead of this method.
+        *
+        * @return      void
+        */
+       function initCountersGapsArray ();
+
+       /**
+        * Getter for header size
+        *
+        * @return      $totalEntries   Size of file header
+        */
+       function getHeaderSize ();
+
+       /**
+        * Setter for header size
+        *
+        * @param       $headerSize             Size of file header
+        * @return      void
+        */
+       function setHeaderSize ($headerSize);
+
+       /**
+        * Getter for header array
+        *
+        * @return      $totalEntries   Size of file header
+        */
+       function getHeader ();
+
+       /**
+        * Setter for header
+        *
+        * @param       $header         Array for a file header
+        * @return      void
+        */
+       function setHeader (array $header);
+
+       /**
+        * Updates seekPosition attribute from file to avoid to much access on file.
+        *
+        * @return      void
+        */
+       function updateSeekPosition ();
+
+       /**
+        * Getter for total entries
+        *
+        * @return      $totalEntries   Total entries in this file
+        */
+       function getCounter ();
+
+       /**
+        * "Getter" for file size
+        *
+        * @return      $fileSize       Size of currently loaded file
+        */
+       function getFileSize ();
+
+       /**
+        * Writes data at given position
+        *
+        * @param       $seekPosition   Seek position
+        * @param       $data                   Data to be written
+        * @param       $flushHeader    Whether to flush the header (default: flush)
+        * @return      void
+        */
+       function writeData ($seekPosition, $data, $flushHeader = true);
+
+       /**
+        * Getter for seek position
+        *
+        * @return      $seekPosition   Current seek position (stored here in object)
+        */
+       function getSeekPosition ();
+
+       /**
+        * Writes given value to the file and returns a hash and gap position for it
+        *
+        * @param       $groupId        Group identifier
+        * @param       $value          Value to be added to the stack
+        * @return      $data           Hash and gap position
+        */
+       function writeValueToFile ($groupId, $value);
+
+       /**
+        * Writes given raw data to the file and returns a gap position and length
+        *
+        * @param       $groupId        Group identifier
+        * @param       $hash           Hash from encoded value
+        * @param       $encoded        Encoded value to be written to the file
+        * @return      $data           Gap position and length of the raw data
+        */
+       function writeDataToFreeGap ($groupId, $hash, $encoded);
+
+       /**
+        * Searches for next suitable gap the given length of data can fit in
+        * including padding bytes.
+        *
+        * @param       $length                 Length of raw data
+        * @return      $seekPosition   Found next gap's seek position
+        */
+       function searchNextGap ($length);
+
+}
diff --git a/framework/main/interfaces/iterator/registry/.htaccess b/framework/main/interfaces/iterator/registry/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/framework/main/interfaces/iterator/registry/class_IteratableRegistry.php b/framework/main/interfaces/iterator/registry/class_IteratableRegistry.php
new file mode 100644 (file)
index 0000000..335ee5f
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+// Own namespace
+namespace CoreFramework\Iterator\Registry;
+
+// Import framework stuff
+use CoreFramework\Generic\FrameworkInterface;
+
+// Import SPL stuff
+use \Iterator;
+
+/**
+ * A registry iterator interface
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core 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 <http://www.gnu.org/licenses/>.
+ */
+interface IteratableRegistry extends FrameworkInterface, Iterator {
+
+       /**
+        * Initializes this iterator by scanning over the registry for all keys.
+        *
+        * @return      void
+        * @throws      LogicException  If a registry entry does not implement Registerable
+        * @throws      NullPointerException    If criteriaKey or criteriaMethod is not set but a call-back instance is set
+        */
+       function initIterator (FrameworkInterface $callbackInstance = NULL, $criteriaKey = NULL, $criteriaMethod = NULL);
+
+}
index 3fc6b55..3383964 100644 (file)
@@ -46,10 +46,51 @@ interface Register extends FrameworkInterface {
        function addInstance ($instanceKey, Registerable $objectInstance);
 
        /**
+        * Getter for whole generic registry
+        *
+        * @return      $instanceRegistry       The whole generic registry array
+        */
+       function getGenericRegistry ();
+
+       /**
+        * Getter for whole instance registry
+        *
+        * @return      $instanceRegistry       The whole instance registry array
+        */
+       function getInstanceRegistry ();
+
+       /**
+        * Adds a new entry to the given list name. If you want to add objects
+        * please use addInstance() and getInstance() instead.
+        *
+        * @param       $key    The key to identify the whole list
+        * @param       $value  The value to be stored
+        * @return      void
+        */
+       function addEntry ($key, $value);
+
+       /**
+        * Getter for entries or "sub entries"
+        *
+        * @return      $entries        An array with entries from this registry
+        */
+       function getEntries ($key = NULL);
+
+       /**
+        * "Getter" for an array of all entries for given key
+        *
+        * @param       $arrayKey       The array (key) to look in
+        * @param       $lookFor        The key to look for
+        * @return      $entry          An array with all keys
+        */
+       function getArrayFromKey ($arrayKey, $lookFor);
+
+       /**
         * Gets a registered instance or null if not found
         *
         * @param       $instanceKey            The key to identify the instance
         * @return      $objectInstance         An instance we shall store
+        * @throws      NullPointerException    If the requested key is not found
         */
        function getInstance ($instanceKey);