## Class TStack

Description

Implements interfaces:

TStack class

TStack implements a stack.

The typical stack operations are implemented, which include push(), pop() and peek(). In addition, contains() can be used to check if an item is contained in the stack. To obtain the number of the items in the stack, check the Count property.

Items in the stack may be traversed using foreach as follows,

     foreach($stack as $item) ...

- since: 3.0
- version: $Id: TStack.php 1398 2006-09-08 19:31:03Z xue $
- author: Qiang Xue <qiang.xue@gmail.com>

Located in /Collections/TStack.php (line 34)

    TComponent
       |
       --TStack

Method Summary
TStack __construct ([array|Iterator $data = null])
void clear ()
boolean contains (mixed $item)
void copyFrom (mixed $data)
integer count ()
integer getCount ()
Iterator getIterator ()
mixed peek ()
mixed pop ()
void push (mixed $item)
array toArray ()
Methods
Constructor __construct (line 53)

Constructor.

Initializes the stack with an array or an iterable object.

- access: public
- throws: TInvalidDataTypeException If data is not null and neither an array nor an iterator.

TStack __construct ([array|Iterator $data = null])

- array|Iterator $data: the intial data. Default is null, meaning no initialization.

clear (line 91)

Removes all items in the stack.

- access: public

void clear ()
contains (line 101)

- return: whether the stack contains the item
- access: public

boolean contains (mixed $item)

- mixed $item: the item

copyFrom (line 73)

Copies iterable data into the stack.

Note, existing data in the list will be cleared first.

- access: public
- throws: TInvalidDataTypeException If data is neither an array nor a Traversable.

void copyFrom (mixed $data)

- mixed $data: the data to be copied from, must be an array or object implementing Traversable

count (line 169)

Returns the number of items in the stack.

This method is required by Countable interface.

- return: number of items in the stack.
- access: public

integer count ()
getCount (line 159)

- return: the number of items in the stack
- access: public

integer getCount ()
getIterator (line 151)

Returns an iterator for traversing the items in the stack.

This method is required by the interface IteratorAggregate.

- return: an iterator for traversing the items in the stack.
- access: public

Iterator getIterator ()
peek (line 112)

Returns the item at the top of the stack.

Unlike pop(), this method does not remove the item from the stack.

- return: item at the top of the stack
- access: public
- throws: TInvalidOperationException if the stack is empty

mixed peek ()
pop (line 125)

Pops up the item at the top of the stack.

- return: the item at the top of the stack
- access: public
- throws: TInvalidOperationException if the stack is empty

mixed pop ()
push (line 140)

Pushes an item into the stack.

- access: public

void push (mixed $item)

- mixed $item: the item to be pushed into the stack

toArray (line 62)

- return: the list of items in stack
- access: public

array toArray ()

#### Inherited Methods

Inherited From TComponent

> TComponent::addParsedObject()
> TComponent::attachEventHandler()
> TComponent::canGetProperty()
> TComponent::canSetProperty()
> TComponent::createdOnTemplate()
> TComponent::detachEventHandler()
> TComponent::evaluateExpression()
> TComponent::evaluateStatements()
> TComponent::getEventHandlers()
> TComponent::getSubProperty()
> TComponent::hasEvent()
> TComponent::hasEventHandler()
> TComponent::hasProperty()
> TComponent::raiseEvent()
> TComponent::setSubProperty()
> TComponent::__get()
> TComponent::__set()

Documentation generated on Sun, 14 Jan 2007 21:44:28 -0500 by phpDocumentor 1.3.0RC4