Added new method for MacOS-X compatibility.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14342 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2002-08-27 09:37:58 +00:00
parent 76266fba00
commit 75e76795e2
3 changed files with 56 additions and 16 deletions

View file

@ -5,7 +5,8 @@
* Source/NSUserDefaults.m: Use distributed lock to ensure that there * Source/NSUserDefaults.m: Use distributed lock to ensure that there
is no possible window when the defaults file is invalid ... not all is no possible window when the defaults file is invalid ... not all
systems guarantee that the rename() system call is atomic. systems guarantee that the rename() system call is atomic.
* Source/NSArray.m: New MacOS-X method ([-initWithArray:copyItems:])
2002-08-25 Richard Frith-Macdonald <rfm@gnu.org> 2002-08-25 Richard Frith-Macdonald <rfm@gnu.org>
* Source/WindowsFileHandle.m: Removed ... no longer used. * Source/WindowsFileHandle.m: Removed ... no longer used.

View file

@ -50,6 +50,9 @@
- (unsigned) indexOfObjectIdenticalTo: (id)anObject; - (unsigned) indexOfObjectIdenticalTo: (id)anObject;
- (unsigned) indexOfObjectIdenticalTo: (id)anObject inRange: (NSRange)aRange; - (unsigned) indexOfObjectIdenticalTo: (id)anObject inRange: (NSRange)aRange;
- (id) initWithArray: (NSArray*)array; - (id) initWithArray: (NSArray*)array;
#ifndef STRICT_OPENSTEP
- (id) initWithArray: (NSArray*)array copyItems: (BOOL)shouldCopy;
#endif
- (id) initWithContentsOfFile: (NSString*)file; - (id) initWithContentsOfFile: (NSString*)file;
- (id) initWithObjects: firstObject, ...; - (id) initWithObjects: firstObject, ...;
- (id) initWithObjects: (id*)objects count: (unsigned)count; // Primitive - (id) initWithObjects: (id*)objects count: (unsigned)count; // Primitive

View file

@ -459,26 +459,59 @@ static SEL rlSel;
} }
/** /**
* Initialize the array with the content of anArray. The order is preserved. * Initialize the receiver with the contents of array.
* <br />May change the value of self before returning it. * The order of array is preserved.<br />
* If shouldCopy is YES then the objects are copied
* rather than simply retained.<br />
* Invokes -initWithObjects:count:
*/ */
- (id) initWithArray: (NSArray*)array - (id) initWithArray: (NSArray*)array copyItems: (BOOL)shouldCopy
{ {
unsigned c; unsigned c = [array count];
id objects[c];
c = [array count]; [array getObjects: objects];
{ if (shouldCopy == YES)
id objects[c]; {
unsigned i;
[array getObjects: objects]; for (i = 0; i < c; i++)
self = [self initWithObjects: objects count: c]; {
} objects[i] = [objects[i] copy];
}
self = [self initWithObjects: objects count: c];
#if GS_WITH_GC == 0
while (i > 0)
{
[objects[--i] release];
}
#endif
}
else
{
self = [self initWithObjects: objects count: c];
}
return self; return self;
} }
/** /**
* Initialize the array by decoding from an archive. * Initialize the receiver with the contents of array.
* <br />May change the value of self before returning it. * The order of array is preserved.<br />
* Invokes -initWithObjects:count:
*/
- (id) initWithArray: (NSArray*)array
{
unsigned c = [array count];
id objects[c];
[array getObjects: objects];
self = [self initWithObjects: objects count: c];
return self;
}
/**
* Initialize the array by decoding from an archive.<br />
* Invokes -initWithObjects:count:
*/ */
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
{ {
@ -496,7 +529,9 @@ static SEL rlSel;
return [self initWithObjects: contents count: count]; return [self initWithObjects: contents count: count];
} }
else else
return [self initWithObjects: 0 count: 0]; {
return [self initWithObjects: 0 count: 0];
}
} }
/** /**
@ -548,8 +583,9 @@ static SEL rlSel;
} }
/** <init /> /** <init />
* Initialize the array with count objects. * Initialize the array with count objects.<br />
* <br />May change the value of self before returning it. * Retains each object placed in the array.<br />
* Like all initializers, may change the value of self before returning it.
*/ */
- (id) initWithObjects: (id*)objects count: (unsigned)count - (id) initWithObjects: (id*)objects count: (unsigned)count
{ {