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 * @copyright Copyright (c) 2017 Core Developer Team
20 * @license GNU GPL 3.0 or any newer version
21 * @link http://www.ship-simu.org
23 * This program is free software: you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation, either version 3 of the License, or
26 * (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program. If not, see <http://www.gnu.org/licenses/>.
36 class FiFoFileStack extends BaseFileStack implements StackableFile, CalculatableBlock, Registerable {
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
48 * Creates an instance of this class
50 * @param $fileInfoInstance An instance of a SplFileInfo class
51 * @param $type Type of this stack (e.g. url_source for URL sources)
52 * @return $stackInstance An instance of a StackableFile class
54 public final static function createFiFoFileStack (SplFileInfo $fileInfoInstance, $type) {
56 $stackInstance = new FiFoFileStack();
59 $stackInstance->initFileStack($fileInfoInstance, $type);
61 // Return the prepared instance
62 return $stackInstance;
66 * Pushs a value on a named stacker
68 * @param $stackerName Name of the stack
69 * @param $value Value to push on it
71 * @throws StackerFullException If the stack is full
73 public function pushNamed ($stackerName, $value) {
74 // Call the protected method
75 parent::addValue($stackerName, $value);
79 * 'Pops' a value from a named stacker and returns it's value
81 * @param $stackerName Name of the stack
82 * @return $value Value of the current stack entry
83 * @throws NoStackerException If the named stacker was not found
84 * @throws EmptyStackerException If the named stacker is empty
86 public function popNamed ($stackerName) {
88 $value = $this->getNamed($stackerName);
90 // Call the protected method
91 parent::popFirst($stackerName);
98 * Get value from named stacker
100 * @param $stackerName Name of the stack
101 * @return $value Value of last added value
102 * @throws NoStackerException If the named stacker was not found
103 * @throws EmptyStackerException If the named stacker is empty
105 public function getNamed ($stackerName) {
106 // Call the protected method
107 return parent::getFirstValue($stackerName);
111 * Seeks to given position
113 * @param $seekPosition Seek position in file
114 * @return $status Status of this operation
116 public function seek ($seekPosition) {
117 $this->partialStub('seekPosition=' . $seekPosition);
123 * @return $size Size (in bytes) of file
125 public function size () {
126 // Call the iterator instance
127 return $this->getIteratorInstance()->size();