1995-03-12 15:39:56 +00:00
|
|
|
/* Implementation of NSArray for GNUStep
|
|
|
|
Copyright (C) 1994, 1995 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
|
|
|
Date: August 1994
|
|
|
|
|
|
|
|
This file is part of the GNU Objective C Class Library.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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
|
|
|
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <objects/stdobjects.h>
|
1994-11-08 16:44:01 +00:00
|
|
|
#include <foundation/NSArray.h>
|
1995-04-03 03:18:43 +00:00
|
|
|
#include <objects/Array.h>
|
1995-04-03 22:55:36 +00:00
|
|
|
#include <limits.h>
|
1994-11-08 16:44:01 +00:00
|
|
|
|
1995-04-03 03:18:43 +00:00
|
|
|
@interface NSArray (libobjects) <IndexedCollecting>
|
|
|
|
@end
|
1994-11-08 16:44:01 +00:00
|
|
|
|
1995-04-03 03:18:43 +00:00
|
|
|
@implementation NSArray
|
1994-11-08 16:44:01 +00:00
|
|
|
|
|
|
|
+ (id) array
|
|
|
|
{
|
|
|
|
return [[[self alloc] init] autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (id) arrayWithObject: anObject
|
|
|
|
{
|
|
|
|
return [[[[self alloc] init] addObject: anObject] autorelease];
|
|
|
|
}
|
|
|
|
|
1995-04-03 22:55:36 +00:00
|
|
|
+ (id) arrayWithObjects: firstObject, ...
|
1994-11-08 16:44:01 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
Array *n = [[self alloc] init];
|
|
|
|
id o;
|
|
|
|
|
|
|
|
[n addObject:firstObject];
|
|
|
|
va_start(ap, firstObject);
|
|
|
|
while ((o = va_arg(ap, id)))
|
|
|
|
[n addObject:o];
|
|
|
|
va_end(ap);
|
|
|
|
return [n autorelease];
|
|
|
|
}
|
|
|
|
|
1995-04-03 03:18:43 +00:00
|
|
|
- (id) initWithCapacity: (unsigned)cap
|
|
|
|
{
|
|
|
|
[self notImplemented:_cmd];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1994-11-08 16:44:01 +00:00
|
|
|
- (id) initWithArray: (NSArray*)array
|
|
|
|
{
|
|
|
|
int i, c;
|
|
|
|
|
|
|
|
c = [array count];
|
1995-04-03 03:18:43 +00:00
|
|
|
[self initWithCapacity:c];
|
1994-11-08 16:44:01 +00:00
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
[self addObject:[array objectAtIndex:i]];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithObjects: (id)firstObject, ...
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
id o;
|
|
|
|
|
|
|
|
[super init];
|
|
|
|
[self addObject:firstObject];
|
|
|
|
va_start(ap, firstObject);
|
|
|
|
while ((o = va_arg(ap, id)))
|
|
|
|
[self addObject:o];
|
|
|
|
va_end(ap);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithObjects: (id*)objects count: (unsigned int)count
|
|
|
|
{
|
|
|
|
[self initWithCapacity:count];
|
|
|
|
while (count--)
|
|
|
|
[self addObject:objects[count]];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) containsObject: (id)candidate
|
|
|
|
{
|
|
|
|
return [self includesObject:candidate];
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
- (unsigned) count; /* inherited */
|
|
|
|
- (unsigned) indexOfObject: (id)anObject; /* inherited */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
- (unsigned) indexOfObjectIdenticalTo: (id)anObject
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < _count; i++)
|
1995-04-03 22:55:36 +00:00
|
|
|
if (anObject == _contents_array[i].id_u)
|
1994-11-08 16:44:01 +00:00
|
|
|
return i;
|
|
|
|
return UINT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
- (id) lastObject; /* inherited */
|
1995-04-03 03:18:43 +00:00
|
|
|
- (id) objectAtIndex: (unsigned)index; /* inherited */
|
1994-11-08 16:44:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
- (NSEnumerator*) objectEnumerator
|
|
|
|
{
|
|
|
|
[self notImplemented:_cmd];
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSEnumerator*) reverseObjectEnumerator
|
|
|
|
{
|
|
|
|
[self notImplemented:_cmd];
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
- (void) makeObjectsPerform: (SEL)aSelector;
|
|
|
|
- (void) makeObjectsPerform: (SEL)aSelector withObject: (id)anObject;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
- (id) firstObjectCommonWithArray: (NSArray*)otherArray
|
|
|
|
{
|
|
|
|
BOOL is_in_otherArray (id o)
|
|
|
|
{
|
|
|
|
return [otherArray containsObject:o];
|
|
|
|
}
|
1995-04-03 22:55:36 +00:00
|
|
|
id none_found(arglist_t a)
|
1994-11-08 16:44:01 +00:00
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
return [self detectObjectByCalling:is_in_otherArray
|
|
|
|
ifNoneCall:none_found];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isEqualToArray: (NSArray*)otherArray
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (_count != [otherArray count])
|
|
|
|
return NO;
|
|
|
|
for (i = 0; i < _count; i++)
|
1995-04-03 22:55:36 +00:00
|
|
|
if ([_contents_array[i].id_u isEqual:[otherArray objectAtIndex:i]])
|
1994-11-08 16:44:01 +00:00
|
|
|
return NO;
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*) sortedArrayUsingFunction: (int(*)(id,id,void*))comparator
|
|
|
|
context: (void*)context
|
|
|
|
{
|
|
|
|
id n = [self copy];
|
|
|
|
int compare(id o1, id o2)
|
|
|
|
{
|
|
|
|
return comparator(o1, o2, context);
|
|
|
|
}
|
|
|
|
[n sortObjectsByCalling:compare];
|
|
|
|
return [n autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*) sortedArrayUsingSelector: (SEL)comparator
|
|
|
|
{
|
|
|
|
id n = [self copy];
|
|
|
|
int compare(id o1, id o2)
|
|
|
|
{
|
1995-04-03 22:55:36 +00:00
|
|
|
return (int) [o1 perform:comparator with:o2];
|
1994-11-08 16:44:01 +00:00
|
|
|
}
|
|
|
|
[n sortObjectsByCalling:compare];
|
|
|
|
return [n autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*) subarrayWithRange: (NSRange)range
|
|
|
|
{
|
|
|
|
id n = [self emptyCopy];
|
|
|
|
[self notImplemented:_cmd];
|
|
|
|
return [n autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) componentsJoinedByString: (NSString*)separator
|
|
|
|
{
|
1995-03-12 15:39:56 +00:00
|
|
|
[self notImplemented:_cmd];
|
|
|
|
return nil;
|
1994-11-08 16:44:01 +00:00
|
|
|
}
|
|
|
|
|
1995-04-03 03:18:43 +00:00
|
|
|
- (NSString*) description
|
|
|
|
{
|
|
|
|
[self notImplemented:_cmd];
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
1994-11-08 16:44:01 +00:00
|
|
|
@end
|