EDStack


Inherits From:
NSObject
Declared In:
EDStack.h


Class Description

From a purely functional point EDStack does not add anything to NSArray. However, EDStack clarifies the indended use of the datastructure. Note that it is not a subclass of NSMutableArray; something you might expect if you are familiar with Java. (See Martin Fowler "Refactoring" p. 352 for a good explanation why the Java way is "wrong.")

This datastructure does not implement the copying and coding protocols as stacks are usually required in the context of algorithms, rather than data storage.


Instance Variables

NSMutableArray *storage;

storageAll instance variables are private.


Method Types

Creating stacks
+ stack
+ stackWithObject:
- init
- initWithObject:
Adding/removing objects
- pushObject:
- popObject
- clear
Querying the stack
- topObject
- topObjects:
- count


Class Methods

stack

+ (EDStack *)stack

Creates and returns an empty stack.


stackWithObject:

+ (EDStack *)stackWithObject:(id)anObject

Creates and returns a stack with a single object on it.


Instance Methods

clear

- (void)clear

Removes all objects from the stack. Each removed object is sent a release message.


count

- (unsigned int)count

Returns the number of objects on the stack.


init

- (id)init

Initialises a newly allocated stack.


initWithObject:

- (id)initWithObject:(id)anObject

Initialises a newly allocated stack by adding anObject to it. The object receives a retain message.


popObject

- (id)popObject

Removes and returns the topmost object from the stack. The object receives a release message. If the stack is empty this method returns nil.


pushObject:

- (void)pushObject:(id)anObject

Pushes anObject onto the stack. The object receives a retain message.


topObject

- (id)topObject

Returns the topmost object on the stack, or nil if the stack is empty.


topObjects:

- (NSArray *)topObjects:(int)count

Returns an array containing the n topmost object on the stack. Raises an exception if n is greater than the value returned by count.


Version 2.0 Copyright ©2002. All Rights Reserved.