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