mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-12 17:11:12 +00:00
([NSDictionary +_setConcreteClass:]): New method.
([NSDictionary +_setMutableConcreteClass:]): New method. ([NSDictionary +_concreteClass]): New method. ([NSDictionary +_mutableConcreteClass]): New method. ([NSDictionary +initialize]): New method. (NSDictionary_concrete_class, NSMutableDictionary_concrete_class): New static variables. ([NSDictionary -copyWithZone:]): Make a deep copy to conform to spec; it was a shallow copy. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@475 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7c31f75f2e
commit
403165fd49
1 changed files with 57 additions and 10 deletions
|
@ -31,14 +31,43 @@
|
||||||
|
|
||||||
@implementation NSDictionary
|
@implementation NSDictionary
|
||||||
|
|
||||||
|
static Class NSDictionary_concrete_class;
|
||||||
|
static Class NSMutableDictionary_concrete_class;
|
||||||
|
|
||||||
|
+ (void) _setConcreteClass: (Class)c
|
||||||
|
{
|
||||||
|
NSDictionary_concrete_class = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void) _setMutableConcreteClass: (Class)c
|
||||||
|
{
|
||||||
|
NSMutableDictionary_concrete_class = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (Class) _concreteClass
|
||||||
|
{
|
||||||
|
return NSDictionary_concrete_class;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (Class) _mutableConcreteClass
|
||||||
|
{
|
||||||
|
return NSMutableDictionary_concrete_class;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void) initialize
|
||||||
|
{
|
||||||
|
NSDictionary_concrete_class = [NSGDictionary class];
|
||||||
|
NSMutableDictionary_concrete_class = [NSGMutableDictionary class];
|
||||||
|
}
|
||||||
|
|
||||||
+ allocWithZone: (NSZone*)z
|
+ allocWithZone: (NSZone*)z
|
||||||
{
|
{
|
||||||
return NSAllocateObject([NSGDictionary class], 0, z);
|
return NSAllocateObject([self _concreteClass], 0, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ dictionary
|
+ dictionary
|
||||||
{
|
{
|
||||||
return [[[NSGDictionary alloc] init]
|
return [[[[self _concreteClass] alloc] init]
|
||||||
autorelease];
|
autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,9 +75,9 @@
|
||||||
forKeys: (NSString**)keys
|
forKeys: (NSString**)keys
|
||||||
count: (unsigned)count
|
count: (unsigned)count
|
||||||
{
|
{
|
||||||
return [[[NSGDictionary alloc] initWithObjects:objects
|
return [[[[self _concreteClass] alloc] initWithObjects:objects
|
||||||
forKeys:keys
|
forKeys:keys
|
||||||
count:count]
|
count:count]
|
||||||
autorelease];
|
autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +98,7 @@
|
||||||
|
|
||||||
+ dictionaryWithObjects: (NSArray*)objects forKeys: (NSArray*)keys
|
+ dictionaryWithObjects: (NSArray*)objects forKeys: (NSArray*)keys
|
||||||
{
|
{
|
||||||
return [[[NSGDictionary alloc] initWithObjects:objects forKeys:keys]
|
return [[[[self _concreteClass] alloc] initWithObjects:objects forKeys:keys]
|
||||||
autorelease];
|
autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,12 +249,30 @@
|
||||||
|
|
||||||
- copyWithZone: (NSZone*)z
|
- copyWithZone: (NSZone*)z
|
||||||
{
|
{
|
||||||
return [[NSGDictionary alloc] initWithDictionary:self];
|
/* a deep copy */
|
||||||
|
int count = [self count];
|
||||||
|
id objects[count];
|
||||||
|
NSString *keys[count];
|
||||||
|
id enumerator = [self keyEnumerator];
|
||||||
|
id key;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; (key = [enumerator nextObject]); i++)
|
||||||
|
{
|
||||||
|
keys[i] = [key copyWithZone:z];
|
||||||
|
objects[i] = [[self objectForKey:key] copyWithZone:z];
|
||||||
|
}
|
||||||
|
return [[[[self class] _concreteClass] alloc]
|
||||||
|
initWithObjects:objects
|
||||||
|
forKeys:keys
|
||||||
|
count:count];
|
||||||
}
|
}
|
||||||
|
|
||||||
- mutableCopyWithZone: (NSZone*)z
|
- mutableCopyWithZone: (NSZone*)z
|
||||||
{
|
{
|
||||||
return [[NSGMutableDictionary alloc] initWithDictionary:self];
|
/* a shallow copy */
|
||||||
|
return [[[[[self class] _mutableConcreteClass] _mutableConcreteClass] alloc]
|
||||||
|
initWithDictionary:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -234,12 +281,12 @@
|
||||||
|
|
||||||
+ allocWithZone: (NSZone*)z
|
+ allocWithZone: (NSZone*)z
|
||||||
{
|
{
|
||||||
return NSAllocateObject([NSGMutableDictionary class], 0, z);
|
return NSAllocateObject([self _mutableConcreteClass], 0, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ dictionaryWithCapacity: (unsigned)numItems
|
+ dictionaryWithCapacity: (unsigned)numItems
|
||||||
{
|
{
|
||||||
return [[[NSGDictionary alloc] initWithCapacity:numItems]
|
return [[[[self _mutableConcreteClass] alloc] initWithCapacity:numItems]
|
||||||
autorelease];
|
autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue