Index: src/OFEnumerator.h ================================================================== --- src/OFEnumerator.h +++ src/OFEnumerator.h @@ -15,10 +15,11 @@ */ #import "OFObject.h" @class OFEnumerator; +@class OFArray; /*! * @brief A protocol for getting an enumerator for the object. */ @protocol OFEnumerating @@ -40,10 +41,17 @@ * * @return The next object */ - (id)nextObject; +/*! + * @brief Returns an array of all remaining objects in the collection. + * + * @return An array of all remaining objects in the collection + */ +- (OFArray*)allObjects; + /*! * @brief Resets the enumerator, so the next call to nextObject returns the * first object again. */ - (void)reset; Index: src/OFEnumerator.m ================================================================== --- src/OFEnumerator.m +++ src/OFEnumerator.m @@ -17,10 +17,13 @@ #include "config.h" #include #import "OFEnumerator.h" +#import "OFArray.h" + +#import "autorelease.h" @implementation OFEnumerator - init { if (object_getClass(self) == [OFEnumerator class]) { @@ -39,12 +42,28 @@ - (id)nextObject { [self doesNotRecognizeSelector: _cmd]; abort(); } + +- (OFArray*)allObjects +{ + OFMutableArray *ret = [OFMutableArray array]; + void *pool = objc_autoreleasePoolPush(); + id object; + + while ((object = [self nextObject]) != nil) + [ret addObject: object]; + + [ret makeImmutable]; + + objc_autoreleasePoolPop(pool); + + return ret; +} - (void)reset { [self doesNotRecognizeSelector: _cmd]; abort(); } @end