OLIterator Class Reference
[Iterators]

An abstract base class for iterators. More...

#import <ObjectiveLib/Iterator.h>

Inheritance diagram for OLIterator:

Inheritance graph
[legend]
List of all members.

Public Member Functions

(id) - assign:
 Assign an object to the position in the controlled sequence to which this iterator refers.
(id) - copy
 Make a copy of this iterator.
(id) - dereference
 Dereference the iterator.
(BOOL) - isEqual:
 Return whether this object is equal to another one.

Static Public Member Functions

(void) + advanceIterator:distance:
 Advance the iterator by a certain distance.
(unsigned) + distanceFrom:to:
 Compute the distance that exists between two iterators.

Detailed Description

An abstract base class for iterators.

Iterators exist to travsere the objects that are held in containers. All iterators share the ability retrieve a reference to the object to which they point and to assign an object to the iterator's position in its container. How they differ is in how they are able to move through their containers. Some iterators can only go forward (OLForwardIterator), some can go forward and backward (OLBidirectionalIterator), and some can move at will (OLRandomAccessIterator). Additionally there are specialized iterators for inserting elements into a container (rather than simply assigning to elements already in the container) and for reversing the motion of other iterators.

Note that by convention a pair of iterators first and last describing a range of elements refers to the range [first, last). That is, the last iterator points to a position one step beyond the range under consideration.


Member Function Documentation

+ (void) advanceIterator: (OLIterator *)  itor
distance: (int)  count 

Advance the iterator by a certain distance.

The message tests the iterator for its type and chooses the most efficient method available for advancing the iterator. If the iterator is not a type of OLRandomAccessIterator, then its advance or reverse messages will simply be sent enough to times to complete the operation. If the iterator cannot support the operation, for example if count is negative and the iterator is not a OLBidirectionalIterator, then the message will simply return.

Parameters:
itor the iterator to advance
count the number of positions to advance (or reverse) the iterator

- (id) assign: (id)  object  

Assign an object to the position in the controlled sequence to which this iterator refers.

The object currently at the position will be removed and replaced with the given object.

Parameters:
object the object to assign
Returns:
a reference to this iterator

Reimplemented in OLDequeIterator, OLReverseBidiIterator, OLBackInsertIterator, OLFrontInsertIterator, OLInsertIterator, OLAssociativeIterator, OLArrayIterator, OLHashIterator, OLListIterator, and OLBitIterator.

- (id) copy  

Make a copy of this iterator.

Returns:
a copy of this iterator

Reimplemented in OLDequeIterator, OLReverseBidiIterator, OLReverseRandomIterator, OLBackInsertIterator, OLFrontInsertIterator, OLInsertIterator, OLAssociativeIterator, OLArrayIterator, OLHashIterator, OLListIterator, and OLBitIterator.

- (id) dereference  

Dereference the iterator.

Return the id of the object to which this iterator points.

Returns:
the id of the referenced object

Reimplemented in OLDequeIterator, OLReverseBidiIterator, OLAssociativeIterator, OLArrayIterator, OLHashIterator, OLListIterator, and OLBitIterator.

+ (unsigned) distanceFrom: (OLIterator *)  first
to: (OLIterator *)  last 

Compute the distance that exists between two iterators.

The distance is computed using the most efficient means possible given the type of iterator. For example, random access iterators can compute distances in one step, while forward iterators must be advance multiple times to find a distance.

Precondition:
The iterators must refer to the same container and first must be before last in the sequence.
Parameters:
first the first in the series
last the last in the series
Returns:
the distance from first to last

- (BOOL) isEqual: (id)  object  

Return whether this object is equal to another one.

Parameters:
object the object to test
Returns:
YES if the iterator is equal to the object, NO if not

Reimplemented in OLDequeIterator, OLReverseBidiIterator, OLReverseRandomIterator, OLBackInsertIterator, OLFrontInsertIterator, OLInsertIterator, OLAssociativeIterator, OLArrayIterator, OLHashIterator, OLListIterator, and OLBitIterator.


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