mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Divide methods between NSArray and NSArrayNonCore classes. Add
NSArrayNonCore behavior to NSArray. Divide methods between NSMutableArray and NSMutableArrayNonCore classes. Add NSArrayNonCore behavior to NSArray. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1323 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
209321a123
commit
048f55528d
1 changed files with 135 additions and 109 deletions
244
Source/NSArray.m
244
Source/NSArray.m
|
@ -29,66 +29,30 @@
|
||||||
#include <Foundation/NSUtilities.h>
|
#include <Foundation/NSUtilities.h>
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
|
|
||||||
@interface NSArrayEnumerator : NSEnumerator
|
@class NSArrayEnumerator;
|
||||||
{
|
@class NSArrayEnumeratorReverse;
|
||||||
id array;
|
|
||||||
int next_index;
|
@interface NSArrayNonCore : NSArray
|
||||||
}
|
|
||||||
@end
|
@end
|
||||||
|
@interface NSMutableArrayNonCore : NSMutableArray
|
||||||
@interface NSArrayEnumeratorReverse : NSArrayEnumerator
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation NSArrayEnumerator
|
|
||||||
|
|
||||||
- initWithArray: (NSArray*)anArray
|
|
||||||
{
|
|
||||||
[super init];
|
|
||||||
array = anArray;
|
|
||||||
[array retain];
|
|
||||||
next_index = 0;
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) nextObject
|
|
||||||
{
|
|
||||||
if (next_index >= [array count])
|
|
||||||
return nil;
|
|
||||||
return [array objectAtIndex:next_index++];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) dealloc
|
|
||||||
{
|
|
||||||
[array release];
|
|
||||||
[super dealloc];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation NSArrayEnumeratorReverse
|
|
||||||
|
|
||||||
- initWithArray: (NSArray*)anArray
|
|
||||||
{
|
|
||||||
[super init];
|
|
||||||
array = anArray;
|
|
||||||
[array retain];
|
|
||||||
next_index = [array count]-1;
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) nextObject
|
|
||||||
{
|
|
||||||
if (next_index < 0)
|
|
||||||
return nil;
|
|
||||||
return [array objectAtIndex:next_index--];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@implementation NSArray
|
|
||||||
|
|
||||||
static Class NSArray_concrete_class;
|
static Class NSArray_concrete_class;
|
||||||
static Class NSMutableArray_concrete_class;
|
static Class NSMutableArray_concrete_class;
|
||||||
|
|
||||||
|
|
||||||
|
@implementation NSArray
|
||||||
|
|
||||||
|
+ (void) initialize
|
||||||
|
{
|
||||||
|
if (self == [NSArray class])
|
||||||
|
{
|
||||||
|
NSArray_concrete_class = [NSGArray class];
|
||||||
|
NSMutableArray_concrete_class = [NSGMutableArray class];
|
||||||
|
behavior_class_add_class (self, [NSArrayNonCore class]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+ (void) _setConcreteClass: (Class)c
|
+ (void) _setConcreteClass: (Class)c
|
||||||
{
|
{
|
||||||
NSArray_concrete_class = c;
|
NSArray_concrete_class = c;
|
||||||
|
@ -109,17 +73,35 @@ static Class NSMutableArray_concrete_class;
|
||||||
return NSMutableArray_concrete_class;
|
return NSMutableArray_concrete_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (void) initialize
|
|
||||||
{
|
|
||||||
NSArray_concrete_class = [NSGArray class];
|
|
||||||
NSMutableArray_concrete_class = [NSGMutableArray class];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ allocWithZone: (NSZone*)z
|
+ allocWithZone: (NSZone*)z
|
||||||
{
|
{
|
||||||
return NSAllocateObject([self _concreteClass], 0, z);
|
return NSAllocateObject ([self _concreteClass], 0, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This is the designated initializer for NSArray. */
|
||||||
|
- initWithObjects: (id*)objects count: (unsigned)count
|
||||||
|
{
|
||||||
|
[self subclassResponsibility:_cmd];
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (unsigned) count
|
||||||
|
{
|
||||||
|
[self subclassResponsibility:_cmd];
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
- objectAtIndex: (unsigned)index
|
||||||
|
{
|
||||||
|
[self subclassResponsibility:_cmd];
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation NSArrayNonCore
|
||||||
|
|
||||||
+ array
|
+ array
|
||||||
{
|
{
|
||||||
return [[[self alloc] init]
|
return [[[self alloc] init]
|
||||||
|
@ -171,13 +153,6 @@ static Class NSMutableArray_concrete_class;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* This is the designated initializer for NSArray. */
|
|
||||||
- initWithObjects: (id*)objects count: (unsigned)count
|
|
||||||
{
|
|
||||||
[self subclassResponsibility:_cmd];
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Not very pretty... */
|
/* Not very pretty... */
|
||||||
#define INITIAL_OBJECTS_SIZE 10
|
#define INITIAL_OBJECTS_SIZE 10
|
||||||
- initWithObjects: firstObject rest: (va_list)ap
|
- initWithObjects: firstObject rest: (va_list)ap
|
||||||
|
@ -236,18 +211,6 @@ static Class NSMutableArray_concrete_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (unsigned) count
|
|
||||||
{
|
|
||||||
[self subclassResponsibility:_cmd];
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
- objectAtIndex: (unsigned)index
|
|
||||||
{
|
|
||||||
[self subclassResponsibility:_cmd];
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (unsigned) indexOfObjectIdenticalTo:anObject
|
- (unsigned) indexOfObjectIdenticalTo:anObject
|
||||||
{
|
{
|
||||||
int i, c = [self count];
|
int i, c = [self count];
|
||||||
|
@ -435,17 +398,18 @@ static Class NSMutableArray_concrete_class;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation NSMutableArray: NSArray
|
|
||||||
|
@implementation NSMutableArray
|
||||||
|
|
||||||
|
+ (void) initialize
|
||||||
|
{
|
||||||
|
if (self == [NSMutableArray class])
|
||||||
|
behavior_class_add_class (self, [NSMutableArrayNonCore class]);
|
||||||
|
}
|
||||||
|
|
||||||
+ allocWithZone: (NSZone*)z
|
+ allocWithZone: (NSZone*)z
|
||||||
{
|
{
|
||||||
return NSAllocateObject([self _mutableConcreteClass], 0, z);
|
return NSAllocateObject ([self _mutableConcreteClass], 0, z);
|
||||||
}
|
|
||||||
|
|
||||||
+ arrayWithCapacity: (unsigned)numItems
|
|
||||||
{
|
|
||||||
return [[[self alloc] initWithCapacity:numItems]
|
|
||||||
autorelease];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is the desgnated initializer for NSMutableArray */
|
/* This is the desgnated initializer for NSMutableArray */
|
||||||
|
@ -455,24 +419,6 @@ static Class NSMutableArray_concrete_class;
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* Not in OpenStep. */
|
|
||||||
- (void) addObjects: (id*)objects count: (unsigned)count
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Override our superclass's designated initializer to go our's */
|
|
||||||
- initWithObjects: (id*)objects count: (unsigned)count
|
|
||||||
{
|
|
||||||
/* xxx Could be made more efficient by increasing capacity all at once. */
|
|
||||||
int i;
|
|
||||||
self = [self initWithCapacity:count];
|
|
||||||
for (i = 0; i < count; i++)
|
|
||||||
[self addObject:objects[i]];
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) addObject: anObject
|
- (void) addObject: anObject
|
||||||
{
|
{
|
||||||
[self subclassResponsibility:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
|
@ -493,6 +439,28 @@ static Class NSMutableArray_concrete_class;
|
||||||
[self subclassResponsibility:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation NSMutableArrayNonCore
|
||||||
|
|
||||||
|
+ arrayWithCapacity: (unsigned)numItems
|
||||||
|
{
|
||||||
|
return [[[self alloc] initWithCapacity:numItems]
|
||||||
|
autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Override our superclass's designated initializer to go our's */
|
||||||
|
- initWithObjects: (id*)objects count: (unsigned)count
|
||||||
|
{
|
||||||
|
/* xxx Could be made more efficient by increasing capacity all at once. */
|
||||||
|
int i;
|
||||||
|
self = [self initWithCapacity: count];
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
[self addObject:objects[i]];
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) removeLastObject
|
- (void) removeLastObject
|
||||||
{
|
{
|
||||||
int count = [self count];
|
int count = [self count];
|
||||||
|
@ -527,17 +495,17 @@ static Class NSMutableArray_concrete_class;
|
||||||
/* xxx Could be made more efficient by increasing capacity all at once. */
|
/* xxx Could be made more efficient by increasing capacity all at once. */
|
||||||
int i, c = [otherArray count];
|
int i, c = [otherArray count];
|
||||||
for (i = 0; i < c; i++)
|
for (i = 0; i < c; i++)
|
||||||
[self addObject:[otherArray objectAtIndex:i]];
|
[self addObject: [otherArray objectAtIndex: i]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setArray:(NSArray *)otherArray
|
- (void) setArray:(NSArray *)otherArray
|
||||||
{
|
{
|
||||||
[self removeAllObjects];
|
[self removeAllObjects];
|
||||||
[self addObjectsFromArray:otherArray];
|
[self addObjectsFromArray: otherArray];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) removeObjectsFromIndices: (unsigned*)indices
|
- (void) removeObjectsFromIndices: (unsigned*)indices
|
||||||
numIndices: (unsigned)count
|
numIndices: (unsigned)count
|
||||||
{
|
{
|
||||||
int compare_unsigned(const void *u1, const void *u2)
|
int compare_unsigned(const void *u1, const void *u2)
|
||||||
{
|
{
|
||||||
|
@ -563,3 +531,61 @@ static Class NSMutableArray_concrete_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@interface NSArrayEnumerator : NSEnumerator
|
||||||
|
{
|
||||||
|
id array;
|
||||||
|
int next_index;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation NSArrayEnumerator
|
||||||
|
|
||||||
|
- initWithArray: (NSArray*)anArray
|
||||||
|
{
|
||||||
|
[super init];
|
||||||
|
array = anArray;
|
||||||
|
[array retain];
|
||||||
|
next_index = 0;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) nextObject
|
||||||
|
{
|
||||||
|
if (next_index >= [array count])
|
||||||
|
return nil;
|
||||||
|
return [array objectAtIndex:next_index++];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
[array release];
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@interface NSArrayEnumeratorReverse : NSArrayEnumerator
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation NSArrayEnumeratorReverse
|
||||||
|
|
||||||
|
- initWithArray: (NSArray*)anArray
|
||||||
|
{
|
||||||
|
[super init];
|
||||||
|
array = anArray;
|
||||||
|
[array retain];
|
||||||
|
next_index = [array count]-1;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) nextObject
|
||||||
|
{
|
||||||
|
if (next_index < 0)
|
||||||
|
return nil;
|
||||||
|
return [array objectAtIndex:next_index--];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue