Continued with renaming-season:
[core.git] / framework / main / classes / stacker / filo / class_FiLoStacker.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Stacker;
4
5 /**
6  * A FiLo Stacker class
7  *
8  * @author              Roland Haeder <webmaster@shipsimu.org>
9  * @version             0.0.0
10  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
11  * @license             GNU GPL 3.0 or any newer version
12  * @link                http://www.shipsimu.org
13  *
14  * This program is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program. If not, see <http://www.gnu.org/licenses/>.
26  */
27 class FiLoStacker extends BaseStacker implements Stackable {
28         /**
29          * Protected constructor
30          *
31          * @return      void
32          */
33         protected function __construct () {
34                 // Call parent constructor
35                 parent::__construct(__CLASS__);
36         }
37
38         /**
39          * Creates an instance of the class Stacker and prepares it for usage
40          *
41          * @return      $stackInstance  An instance of FiLoStacker
42          */
43         public static final function createFiLoStacker () {
44                 // Get a new instance
45                 $stackInstance = new FiLoStacker();
46
47                 // Init the generic stacker
48                 $stackInstance->initStack('generic');
49
50                 // Return the prepared instance
51                 return $stackInstance;
52         }
53
54         /**
55          * Pushs a value on a named stacker
56          *
57          * @param       $stackerName    Name of the stack
58          * @param       $value                  Value to push on it
59          * @return      void
60          * @throws      StackerFullException    If the stack is full
61          */
62         public function pushNamed ($stackerName, $value) {
63                 // Call the protected method
64                 parent::addValue($stackerName, $value);
65         }
66
67         /**
68          * 'Pops' a value from a named stacker and returns it's value
69          *
70          * @param       $stackerName    Name of the stack
71          * @return      $value                  Value of the current stack entry
72          * @throws      NoStackerException      If the named stacker was not found
73          * @throws      EmptyStackerException   If the named stacker is empty
74          */
75         public function popNamed ($stackerName) {
76                 // Get the value
77                 $value = $this->getNamed($stackerName);
78
79                 // Call the protected method
80                 parent::popLast($stackerName);
81
82                 // Return the value
83                 return $value;
84         }
85
86         /**
87          * Get value from named stacker
88          *
89          * @param       $stackerName    Name of the stack
90          * @return      $value                  Value of last added value
91          * @throws      NoStackerException      If the named stacker was not found
92          * @throws      EmptyStackerException   If the named stacker is empty
93          */
94         public function getNamed ($stackerName) {
95                 // Call the protected method
96                 return parent::getLastValue($stackerName);
97         }
98
99 }