*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
* @return void
* @throws AlreadyInitializedStackerException If the stack is already initialized
*/
- protected final function initStacker ($stackerName) {
+ public final function initStacker ($stackerName) {
// Is the stack already initialized?
if ($this->isStackInitialized($stackerName)) {
// Then throw the exception
* @param $stackerName Name of the stack
* @return $isInitialized Wether the stack is initialized
*/
- protected final function isStackInitialized ($stackerName) {
+ public final function isStackInitialized ($stackerName) {
// Is is there?
$isInitialized = ((isset($this->stacks[$stackerName])) && (is_array($this->stacks[$stackerName])));
* @return $isFull Wether the stack is full
* @throws NoStackerException If given stack is missing
*/
- protected final function isStackFull($stackerName) {
+ protected final function isStackFull ($stackerName) {
// Is the stack not yet initialized?
if (!$this->isStackInitialized($stackerName)) {
// Throw an exception
* @return $isEmpty Wether the stack is empty
* @throws NoStackerException If given stack is missing
*/
- protected final function isStackEmpty($stackerName) {
+ public final function isStackEmpty ($stackerName) {
// Is the stack not yet initialized?
if (!$this->isStackInitialized($stackerName)) {
// Throw an exception
throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
} // END - if
- // So, is the stack full?
+ // So, is the stack empty?
$isFull = (($this->getStackCount($stackerName)) == 0);
// Return result
* @return $count Size of stack (array count)
* @throws NoStackerException If given stack is missing
*/
- protected final function getStackCount ($stackerName) {
+ public final function getStackCount ($stackerName) {
// Is the stack not yet initialized?
if (!$this->isStackInitialized($stackerName)) {
// Throw an exception
return $value;
}
+ /**
+ * Get first value from named stacker
+ *
+ * @param $stackerName Name of the stack
+ * @return $value Value of last added value
+ * @throws NoStackerException If the named stacker was not found
+ * @throws EmptyStackerException If the named stacker is empty
+ */
+ protected final function getFirstValue ($stackerName) {
+ // Is the stack not yet initialized or full?
+ if (!$this->isStackInitialized($stackerName)) {
+ // Throw an exception
+ throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
+ } elseif ($this->isStackEmpty($stackerName)) {
+ //Throw an exception
+ throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
+ }
+
+ // Now get the last value
+ $value = $this->stacks[$stackerName]['entries'][0];
+
+ // Return it
+ return $value;
+ }
+
/**
* "Pops" last entry from stack
*
// Now, remove the last entry, we don't care about the return value here, see elseif() block above
array_pop($this->stacks[$stackerName]['entries']);
}
+
+ /**
+ * "Pops" first entry from stack
+ *
+ * @param $stackerName Name of the stack
+ * @return void
+ * @throws NoStackerException If the named stacker was not found
+ * @throws EmptyStackerException If the named stacker is empty
+ */
+ protected final function popFirst ($stackerName) {
+ // Is the stack not yet initialized or full?
+ if (!$this->isStackInitialized($stackerName)) {
+ // Throw an exception
+ throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
+ } elseif ($this->isStackEmpty($stackerName)) {
+ //Throw an exception
+ throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
+ }
+
+ // Now, remove the last entry, we don't care about the return value here, see elseif() block above
+ array_shift($this->stacks[$stackerName]['entries']);
+ }
}
// [EOF]