From 5c59e6f195a02fdedd26f04150a83a3b87b8ba24 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 15 May 2014 22:24:55 +0200 Subject: [PATCH] Continued with file-based stacks: - BaseFileStack now extends BaseStacker and overwrites some methods to have own implementations - renamed 'io' to 'file_directory' MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../.htaccess | 0 .../class_BaseFileIo.php | 0 .../directory}/.htaccess | 0 .../class_FrameworkDirectoryPointer.php | 0 .../{io => file_directories/input}/.htaccess | 0 .../input/class_FrameworkFileInputPointer.php | 0 .../io}/.htaccess | 0 .../class_FrameworkFileInputOutputPointer.php | 0 .../io_handler}/.htaccess | 0 .../io_handler/class_FileIoStream.php | 0 .../io => file_directories/output}/.htaccess | 0 .../class_FrameworkFileOutputPointer.php | 0 .../main/file_stack/class_BaseFileStack.php | 58 ----- .../main/stacker/class_BaseStacker.php | 16 +- .../file_stack}/.htaccess | 0 .../main/{ => stacker}/file_stack/class_ | 36 +++ .../file_stack/class_BaseFileStack.php | 215 ++++++++++++++++++ .../file_stack/fifo}/.htaccess | 0 .../file_stack/fifo/class_FiFoFileStack.php | 36 +++ 19 files changed, 295 insertions(+), 66 deletions(-) rename inc/classes/main/{file_stack => file_directories}/.htaccess (100%) rename inc/classes/main/{io => file_directories}/class_BaseFileIo.php (100%) rename inc/classes/main/{file_stack/fifo => file_directories/directory}/.htaccess (100%) rename inc/classes/main/{io => file_directories}/directory/class_FrameworkDirectoryPointer.php (100%) rename inc/classes/main/{io => file_directories/input}/.htaccess (100%) rename inc/classes/main/{io => file_directories}/input/class_FrameworkFileInputPointer.php (100%) rename inc/classes/main/{io/directory => file_directories/io}/.htaccess (100%) rename inc/classes/main/{io => file_directories}/io/class_FrameworkFileInputOutputPointer.php (100%) rename inc/classes/main/{io/input => file_directories/io_handler}/.htaccess (100%) rename inc/classes/main/{io => file_directories}/io_handler/class_FileIoStream.php (100%) rename inc/classes/main/{io/io => file_directories/output}/.htaccess (100%) rename inc/classes/main/{io => file_directories}/output/class_FrameworkFileOutputPointer.php (100%) delete mode 100644 inc/classes/main/file_stack/class_BaseFileStack.php rename inc/classes/main/{io/io_handler => stacker/file_stack}/.htaccess (100%) rename inc/classes/main/{ => stacker}/file_stack/class_ (59%) create mode 100644 inc/classes/main/stacker/file_stack/class_BaseFileStack.php rename inc/classes/main/{io/output => stacker/file_stack/fifo}/.htaccess (100%) rename inc/classes/main/{ => stacker}/file_stack/fifo/class_FiFoFileStack.php (59%) diff --git a/inc/classes/main/file_stack/.htaccess b/inc/classes/main/file_directories/.htaccess similarity index 100% rename from inc/classes/main/file_stack/.htaccess rename to inc/classes/main/file_directories/.htaccess diff --git a/inc/classes/main/io/class_BaseFileIo.php b/inc/classes/main/file_directories/class_BaseFileIo.php similarity index 100% rename from inc/classes/main/io/class_BaseFileIo.php rename to inc/classes/main/file_directories/class_BaseFileIo.php diff --git a/inc/classes/main/file_stack/fifo/.htaccess b/inc/classes/main/file_directories/directory/.htaccess similarity index 100% rename from inc/classes/main/file_stack/fifo/.htaccess rename to inc/classes/main/file_directories/directory/.htaccess diff --git a/inc/classes/main/io/directory/class_FrameworkDirectoryPointer.php b/inc/classes/main/file_directories/directory/class_FrameworkDirectoryPointer.php similarity index 100% rename from inc/classes/main/io/directory/class_FrameworkDirectoryPointer.php rename to inc/classes/main/file_directories/directory/class_FrameworkDirectoryPointer.php diff --git a/inc/classes/main/io/.htaccess b/inc/classes/main/file_directories/input/.htaccess similarity index 100% rename from inc/classes/main/io/.htaccess rename to inc/classes/main/file_directories/input/.htaccess diff --git a/inc/classes/main/io/input/class_FrameworkFileInputPointer.php b/inc/classes/main/file_directories/input/class_FrameworkFileInputPointer.php similarity index 100% rename from inc/classes/main/io/input/class_FrameworkFileInputPointer.php rename to inc/classes/main/file_directories/input/class_FrameworkFileInputPointer.php diff --git a/inc/classes/main/io/directory/.htaccess b/inc/classes/main/file_directories/io/.htaccess similarity index 100% rename from inc/classes/main/io/directory/.htaccess rename to inc/classes/main/file_directories/io/.htaccess diff --git a/inc/classes/main/io/io/class_FrameworkFileInputOutputPointer.php b/inc/classes/main/file_directories/io/class_FrameworkFileInputOutputPointer.php similarity index 100% rename from inc/classes/main/io/io/class_FrameworkFileInputOutputPointer.php rename to inc/classes/main/file_directories/io/class_FrameworkFileInputOutputPointer.php diff --git a/inc/classes/main/io/input/.htaccess b/inc/classes/main/file_directories/io_handler/.htaccess similarity index 100% rename from inc/classes/main/io/input/.htaccess rename to inc/classes/main/file_directories/io_handler/.htaccess diff --git a/inc/classes/main/io/io_handler/class_FileIoStream.php b/inc/classes/main/file_directories/io_handler/class_FileIoStream.php similarity index 100% rename from inc/classes/main/io/io_handler/class_FileIoStream.php rename to inc/classes/main/file_directories/io_handler/class_FileIoStream.php diff --git a/inc/classes/main/io/io/.htaccess b/inc/classes/main/file_directories/output/.htaccess similarity index 100% rename from inc/classes/main/io/io/.htaccess rename to inc/classes/main/file_directories/output/.htaccess diff --git a/inc/classes/main/io/output/class_FrameworkFileOutputPointer.php b/inc/classes/main/file_directories/output/class_FrameworkFileOutputPointer.php similarity index 100% rename from inc/classes/main/io/output/class_FrameworkFileOutputPointer.php rename to inc/classes/main/file_directories/output/class_FrameworkFileOutputPointer.php diff --git a/inc/classes/main/file_stack/class_BaseFileStack.php b/inc/classes/main/file_stack/class_BaseFileStack.php deleted file mode 100644 index d53d1e3b..00000000 --- a/inc/classes/main/file_stack/class_BaseFileStack.php +++ /dev/null @@ -1,58 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 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 . - */ -class BaseFileStack extends BaseFrameworkSystem { - /** - * Protected constructor - * - * @param $className Name of the class - * @return void - */ - protected function __construct ($className) { - // Call parent constructor - parent::__construct($className); - } - - /** - * Initializes this stack. - * - * @param $fileName File name of this stack - * @return void - */ - protected function initStack ($fileName) { - // Get a file i/o pointer instance - $pointerInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_output_class', array($fileName)); - - // Get iterator instance - $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_io_iterator_class', array($pointerInstance)); - - // Is the instance implementing the right interface? - assert($iteratorInstance instanceof SeekableFileIterator); - - // Set iterator here - $this->setIteratorInstance($iteratorInstance); - } -} - -// [EOF] -?> diff --git a/inc/classes/main/stacker/class_BaseStacker.php b/inc/classes/main/stacker/class_BaseStacker.php index ee63dfd4..0f4ba20f 100644 --- a/inc/classes/main/stacker/class_BaseStacker.php +++ b/inc/classes/main/stacker/class_BaseStacker.php @@ -47,7 +47,7 @@ class BaseStacker extends BaseFrameworkSystem { * @return void * @throws AlreadyInitializedStackerException If the stack is already initialized */ - public final function initStack ($stackerName, $forceReInit = FALSE) { + public function initStack ($stackerName, $forceReInit = FALSE) { // Is the stack already initialized? if (($forceReInit === FALSE) && ($this->isStackInitialized($stackerName))) { // Then throw the exception @@ -77,7 +77,7 @@ class BaseStacker extends BaseFrameworkSystem { * @param $stackerName Name of the stack * @return $isInitialized Whether the stack is initialized */ - public final function isStackInitialized ($stackerName) { + public function isStackInitialized ($stackerName) { // Is is there? $isInitialized = ($this->isValidGenericArrayKey('stacks', $stackerName, 'entries')); @@ -134,7 +134,7 @@ class BaseStacker extends BaseFrameworkSystem { * @return $count Size of stack (array count) * @throws NoStackerException If given stack is missing */ - public final function getStackCount ($stackerName) { + public function getStackCount ($stackerName) { // Is the stack not yet initialized? if (!$this->isStackInitialized($stackerName)) { // Throw an exception @@ -156,7 +156,7 @@ class BaseStacker extends BaseFrameworkSystem { * @return void * @throws FullStackerException Thrown if the stack is full */ - protected final function addValue ($stackerName, $value) { + protected function addValue ($stackerName, $value) { // Is the stack not yet initialized or full? if (!$this->isStackInitialized($stackerName)) { // Then do it here @@ -178,7 +178,7 @@ class BaseStacker extends BaseFrameworkSystem { * @throws NoStackerException If the named stacker was not found * @throws EmptyStackerException If the named stacker is empty */ - protected final function getLastValue ($stackerName) { + protected function getLastValue ($stackerName) { // Is the stack not yet initialized or full? if (!$this->isStackInitialized($stackerName)) { // Throw an exception @@ -203,7 +203,7 @@ class BaseStacker extends BaseFrameworkSystem { * @throws NoStackerException If the named stacker was not found * @throws EmptyStackerException If the named stacker is empty */ - protected final function getFirstValue ($stackerName) { + protected function getFirstValue ($stackerName) { // Is the stack not yet initialized or full? if (!$this->isStackInitialized($stackerName)) { // Throw an exception @@ -228,7 +228,7 @@ class BaseStacker extends BaseFrameworkSystem { * @throws NoStackerException If the named stacker was not found * @throws EmptyStackerException If the named stacker is empty */ - protected final function popLast ($stackerName) { + protected function popLast ($stackerName) { // Is the stack not yet initialized or full? if (!$this->isStackInitialized($stackerName)) { // Throw an exception @@ -250,7 +250,7 @@ class BaseStacker extends BaseFrameworkSystem { * @throws NoStackerException If the named stacker was not found * @throws EmptyStackerException If the named stacker is empty */ - protected final function popFirst ($stackerName) { + protected function popFirst ($stackerName) { // Is the stack not yet initialized or full? if (!$this->isStackInitialized($stackerName)) { // Throw an exception diff --git a/inc/classes/main/io/io_handler/.htaccess b/inc/classes/main/stacker/file_stack/.htaccess similarity index 100% rename from inc/classes/main/io/io_handler/.htaccess rename to inc/classes/main/stacker/file_stack/.htaccess diff --git a/inc/classes/main/file_stack/class_ b/inc/classes/main/stacker/file_stack/class_ similarity index 59% rename from inc/classes/main/file_stack/class_ rename to inc/classes/main/stacker/file_stack/class_ index 274f923f..217eacfe 100644 --- a/inc/classes/main/file_stack/class_ +++ b/inc/classes/main/stacker/file_stack/class_ @@ -48,6 +48,42 @@ class ???FileStack extends BaseFileStack implements Stackable { // Return the prepared instance return $stackInstance; } + + /** + * Pushs a value on a named stacker + * + * @param $stackerName Name of the stack + * @param $value Value to push on it + * @return void + * @throws StackerFullException If the stack is full + */ + public function pushNamed ($stackerName, $value) { + $this->partialStub('stackerName=' . $stackerName . ',value[' . gettype($value) . ']=' . $value); + } + + /** + * 'Pops' a value from a named stacker + * + * @param $stackerName Name of the stack + * @return void + * @throws NoStackerException If the named stacker was not found + * @throws EmptyStackerException If the named stacker is empty + */ + public function popNamed ($stackerName) { + $this->partialStub('stackerName=' . $stackerName); + } + + /** + * Get value from named stacker + * + * @param $stackerName Name of the stack + * @return $value Value of last added value + * @throws NoStackerException If the named stacker was not found + * @throws EmptyStackerException If the named stacker is empty + */ + public function getNamed ($stackerName) { + $this->partialStub('stackerName=' . $stackerName); + } } // [EOF] diff --git a/inc/classes/main/stacker/file_stack/class_BaseFileStack.php b/inc/classes/main/stacker/file_stack/class_BaseFileStack.php new file mode 100644 index 00000000..0e91c788 --- /dev/null +++ b/inc/classes/main/stacker/file_stack/class_BaseFileStack.php @@ -0,0 +1,215 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 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 . + */ +class BaseFileStack extends BaseStacker { + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Initializes this stack. + * + * @param $fileName File name of this stack + * @return void + */ + protected function initStack ($fileName) { + // Get a file i/o pointer instance + $pointerInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_output_class', array($fileName)); + + // Get iterator instance + $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_io_iterator_class', array($pointerInstance)); + + // Is the instance implementing the right interface? + assert($iteratorInstance instanceof SeekableFileIterator); + + // Set iterator here + $this->setIteratorInstance($iteratorInstance); + } + + /** + * Checks whether the given stack is initialized (set in array $stackers) + * + * @param $stackerName Name of the stack + * @return $isInitialized Whether the stack is initialized + */ + public function isStackInitialized ($stackerName) { + // Is is there? + $this->partialStub('stackerName=' . $stackerName); + $isInitialized = TRUE; + + // Return result + return $isInitialized; + } + + /** + * Getter for size of given stack (array count) + * + * @param $stackerName Name of the stack + * @return $count Size of stack (array count) + * @throws NoStackerException If given stack is missing + */ + public function getStackCount ($stackerName) { + // Is the stack not yet initialized? + if (!$this->isStackInitialized($stackerName)) { + // Throw an exception + throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND); + } // END - if + + // Now, count the array of entries + $this->partialStub('stackerName=' . $stackerName); + $count = 0; + + // Return result + return $count; + } + + /** + * Adds a value to given stack + * + * @param $stackerName Name of the stack + * @param $value Value to add to this stacker + * @return void + * @throws FullStackerException Thrown if the stack is full + */ + protected function addValue ($stackerName, $value) { + // Is the stack not yet initialized or full? + if (!$this->isStackInitialized($stackerName)) { + // Then do it here + $this->initStack($stackerName); + } elseif ($this->isStackFull($stackerName)) { + // Stacker is full + throw new FullStackerException(array($this, $stackerName, $value), self::EXCEPTION_STACKER_IS_FULL); + } + + // Now add the value to the stack + $this->partialStub('stackerName=' . $stackerName . ',value[]=' . gettype($value)); + } + + /** + * Get last value from named stacker + * + * @param $stackerName Name of the stack + * @return $value Value of last added value + * @throws NoStackerException If the named stacker was not found + * @throws EmptyStackerException If the named stacker is empty + */ + protected function getLastValue ($stackerName) { + // Is the stack not yet initialized or full? + if (!$this->isStackInitialized($stackerName)) { + // Throw an exception + throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND); + } elseif ($this->isStackEmpty($stackerName)) { + // Throw an exception + throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY); + } + + // Now get the last value + $this->partialStub('stackerName=' . $stackerName); + $value = NULL; + + // Return it + return $value; + } + + /** + * Get first value from named stacker + * + * @param $stackerName Name of the stack + * @return $value Value of last added value + * @throws NoStackerException If the named stacker was not found + * @throws EmptyStackerException If the named stacker is empty + */ + protected function getFirstValue ($stackerName) { + // Is the stack not yet initialized or full? + if (!$this->isStackInitialized($stackerName)) { + // Throw an exception + throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND); + } elseif ($this->isStackEmpty($stackerName)) { + // Throw an exception + throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY); + } + + // Now get the first value + $this->partialStub('stackerName=' . $stackerName); + $value = NULL; + + // Return it + return $value; + } + + /** + * "Pops" last entry from stack + * + * @param $stackerName Name of the stack + * @return $value Value "poped" from array + * @throws NoStackerException If the named stacker was not found + * @throws EmptyStackerException If the named stacker is empty + */ + protected function popLast ($stackerName) { + // Is the stack not yet initialized or full? + if (!$this->isStackInitialized($stackerName)) { + // Throw an exception + throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND); + } elseif ($this->isStackEmpty($stackerName)) { + // Throw an exception + throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY); + } + + // Now, remove the last entry, we don't care about the return value here, see elseif() block above + $this->partialStub('stackerName=' . $stackerName); + return NULL; + } + + /** + * "Pops" first entry from stack + * + * @param $stackerName Name of the stack + * @return $value Value "shifted" from array + * @throws NoStackerException If the named stacker was not found + * @throws EmptyStackerException If the named stacker is empty + */ + protected function popFirst ($stackerName) { + // Is the stack not yet initialized or full? + if (!$this->isStackInitialized($stackerName)) { + // Throw an exception + throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND); + } elseif ($this->isStackEmpty($stackerName)) { + // Throw an exception + throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY); + } + + // Now, remove the last entry, we don't care about the return value here, see elseif() block above + $this->partialStub('stackerName=' . $stackerName); + return NULL; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/io/output/.htaccess b/inc/classes/main/stacker/file_stack/fifo/.htaccess similarity index 100% rename from inc/classes/main/io/output/.htaccess rename to inc/classes/main/stacker/file_stack/fifo/.htaccess diff --git a/inc/classes/main/file_stack/fifo/class_FiFoFileStack.php b/inc/classes/main/stacker/file_stack/fifo/class_FiFoFileStack.php similarity index 59% rename from inc/classes/main/file_stack/fifo/class_FiFoFileStack.php rename to inc/classes/main/stacker/file_stack/fifo/class_FiFoFileStack.php index d180ff34..e9624dd8 100644 --- a/inc/classes/main/file_stack/fifo/class_FiFoFileStack.php +++ b/inc/classes/main/stacker/file_stack/fifo/class_FiFoFileStack.php @@ -48,6 +48,42 @@ class FiFoFileStack extends BaseFileStack implements Stackable { // Return the prepared instance return $stackInstance; } + + /** + * Pushs a value on a named stacker + * + * @param $stackerName Name of the stack + * @param $value Value to push on it + * @return void + * @throws StackerFullException If the stack is full + */ + public function pushNamed ($stackerName, $value) { + $this->partialStub('stackerName=' . $stackerName . ',value[' . gettype($value) . ']=' . $value); + } + + /** + * 'Pops' a value from a named stacker + * + * @param $stackerName Name of the stack + * @return void + * @throws NoStackerException If the named stacker was not found + * @throws EmptyStackerException If the named stacker is empty + */ + public function popNamed ($stackerName) { + $this->partialStub('stackerName=' . $stackerName); + } + + /** + * Get value from named stacker + * + * @param $stackerName Name of the stack + * @return $value Value of last added value + * @throws NoStackerException If the named stacker was not found + * @throws EmptyStackerException If the named stacker is empty + */ + public function getNamed ($stackerName) { + $this->partialStub('stackerName=' . $stackerName); + } } // [EOF] -- 2.39.5