ObjectiveLib  1.0.0
Public Member Functions | Static Public Member Functions | Protected Attributes
OLStack Class Reference

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) - copyWithZone:
 Make a copy of this stack allocating memory from the given zone.
(BOOL) - empty
 Test whether the stack is empty.
(void) - encodeWithCoder:
 Encode the stack.
(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) - init
 Initialize the stack.
(id) - initWithCoder:
 Initialize the stack.
(id) - initWithObjectInStream:
 Initialize the object.
(id) - initWithStack:
 Initialize the stack.
(void) - dealloc
 Finalize the stack and deallocate any allocated memory.

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:
otherthe 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) copyWithZone: (NSZone *)  zone

Make a copy of this stack allocating memory from the given zone.

Parameters:
zonethe zone from which to allocate memory
Returns:
the copy
- (void) dealloc

Finalize the stack and deallocate any allocated memory.

- (BOOL) empty

Test whether the stack is empty.

Returns:
YES if the stack is empty, NO otherwise
- (void) encodeWithCoder: (NSCoder *)  encoder

Encode the stack.

The stack is saved to an archive using encoder. The stack will be retrieved from the archive using the initializer initWithCoder:.

Parameters:
encoderthe coder which will save the bit stack to the archive
- (id) init

Initialize the stack.

The stack is initially empty.

Returns:
a reference to this stack
- (id) initWithCoder: (NSCoder *)  decoder

Initialize the stack.

This initializer creates a new stack from an archive and returns it.

Postcondition:
The stack returned will be identical to the stack saved to the archive using the encodeWithCoder: message.
Parameters:
decoderthe coder which will decode the archived stack
Returns:
a reference to this stack

Initialize the object.

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

Parameters:
streamthe 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:
stackthe 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:
objectthe 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:
objectthe 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:
rightthe 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:
streamthe 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 Sat Feb 15 2014 07:45:35, © 2004-2007 Will Mason