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;
12 * A FiFo file-based stack
14 * @author Roland Haeder <webmaster@ship-simu.org>
16 * @copyright Copyright (c) 2017 Core Developer Team
17 * @license GNU GPL 3.0 or any newer version
18 * @link http://www.ship-simu.org
20 * This program is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 class FiFoFileStack extends BaseFileStack implements StackableFile, CalculatableBlock, Registerable {
35 * Protected constructor
39 protected function __construct () {
40 // Call parent constructor
41 parent::__construct(__CLASS__);
45 * Creates an instance of this class
47 * @param $fileName Absolute Name of stack file
48 * @param $type Type of this stack (e.g. url_source for URL sources)
49 * @return $stackInstance An instance of a StackableFile class
51 public final static function createFiFoFileStack ($fileName, $type) {
53 $stackInstance = new FiFoFileStack();
56 $stackInstance->initFileStack($fileName, $type);
58 // Return the prepared instance
59 return $stackInstance;
63 * Pushs a value on a named stacker
65 * @param $stackerName Name of the stack
66 * @param $value Value to push on it
68 * @throws StackerFullException If the stack is full
70 public function pushNamed ($stackerName, $value) {
71 // Call the protected method
72 parent::addValue($stackerName, $value);
76 * 'Pops' a value from a named stacker and returns it's value
78 * @param $stackerName Name of the stack
79 * @return $value Value of the current stack entry
80 * @throws NoStackerException If the named stacker was not found
81 * @throws EmptyStackerException If the named stacker is empty
83 public function popNamed ($stackerName) {
85 $value = $this->getNamed($stackerName);
87 // Call the protected method
88 parent::popFirst($stackerName);
95 * Get value from named stacker
97 * @param $stackerName Name of the stack
98 * @return $value Value of last added value
99 * @throws NoStackerException If the named stacker was not found
100 * @throws EmptyStackerException If the named stacker is empty
102 public function getNamed ($stackerName) {
103 // Call the protected method
104 return parent::getFirstValue($stackerName);
108 * Seeks to given position
110 * @param $seekPosition Seek position in file
111 * @return $status Status of this operation
113 public function seek ($seekPosition) {
114 $this->partialStub('seekPosition=' . $seekPosition);
120 * @return $size Size (in bytes) of file
122 public function size () {
123 // Call the iterator instance
124 return $this->getIteratorInstance()->size();