]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/index/class_BaseIndex.php
Again interface satisfaction ... ;-)
[core.git] / inc / classes / main / index / class_BaseIndex.php
index a427c5b7c74632a34ff501afb147d06ab6b7bb7f..2f0130b643d0e0e633a37d0a711f9dd4c8ce7a46 100644 (file)
@@ -27,16 +27,6 @@ class BaseIndex extends BaseFrameworkSystem {
         */
        const INDEX_MAGIC = 'INDEXv0.1';
 
-       /**
-        * Separator for header data
-        */
-       const SEPARATOR_HEADER_DATA = 0x01;
-
-       /**
-        * Separator header->entries
-        */
-       const SEPARATOR_HEADER_ENTRIES = 0x02;
-
        /**
         * Protected constructor
         *
@@ -64,7 +54,7 @@ class BaseIndex extends BaseFrameworkSystem {
         *
         * @return      void
         */
-       protected function readFileHeader () {
+       public function readFileHeader () {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
 
                // First rewind to beginning as the header sits at the beginning ...
@@ -124,7 +114,7 @@ class BaseIndex extends BaseFrameworkSystem {
         *
         * @return      void
         */
-       protected function flushFileHeader () {
+       public function flushFileHeader () {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
 
                // Put all informations together
@@ -149,40 +139,42 @@ class BaseIndex extends BaseFrameworkSystem {
        }
 
        /**
-        * 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).
+        * Initializes this index
         *
+        * @param       $fileName       File name of this index
         * @return      void
+        * @todo        Currently the index file is not cached, please implement a memory-handling class and if enough RAM is found, cache the whole index file.
         */
-       private function analyzeFile () {
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
+       protected function initIndex ($fileName) {
+               // Append index file extension
+               $fileName .= $this->getConfigInstance()->getConfigEntry('index_extension');
 
-               // Make sure the file is initialized
-               assert($this->isFileInitialized());
+               // Get a file i/o pointer instance for index file
+               $fileInstance = ObjectFactory::createObjectByConfiguredName('index_file_class', array($fileName, $this));
 
-               // Init counters and gaps array
-               $this->initCountersGapsArray();
+               // Get iterator instance
+               $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_iterator_class', array($fileInstance));
 
-               // Output message (as this may take some time)
-               self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Analyzing file structure ... (this may take some time)', __METHOD__, __LINE__));
+               // Is the instance implementing the right interface?
+               assert($iteratorInstance instanceof SeekableWritableFileIterator);
 
-               // First rewind to the begining
-               $this->getIteratorInstance()->rewind();
+               // Set iterator here
+               $this->setIteratorInstance($iteratorInstance);
 
-               // Then try to load all entries
-               while ($this->getIteratorInstance()->valid()) {
-                       // Go to next entry
-                       $this->getIteratorInstance()->next();
+               // Is the file's header initialized?
+               if (!$this->getIteratorInstance()->isFileHeaderInitialized()) {
+                       // No, then create it (which may pre-allocate the index)
+                       $this->getIteratorInstance()->createFileHeader();
 
-                       // Get current entry
-                       $current = $this->getIteratorInstance()->current();
+                       // And pre-allocate a bit
+                       $this->getIteratorInstance()->preAllocateFile('index');
+               } // END - if
 
-                       // Simply output it
-                       self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] current=%s', __METHOD__, __LINE__, print_r($current, TRUE)));
-               } // END - while
+               // Load the file header
+               $this->readFileHeader();
 
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
+               // Count all entries in file
+               $this->getIteratorInstance()->analyzeFile();
        }
 
        /**
@@ -190,7 +182,7 @@ class BaseIndex extends BaseFrameworkSystem {
         *
         * @return      $length         Minimum length for one entry/block
         */
-       public function caluclateMinimumBlockLength () {
+       public function calculateMinimumBlockLength () {
                // Calulcate it
                // @TODO Not finished yet
                $length = 0;
@@ -200,42 +192,34 @@ class BaseIndex extends BaseFrameworkSystem {
        }
 
        /**
-        * Initializes this index
+        * Close a file source and set it's instance to null and the file name
+        * to empty.
         *
-        * @param       $fileName       File name of this index
         * @return      void
-        * @todo        Currently the index file is not cached, please implement a memory-handling class and if enough RAM is found, cache the whole index file.
+        * @throws      UnsupportedOperationException   If this method is called
         */
-       protected function initIndex ($fileName) {
-               // Append index file extension
-               $fileName .= $this->getConfigInstance()->getConfigEntry('index_extension');
-
-               // Get a file i/o pointer instance for index file
-               $fileInstance = ObjectFactory::createObjectByConfiguredName('index_file_class', array($fileName));
-
-               // Get iterator instance
-               $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_io_iterator_class', array($fileInstance, $this));
-
-               // Is the instance implementing the right interface?
-               assert($iteratorInstance instanceof SeekableWritableFileIterator);
-
-               // Set iterator here
-               $this->setIteratorInstance($iteratorInstance);
-
-               // Is the file's header initialized?
-               if (!$this->isFileHeaderInitialized()) {
-                       // No, then create it (which may pre-allocate the index)
-                       $this->createFileHeader();
-
-                       // And pre-allocate a bit
-                       $this->preAllocateFile('index');
-               } // END - if
+       public function closeFile () {
+               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+       }
 
-               // Load the file header
-               $this->readFileHeader();
+       /**
+        * Determines whether the EOF has been reached
+        *
+        * @return      $isEndOfFileReached             Whether the EOF has been reached
+        * @throws      UnsupportedOperationException   If this method is called
+        */
+       public function isEndOfFileReached () {
+               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+       }
 
-               // Count all entries in file
-               $this->analyzeFile();
+       /**
+        * Getter for file name
+        *
+        * @return      $fileName       The current file name
+        * @throws      UnsupportedOperationException   If this method is called
+        */
+       public function getFileName () {
+               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 }