1995-04-15 19:48:46 +00:00
|
|
|
/* Concrete implementation of NSArray based on GNU Array class
|
1996-01-26 16:29:07 +00:00
|
|
|
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
|
1995-04-05 20:47:19 +00:00
|
|
|
|
|
|
|
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
|
|
|
Date: March 1995
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
1996-04-17 15:34:35 +00:00
|
|
|
#include <gnustep/base/preface.h>
|
1995-04-17 21:13:20 +00:00
|
|
|
#include <Foundation/NSGArray.h>
|
1996-03-31 22:34:27 +00:00
|
|
|
#include <Foundation/NSArray.h>
|
1996-04-17 15:23:00 +00:00
|
|
|
#include <gnustep/base/NSArray.h>
|
|
|
|
#include <gnustep/base/behavior.h>
|
|
|
|
#include <gnustep/base/Array.h>
|
|
|
|
#include <gnustep/base/ArrayPrivate.h>
|
1995-10-22 17:58:57 +00:00
|
|
|
#include <Foundation/NSException.h>
|
1995-04-05 20:47:19 +00:00
|
|
|
|
1995-04-15 19:48:46 +00:00
|
|
|
@implementation NSGArray
|
1995-04-05 20:47:19 +00:00
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
1996-03-31 22:34:27 +00:00
|
|
|
if (self == [NSGArray class])
|
1995-04-05 20:47:19 +00:00
|
|
|
{
|
1996-03-31 22:34:27 +00:00
|
|
|
behavior_class_add_class (self, [NSArrayNonCore class]);
|
|
|
|
behavior_class_add_class (self, [Array class]);
|
1995-04-05 20:47:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-03-31 22:34:27 +00:00
|
|
|
/* #define self ((Array*)self) */
|
|
|
|
|
|
|
|
#if 0
|
1995-04-05 20:47:19 +00:00
|
|
|
/* This is the designated initializer for NSArray. */
|
|
|
|
- initWithObjects: (id*)objects count: (unsigned)count
|
|
|
|
{
|
1995-10-22 17:58:57 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
if (objects[i] == nil)
|
|
|
|
[NSException raise:NSInvalidArgumentException
|
|
|
|
format:@"Tried to add nil"];
|
1996-02-22 15:18:57 +00:00
|
|
|
[self initWithCapacity: count];
|
1995-04-05 20:47:19 +00:00
|
|
|
while (count--)
|
1996-01-26 16:29:07 +00:00
|
|
|
[self addObject: [objects[count] retain]];
|
1995-04-05 20:47:19 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1995-09-21 17:42:46 +00:00
|
|
|
/* Force message to go to super class rather than the behavior class */
|
|
|
|
- (unsigned) indexOfObject: anObject
|
|
|
|
{
|
1996-01-26 16:29:07 +00:00
|
|
|
return [super indexOfObject: anObject];
|
1995-09-21 17:42:46 +00:00
|
|
|
}
|
|
|
|
|
1995-04-05 20:47:19 +00:00
|
|
|
- objectAtIndex: (unsigned)index
|
|
|
|
{
|
1996-01-26 16:29:07 +00:00
|
|
|
if (index >= self->_count)
|
|
|
|
[NSException raise: NSRangeException
|
|
|
|
format: @"Index out of bounds"];
|
1996-02-22 15:18:57 +00:00
|
|
|
return self->_contents_array[index];
|
1995-04-05 20:47:19 +00:00
|
|
|
}
|
1996-03-31 22:34:27 +00:00
|
|
|
#endif
|
1995-04-05 20:47:19 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
1995-04-15 19:48:46 +00:00
|
|
|
@implementation NSGMutableArray
|
1995-04-05 20:47:19 +00:00
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
1996-03-31 22:34:27 +00:00
|
|
|
if (self == [NSGMutableArray class])
|
1995-04-05 20:47:19 +00:00
|
|
|
{
|
1996-03-31 22:34:27 +00:00
|
|
|
behavior_class_add_class (self, [NSMutableArrayNonCore class]);
|
|
|
|
behavior_class_add_class (self, [NSGArray class]);
|
|
|
|
behavior_class_add_class (self, [Array class]);
|
1995-04-05 20:47:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-03-31 22:34:27 +00:00
|
|
|
#if 0
|
1995-04-05 20:47:19 +00:00
|
|
|
/* Comes in from Array behavior
|
1996-02-22 15:18:57 +00:00
|
|
|
- initWithCapacity:
|
1995-04-05 20:47:19 +00:00
|
|
|
- (void) addObject: anObject
|
1996-01-26 16:29:07 +00:00
|
|
|
- (void) insertObject: anObject atIndex: (unsigned)index
|
1995-04-05 20:47:19 +00:00
|
|
|
*/
|
|
|
|
|
1995-10-18 16:47:59 +00:00
|
|
|
- (void) replaceObjectAtIndex: (unsigned)index withObject: anObject
|
|
|
|
{
|
1996-01-26 16:29:07 +00:00
|
|
|
[self replaceObjectAtIndex: index with: anObject];
|
1995-10-18 16:47:59 +00:00
|
|
|
}
|
1996-03-31 22:34:27 +00:00
|
|
|
#endif
|
1995-10-18 16:47:59 +00:00
|
|
|
|
1995-04-05 20:47:19 +00:00
|
|
|
@end
|