OLStack Class Reference
[Containers]

A first-in-last-out collection. More...

#import <ObjectiveLib/Stack.h>

Inheritance diagram for OLStack:

Inheritance graph
[legend]
List of all members.

Public Member Functions

(int) - compare:
 Compare this stack to another object.
(id) - copy
 Make a copy of this stack.
(BOOL) - empty
 Test whether the stack is empty.
(BOOL) - isEqual:
 Return whether this stack is equal to another one.
(void) - pop
 Remove the item at the top of the stack.
(void) - push:
 Add an item to the top of the stack.
(unsigned) - size
 Return the number of elements in the stack.
(id) - top
 Return the element at the top of the stack.
(void) - writeSelfToStream:
 Write the object to a stream.
Initializers and Deallocators
(id) - free
 Finalize the stack and deallocate any allocated memory.
(id) - init
 Initialize the stack.
(id) - initWithObjectInStream:
 Initialize the object.
(id) - initWithStack:
 Initialize the stack.

Static Public Member Functions

(id) + stack
 Create and return a new stack.
(id) + stackWithStack:
 Create and return a new stack.

Protected Attributes

OLDequedeque
 The container that provides the underlying data structure.

Detailed Description

A first-in-last-out collection.

Elements are added to and removed from the top of a stack. Access is provided to the top (OLStack) element of the stack, which is also the most recently added item. The stack class just provides a restricted view of the underlying container OLDeque for occasions when only the simple functionality of a FILO collection is required. It is not a true container because it does not provide iterators, so it cannot be used with generic algorithms.

See also:
OLDeque, OLQueue


Member Function Documentation

- (int) compare: (id)  other  

Compare this stack to another object.

If the other object is of type OLStack, each of the contained objects is compared to the corresponding object in other by calling the compare: method.

Parameters:
other the object with which to compare this one
Returns:
a value greater than, equal to, or less than zero accoringly as this object is greater than, equal to, or less than other

- (id) copy  

Make a copy of this stack.

Returns:
the copy

- (BOOL) empty  

Test whether the stack is empty.

Returns:
YES if the stack is empty, NO otherwise

- (id) free  

Finalize the stack and deallocate any allocated memory.

- (id) init  

Initialize the stack.

The stack is initially empty.

Returns:
a reference to this stack

- (id) initWithObjectInStream: (OLObjectInStream *)  stream  

Initialize the object.

Each instance variable is read from stream and all other initialization is performed.

Parameters:
stream the stream from which to read
Returns:
a reference to this object

Reimplemented from < OLStreamable >.

- (id) initWithStack: (OLStack *)  stack  

Initialize the stack.

All objects are copied from stack into this stack.

Parameters:
stack the stack that should be copied
Returns:
a reference to this stack

- (BOOL) isEqual: (id)  object  

Return whether this stack is equal to another one.

Two stacks are considered equal if they both contain the same number of objects that all return YES to the message isEqual: and they are in the same order.

Parameters:
object the object to test
Returns:
YES if object is equal to this stack

- (void) pop  

Remove the item at the top of the stack.

The element returned by the message top is removed from the stack.

Precondition:
The stack cannot be empty.

- (void) push: (id)  object  

Add an item to the top of the stack.

The element object will be added to the top of the stack and can be accessed with the message top.

Parameters:
object the element to add

- (unsigned) size  

Return the number of elements in the stack.

Returns:
the number of elements

+ (id) stack  

Create and return a new stack.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Returns:
a new stack

+ (id) stackWithStack: (OLStack *)  right  

Create and return a new stack.

The stack is initialized with the contents of right.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
right the stack to copy into the new one
Returns:
a new stack

- (id) top  

Return the element at the top of the stack.

The element returned is the one removed by the message pop and is also the most recently added element.

Returns:
the top element

- (void) writeSelfToStream: (OLObjectOutStream *)  stream  

Write the object to a stream.

All instance variables are written to stream.

Parameters:
stream the stream to which to write.

Reimplemented from < OLStreamable >.


Member Data Documentation

- (OLDeque*) deque [protected]

The container that provides the underlying data structure.


The documentation for this class was generated from the following file:
ObjectiveLibGenerated Sun Apr 22 15:19:05 2007, © 2004-2007 Will Mason
SourceForge.net Logo