3 namespace Org\Mxchange\CoreFramework\Stacker\Filesystem;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Filesystem\Block\CalculatableBlock;
7 use Org\Mxchange\CoreFramework\Filesystem\Stack\StackableFile;
8 use Org\Mxchange\CoreFramework\Registry\Registerable;
9 use Org\Mxchange\CoreFramework\Stacker\Filesystem\BaseFileStacker;
15 * A FiFo file-based stack
17 * @author Roland Haeder <webmaster@ship-simu.org>
19 <<<<<<< HEAD:framework/main/classes/stacker/file/fifo/class_FiFoFileStack.php
20 * @copyright Copyright (c) 2017 Core Developer Team
22 * @copyright Copyright (c) 2016 Core Developer Team
23 >>>>>>> Some updates::inc/main/classes/stacker/file/fifo/class_FiFoFileStack.php
24 * @license GNU GPL 3.0 or any newer version
25 * @link http://www.ship-simu.org
27 * This program is free software: you can redistribute it and/or modify
28 * it under the terms of the GNU General Public License as published by
29 * the Free Software Foundation, either version 3 of the License, or
30 * (at your option) any later version.
32 * This program is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public License
38 * along with this program. If not, see <http://www.gnu.org/licenses/>.
40 class FiFoFileStack extends BaseFileStack implements StackableFile, CalculatableBlock, Registerable {
42 * Protected constructor
46 protected function __construct () {
47 // Call parent constructor
48 parent::__construct(__CLASS__);
52 * Creates an instance of this class
54 * @param $fileInfoInstance An instance of a SplFileInfo class
55 * @param $type Type of this stack (e.g. url_source for URL sources)
56 * @return $stackInstance An instance of a StackableFile class
58 public final static function createFiFoFileStack (SplFileInfo $fileInfoInstance, $type) {
60 $stackInstance = new FiFoFileStack();
63 $stackInstance->initFileStack($fileInfoInstance, $type);
65 // Return the prepared instance
66 return $stackInstance;
70 * Pushs a value on a named stacker
72 * @param $stackerName Name of the stack
73 * @param $value Value to push on it
75 * @throws StackerFullException If the stack is full
77 public function pushNamed ($stackerName, $value) {
78 // Call the protected method
79 parent::addValue($stackerName, $value);
83 * 'Pops' a value from a named stacker and returns it's value
85 * @param $stackerName Name of the stack
86 * @return $value Value of the current stack entry
87 * @throws NoStackerException If the named stacker was not found
88 * @throws EmptyStackerException If the named stacker is empty
90 public function popNamed ($stackerName) {
92 $value = $this->getNamed($stackerName);
94 // Call the protected method
95 parent::popFirst($stackerName);
102 * Get value from named stacker
104 * @param $stackerName Name of the stack
105 * @return $value Value of last added value
106 * @throws NoStackerException If the named stacker was not found
107 * @throws EmptyStackerException If the named stacker is empty
109 public function getNamed ($stackerName) {
110 // Call the protected method
111 return parent::getFirstValue($stackerName);
115 * Seeks to given position
117 * @param $seekPosition Seek position in file
118 * @return $status Status of this operation
120 public function seek ($seekPosition) {
121 $this->partialStub('seekPosition=' . $seekPosition);
127 * @return $size Size (in bytes) of file
129 public function size () {
130 // Call the iterator instance
131 return $this->getIteratorInstance()->size();