Class TStack

Description

Implements interfaces:

  • IteratorAggregate (internal interface)
  • Countable (internal interface)

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,

  1.  foreach($stack as $item...

  • author: Qiang Xue <qiang.xue@gmail.com>
  • version: $Id: TStack.php 2996 2011-06-20 15:24:57Z ctrlaltca@gmail.com $
  • since: 3.0

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.

  • throws: TInvalidDataTypeException If data is not null and neither an array nor an iterator.
  • access: public
TStack __construct ([array|Iterator $data = null])
  • array|Iterator $data: the initial 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.

  • throws: TInvalidDataTypeException If data is neither an array nor a Traversable.
  • access: public
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 ()

Implementation of:
Countable::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 ()

Implementation of:
IteratorAggregate::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
  • throws: TInvalidOperationException if the stack is empty
  • access: public
mixed peek ()
pop (line 125)

Pops up the item at the top of the stack.

  • return: the item at the top of the stack
  • throws: TInvalidOperationException if the stack is empty
  • access: public
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::__call()
TComponent::__get()
TComponent::__set()
TComponent::__sleep()
TComponent::__wakeup()

Documentation generated on Mon, 25 Jun 2012 14:39:19 +0200 by phpDocumentor 1.4.3