3 namespace CoreFramework\Stack\Filesystem;
5 // Import framework stuff
6 use CoreFramework\Registry\Registerable;
9 * A FiFo file-based stack
11 * @author Roland Haeder <webmaster@ship-simu.org>
13 * @copyright Copyright (c) 2017 Core Developer Team
14 * @license GNU GPL 3.0 or any newer version
15 * @link http://www.ship-simu.org
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 class FiFoFileStack extends BaseFileStack implements StackableFile, CalculatableBlock, Registerable {
32 * Protected constructor
36 protected function __construct () {
37 // Call parent constructor
38 parent::__construct(__CLASS__);
42 * Creates an instance of this class
44 * @param $fileName Absolute Name of stack file
45 * @param $type Type of this stack (e.g. url_source for URL sources)
46 * @return $stackInstance An instance of a StackableFile class
48 public final static function createFiFoFileStack ($fileName, $type) {
50 $stackInstance = new FiFoFileStack();
53 $stackInstance->initFileStack($fileName, $type);
55 // Return the prepared instance
56 return $stackInstance;
60 * Pushs a value on a named stacker
62 * @param $stackerName Name of the stack
63 * @param $value Value to push on it
65 * @throws StackerFullException If the stack is full
67 public function pushNamed ($stackerName, $value) {
68 // Call the protected method
69 parent::addValue($stackerName, $value);
73 * 'Pops' a value from a named stacker and returns it's value
75 * @param $stackerName Name of the stack
76 * @return $value Value of the current stack entry
77 * @throws NoStackerException If the named stacker was not found
78 * @throws EmptyStackerException If the named stacker is empty
80 public function popNamed ($stackerName) {
82 $value = $this->getNamed($stackerName);
84 // Call the protected method
85 parent::popFirst($stackerName);
92 * Get value from named stacker
94 * @param $stackerName Name of the stack
95 * @return $value Value of last added value
96 * @throws NoStackerException If the named stacker was not found
97 * @throws EmptyStackerException If the named stacker is empty
99 public function getNamed ($stackerName) {
100 // Call the protected method
101 return parent::getFirstValue($stackerName);
105 * Seeks to given position
107 * @param $seekPosition Seek position in file
108 * @return $status Status of this operation
110 public function seek ($seekPosition) {
111 $this->partialStub('seekPosition=' . $seekPosition);
117 * @return $size Size (in bytes) of file
119 public function size () {
120 // Call the iterator instance
121 return $this->getIteratorInstance()->size();