#import <ObjectiveLib/Iterator.h>
Inheritance diagram for OLIterator:
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. |
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.
+ (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.
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.
object | the object to assign |
Reimplemented in OLDequeIterator, OLReverseBidiIterator, OLBackInsertIterator, OLFrontInsertIterator, OLInsertIterator, OLAssociativeIterator, OLArrayIterator, OLHashIterator, OLListIterator, and OLBitIterator.
- (id) copy |
Make 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.
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.
first | the first in the series | |
last | the last in the series |
- (BOOL) isEqual: | (id) | object |
Return whether this object is equal to another one.
object | the object to test |
Reimplemented in OLDequeIterator, OLReverseBidiIterator, OLReverseRandomIterator, OLBackInsertIterator, OLFrontInsertIterator, OLInsertIterator, OLAssociativeIterator, OLArrayIterator, OLHashIterator, OLListIterator, and OLBitIterator.
|