]> git.mxchange.org Git - core.git/blob - framework/main/classes/stacker/file/fifo/class_FiFoFileStack.php
2e380b2d3d8d89d14f53dc9462cf27e1bb27752b
[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\Filesystem\Block\CalculatableBlock;
7 use CoreFramework\Registry\Registerable;
8
9 /**
10  * A FiFo file-based stack
11  *
12  * @author              Roland Haeder <webmaster@ship-simu.org>
13  * @version             0.0.0
14  * @copyright   Copyright (c) 2017 Core Developer Team
15  * @license             GNU GPL 3.0 or any newer version
16  * @link                http://www.ship-simu.org
17  *
18  * This program is free software: you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation, either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30  */
31 class FiFoFileStack extends BaseFileStack implements StackableFile, CalculatableBlock, Registerable {
32         /**
33          * Protected constructor
34          *
35          * @return      void
36          */
37         protected function __construct () {
38                 // Call parent constructor
39                 parent::__construct(__CLASS__);
40         }
41
42         /**
43          * Creates an instance of this class
44          *
45          * @param       $fileName               Absolute Name of stack file
46          * @param       $type                   Type of this stack (e.g. url_source for URL sources)
47          * @return      $stackInstance  An instance of a StackableFile class
48          */
49         public final static function createFiFoFileStack ($fileName, $type) {
50                 // Get new instance
51                 $stackInstance = new FiFoFileStack();
52
53                 // Init this stack
54                 $stackInstance->initFileStack($fileName, $type);
55
56                 // Return the prepared instance
57                 return $stackInstance;
58         }
59
60         /**
61          * Pushs a value on a named stacker
62          *
63          * @param       $stackerName    Name of the stack
64          * @param       $value                  Value to push on it
65          * @return      void
66          * @throws      StackerFullException    If the stack is full
67          */
68         public function pushNamed ($stackerName, $value) {
69                 // Call the protected method
70                 parent::addValue($stackerName, $value);
71         }
72
73         /**
74          * 'Pops' a value from a named stacker and returns it's value
75          *
76          * @param       $stackerName    Name of the stack
77          * @return      $value                  Value of the current stack entry
78          * @throws      NoStackerException      If the named stacker was not found
79          * @throws      EmptyStackerException   If the named stacker is empty
80          */
81         public function popNamed ($stackerName) {
82                 // Get the value
83                 $value = $this->getNamed($stackerName);
84
85                 // Call the protected method
86                 parent::popFirst($stackerName);
87
88                 // Return the value
89                 return $value;
90         }
91
92         /**
93          * Get value from named stacker
94          *
95          * @param       $stackerName    Name of the stack
96          * @return      $value                  Value of last added value
97          * @throws      NoStackerException      If the named stacker was not found
98          * @throws      EmptyStackerException   If the named stacker is empty
99          */
100         public function getNamed ($stackerName) {
101                 // Call the protected method
102                 return parent::getFirstValue($stackerName);
103         }
104
105         /**
106          * Seeks to given position
107          *
108          * @param       $seekPosition   Seek position in file
109          * @return      $status                 Status of this operation
110          */
111         public function seek ($seekPosition) {
112                 $this->partialStub('seekPosition=' . $seekPosition);
113         }
114
115         /**
116          * Size of file stack
117          *
118          * @return      $size   Size (in bytes) of file
119          */
120         public function size () {
121                 // Call the iterator instance
122                 return $this->getIteratorInstance()->size();
123         }
124
125 }