2001-12-17 14:31:42 +00:00
|
|
|
/** NSEnumerator abstrace class for GNUStep
|
1996-02-01 17:04:17 +00:00
|
|
|
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
|
1995-04-09 01:28:47 +00:00
|
|
|
|
1996-04-17 20:17:45 +00:00
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
1995-04-09 01:28:47 +00:00
|
|
|
Date: March 1995
|
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
1995-04-09 01:28:47 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1995-04-09 01:28:47 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
1999-09-09 02:56:20 +00:00
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
2001-12-18 16:54:15 +00:00
|
|
|
|
|
|
|
<title>NSEnumerator class reference</title>
|
|
|
|
$Date$ $Revision$
|
1995-04-09 01:28:47 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-07 01:24:41 +00:00
|
|
|
#include "config.h"
|
2003-07-31 23:49:32 +00:00
|
|
|
#include "GNUstepBase/preface.h"
|
2003-06-07 01:24:41 +00:00
|
|
|
#include "Foundation/NSUtilities.h"
|
|
|
|
#include "Foundation/NSArray.h"
|
1995-04-09 01:28:47 +00:00
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Simple class for iterating over a collection of objects, usually returned
|
|
|
|
* from an [NSArray] or similar.
|
|
|
|
*/
|
1995-04-09 01:28:47 +00:00
|
|
|
@implementation NSEnumerator
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Returns all objects remaining in the enumeration as an array.
|
|
|
|
*/
|
2001-10-15 14:42:56 +00:00
|
|
|
- (NSArray*) allObjects
|
2001-01-03 11:22:59 +00:00
|
|
|
{
|
2001-10-15 14:42:56 +00:00
|
|
|
NSMutableArray *array;
|
|
|
|
id obj;
|
|
|
|
SEL nsel;
|
|
|
|
IMP nimp;
|
|
|
|
SEL asel;
|
|
|
|
IMP aimp;
|
|
|
|
|
|
|
|
array = [NSMutableArray arrayWithCapacity: 10];
|
|
|
|
|
|
|
|
nsel = @selector(nextObject);
|
|
|
|
nimp = [self methodForSelector: nsel];
|
|
|
|
asel = @selector(addObject:);
|
|
|
|
aimp = [array methodForSelector: asel];
|
|
|
|
|
|
|
|
while ((obj = (*nimp)(self, nsel)) != nil)
|
|
|
|
{
|
|
|
|
(*aimp)(array, asel, obj);
|
|
|
|
}
|
2001-01-03 11:22:59 +00:00
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
/**
|
|
|
|
* Returns next object in enumeration, or nil if none remain. Use code like
|
|
|
|
* <code>while (object = [enumerator nextObject]) { ... }</code>.
|
|
|
|
*/
|
1995-04-09 01:28:47 +00:00
|
|
|
- (id) nextObject
|
|
|
|
{
|
1996-02-01 17:04:17 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1995-04-09 01:28:47 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|