TypedStack
Class: TypedStack
@include <TypedStack>
Stack which enforces type restrictions on its elements
The type must be set before adding any elements to the stack. Once elements have been added, the type cannot be changed.
Methods
@TypedStack.set_type
Scope: public
Set the type of elements that this stack will hold.
This method must be called before adding elements to the stack. The stack’s type cannot be changed after elements have been added.
Returns: 1 if the type cannot be changed, 0 otherwise.
Usage: @TypedStack.set_type $type
Parameters
type- Type:
Primitive - The type to enforce for the elements of this stack.
- Type:
@TypedStack.push
Scope: public
Add a value to the top of the stack, enforcing the specified type.
Returns: 1 if the value is of the wrong type, 0 otherwise.
Usage: @TypedStack.push $value
Parameters
value- Type:
Primitive - The value to add to the stack.
- Type:
@TypedStack.size
Scope: public
Echo the number of elements in the stack.
Outputs: The number of elements in the stack.
Usage: @TypedStack.size
@TypedStack.pop
Scope: public
Pop the top element off the stack and echo it.
Returns: 1 if the stack is empty, 0 otherwise.
Outputs: The value at the top of the stack.
Usage: @TypedStack.pop
@TypedStack.top
Scope: public
Echo the top element of the stack without removing it.
Returns: 1 if the stack is empty, 0 otherwise.
Outputs: The value at the top of the stack.
Usage: @TypedStack.top
@TypedStack.clear
Scope: public
Clear the stack by removing all elements.
Usage: @TypedStack.clear
@TypedStack.empty
Scope: public
Silently check whether the stack is empty.
Returns: 0 if the stack is empty, 1 otherwise.
Outputs: nothing
Usage: @TypedStack.empty