Continued with renaming-season:
[core.git] / framework / main / classes / stacker / file / fifo / class_FiFoFileStack.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Stack\Filesystem;
4
5 // Import framework stuff
6 use CoreFramework\Registry\Registerable;
7
8 /**
9  * A FiFo file-based stack
10  *
11  * @author              Roland Haeder <webmaster@ship-simu.org>
12  * @version             0.0.0
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
16  *
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.
21  *
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.
26  *
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/>.
29  */
30 class FiFoFileStack extends BaseFileStack implements StackableFile, CalculatableBlock, Registerable {
31         /**
32          * Protected constructor
33          *
34          * @return      void
35          */
36         protected function __construct () {
37                 // Call parent constructor
38                 parent::__construct(__CLASS__);
39         }
40
41         /**
42          * Creates an instance of this class
43          *
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 Stackable class
47          */
48         public final static function createFiFoFileStack ($fileName, $type) {
49                 // Get new instance
50                 $stackInstance = new FiFoFileStack();
51
52                 // Init this stack
53                 $stackInstance->initFileStack($fileName, $type);
54
55                 // Return the prepared instance
56                 return $stackInstance;
57         }
58
59         /**
60          * Pushs a value on a named stacker
61          *
62          * @param       $stackerName    Name of the stack
63          * @param       $value                  Value to push on it
64          * @return      void
65          * @throws      StackerFullException    If the stack is full
66          */
67         public function pushNamed ($stackerName, $value) {
68                 // Call the protected method
69                 parent::addValue($stackerName, $value);
70         }
71
72         /**
73          * 'Pops' a value from a named stacker and returns it's value
74          *
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
79          */
80         public function popNamed ($stackerName) {
81                 // Get the value
82                 $value = $this->getNamed($stackerName);
83
84                 // Call the protected method
85                 parent::popFirst($stackerName);
86
87                 // Return the value
88                 return $value;
89         }
90
91         /**
92          * Get value from named stacker
93          *
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
98          */
99         public function getNamed ($stackerName) {
100                 // Call the protected method
101                 return parent::getFirstValue($stackerName);
102         }
103
104         /**
105          * Seeks to given position
106          *
107          * @param       $seekPosition   Seek position in file
108          * @return      $status                 Status of this operation
109          */
110         public function seek ($seekPosition) {
111                 $this->partialStub('seekPosition=' . $seekPosition);
112         }
113
114         /**
115          * Size of file stack
116          *
117          * @return      $size   Size (in bytes) of file
118          */
119         public function size () {
120                 // Call the iterator instance
121                 return $this->getIteratorInstance()->size();
122         }
123
124 }