Some set tidyups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@8274 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2000-12-07 22:57:56 +00:00
parent 4d3ec2af14
commit edc67ffd44
8 changed files with 353 additions and 380 deletions

View file

@ -1,3 +1,11 @@
2000-12-07 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSGSet.m: renamed to GSSet.m for consistency, tidied.
* Source/NSGCountedSet.m: renamed to GSCountedSet.m for consistency.
* Headers/Foundation/NSGSet.h: removed - obsolete.
* Source/NSSet.m: Updated and tidied. Fixed coding class for
mutable sets.
2000-12-05 Richard Frith-Macdonald <rfm@gnu.org> 2000-12-05 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSURLHandle.m: minor mods to background loading. * Source/NSURLHandle.m: minor mods to background loading.

View file

@ -1,39 +0,0 @@
/* Interface to concrete implementation of NSSet based on GNU Array
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
Date: April 1995
This file is part of the GNUstep Base 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#ifndef __NSGSet_h_GNUSTEP_BASE_INCLUDE
#define __NSGSet_h_GNUSTEP_BASE_INCLUDE
#include <Foundation/NSSet.h>
@interface NSGSet : NSSet
@end
@interface NSGMutableSet : NSMutableSet
@end
@interface NSGCountedSet : NSCountedSet
@end
#endif /* __NSGSet_h_GNUSTEP_BASE_INCLUDE */

View file

@ -144,8 +144,10 @@ preface.h
# GNUStep source files # GNUStep source files
BASE_MFILES = \ BASE_MFILES = \
GSCountedSet.m \
GSHTTPURLHandle.m \ GSHTTPURLHandle.m \
GSMime.m \ GSMime.m \
GSSet.m \
GSString.m \ GSString.m \
NSAttributedString.m \ NSAttributedString.m \
NSArchiver.m \ NSArchiver.m \
@ -181,9 +183,7 @@ NSFormatter.m \
NSGeometry.m \ NSGeometry.m \
NSGArray.m \ NSGArray.m \
NSGAttributedString.m \ NSGAttributedString.m \
NSGCountedSet.m \
NSGDictionary.m \ NSGDictionary.m \
NSGSet.m \
NSHashTable.m \ NSHashTable.m \
NSHost.m \ NSHost.m \
NSInvocation.m \ NSInvocation.m \
@ -289,7 +289,6 @@ NSFormatter.h \
NSGeometry.h \ NSGeometry.h \
NSGArray.h \ NSGArray.h \
NSGAttributedString.h \ NSGAttributedString.h \
NSGSet.h \
NSHashTable.h \ NSHashTable.h \
NSHost.h \ NSHost.h \
NSInvocation.h \ NSInvocation.h \

View file

@ -1,5 +1,5 @@
/* Concrete implementation of NSSet based on GNU Set class /* Concrete implementation of NSCountedSet based on GNU Set class
Copyright (C) 1998 Free Software Foundation, Inc. Copyright (C) 1998,2000 Free Software Foundation, Inc.
Written by: Richard frith-Macdonald <richard@brainstorm.co.uk> Written by: Richard frith-Macdonald <richard@brainstorm.co.uk>
Created: October 1998 Created: October 1998
@ -42,28 +42,34 @@
@class NSSetNonCore; @class NSSetNonCore;
@class NSMutableSetNonCore; @class NSMutableSetNonCore;
@interface NSGCountedSet : NSCountedSet @interface GSCountedSet : NSCountedSet
{ {
@public @public
GSIMapTable_t map; GSIMapTable_t map;
} }
@end @end
@interface NSGCountedSetEnumerator : NSEnumerator @interface GSCountedSetEnumerator : NSEnumerator
{ {
NSGCountedSet *set; GSCountedSet *set;
GSIMapNode node; GSIMapNode node;
} }
@end @end
@implementation NSGCountedSetEnumerator @implementation GSCountedSetEnumerator
- (void) dealloc
{
RELEASE(set);
[super dealloc];
}
- (id) initWithSet: (NSSet*)d - (id) initWithSet: (NSSet*)d
{ {
self = [super init]; self = [super init];
if (self) if (self)
{ {
set = RETAIN((NSGCountedSet*)d); set = RETAIN((GSCountedSet*)d);
node = set->map.firstNode; node = set->map.firstNode;
} }
return self; return self;
@ -81,113 +87,20 @@
return old->key.obj; return old->key.obj;
} }
- (void) dealloc
{
RELEASE(set);
[super dealloc];
}
@end @end
@implementation NSGCountedSet @implementation GSCountedSet
+ (void) initialize + (void) initialize
{ {
if (self == [NSGCountedSet class]) if (self == [GSCountedSet class])
{ {
class_add_behavior(self, [NSSetNonCore class]); class_add_behavior(self, [NSSetNonCore class]);
class_add_behavior(self, [NSMutableSetNonCore class]); class_add_behavior(self, [NSMutableSetNonCore class]);
} }
} }
- (void) dealloc
{
GSIMapEmptyMap(&map);
[super dealloc];
}
- (void) encodeWithCoder: (NSCoder*)aCoder
{
unsigned count = map.nodeCount;
GSIMapNode node = map.firstNode;
SEL sel1 = @selector(encodeObject:);
IMP imp1 = [aCoder methodForSelector: sel1];
SEL sel2 = @selector(encodeValueOfObjCType:at:);
IMP imp2 = [aCoder methodForSelector: sel2];
const char *type = @encode(unsigned);
(*imp2)(aCoder, sel2, type, &count);
while (node != 0)
{
(*imp1)(aCoder, sel1, node->key.obj);
(*imp2)(aCoder, sel2, type, &node->value.uint);
node = node->nextInMap;
}
}
- (id) initWithCoder: (NSCoder*)aCoder
{
unsigned count;
id value;
unsigned valcnt;
SEL sel = @selector(decodeValueOfObjCType:at:);
IMP imp = [aCoder methodForSelector: sel];
const char *utype = @encode(unsigned);
const char *otype = @encode(id);
(*imp)(aCoder, sel, utype, &count);
GSIMapInitWithZoneAndCapacity(&map, [self zone], count);
while (count-- > 0)
{
(*imp)(aCoder, sel, otype, &value);
(*imp)(aCoder, sel, utype, &valcnt);
GSIMapAddPairNoRetain(&map, (GSIMapKey)value, (GSIMapVal)valcnt);
}
return self;
}
/* Designated initialiser */
- (id) initWithCapacity: (unsigned)cap
{
GSIMapInitWithZoneAndCapacity(&map, [self zone], cap);
return self;
}
- (id) initWithObjects: (id*)objs count: (unsigned)c
{
int i;
if ([self initWithCapacity: c] == nil)
{
return nil;
}
for (i = 0; i < c; i++)
{
GSIMapNode node;
if (objs[i] == nil)
{
IF_NO_GC(AUTORELEASE(self));
[NSException raise: NSInvalidArgumentException
format: @"Tried to init counted set with nil value"];
}
node = GSIMapNodeForKey(&map, (GSIMapKey)objs[i]);
if (node == 0)
{
GSIMapAddPair(&map,(GSIMapKey)objs[i],(GSIMapVal)(unsigned)1);
}
else
{
node->value.uint++;
}
}
return self;
}
- (void) addObject: (NSObject*)anObject - (void) addObject: (NSObject*)anObject
{ {
GSIMapNode node; GSIMapNode node;
@ -228,18 +141,105 @@
return 0; return 0;
} }
- (void) dealloc
{
GSIMapEmptyMap(&map);
[super dealloc];
}
- (void) encodeWithCoder: (NSCoder*)aCoder
{
unsigned count = map.nodeCount;
GSIMapNode node = map.firstNode;
SEL sel1 = @selector(encodeObject:);
IMP imp1 = [aCoder methodForSelector: sel1];
SEL sel2 = @selector(encodeValueOfObjCType:at:);
IMP imp2 = [aCoder methodForSelector: sel2];
const char *type = @encode(unsigned);
(*imp2)(aCoder, sel2, type, &count);
while (node != 0)
{
(*imp1)(aCoder, sel1, node->key.obj);
(*imp2)(aCoder, sel2, type, &node->value.uint);
node = node->nextInMap;
}
}
- (unsigned) hash - (unsigned) hash
{ {
return map.nodeCount; return map.nodeCount;
} }
/* Designated initialiser */
- (id) initWithCapacity: (unsigned)cap
{
GSIMapInitWithZoneAndCapacity(&map, [self zone], cap);
return self;
}
- (id) initWithCoder: (NSCoder*)aCoder
{
unsigned count;
id value;
unsigned valcnt;
SEL sel = @selector(decodeValueOfObjCType:at:);
IMP imp = [aCoder methodForSelector: sel];
const char *utype = @encode(unsigned);
const char *otype = @encode(id);
(*imp)(aCoder, sel, utype, &count);
GSIMapInitWithZoneAndCapacity(&map, [self zone], count);
while (count-- > 0)
{
(*imp)(aCoder, sel, otype, &value);
(*imp)(aCoder, sel, utype, &valcnt);
GSIMapAddPairNoRetain(&map, (GSIMapKey)value, (GSIMapVal)valcnt);
}
return self;
}
- (id) initWithObjects: (id*)objs count: (unsigned)c
{
int i;
if ([self initWithCapacity: c] == nil)
{
return nil;
}
for (i = 0; i < c; i++)
{
GSIMapNode node;
if (objs[i] == nil)
{
IF_NO_GC(AUTORELEASE(self));
[NSException raise: NSInvalidArgumentException
format: @"Tried to init counted set with nil value"];
}
node = GSIMapNodeForKey(&map, (GSIMapKey)objs[i]);
if (node == 0)
{
GSIMapAddPair(&map,(GSIMapKey)objs[i],(GSIMapVal)(unsigned)1);
}
else
{
node->value.uint++;
}
}
return self;
}
- (id) member: (id)anObject - (id) member: (id)anObject
{ {
if (anObject) if (anObject != nil)
{ {
GSIMapNode node = GSIMapNodeForKey(&map, (GSIMapKey)anObject); GSIMapNode node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
if (node) if (node != 0)
{ {
return node->key.obj; return node->key.obj;
} }
@ -249,7 +249,7 @@
- (NSEnumerator*) objectEnumerator - (NSEnumerator*) objectEnumerator
{ {
return AUTORELEASE([[NSGCountedSetEnumerator allocWithZone: return AUTORELEASE([[GSCountedSetEnumerator allocWithZone:
NSDefaultMallocZone()] initWithSet: self]); NSDefaultMallocZone()] initWithSet: self]);
} }
@ -276,6 +276,11 @@
} }
} }
- (void) removeAllObjects
{
GSIMapCleanMap(&map);
}
- (void) removeObject: (NSObject*)anObject - (void) removeObject: (NSObject*)anObject
{ {
GSIMapBucket bucket; GSIMapBucket bucket;
@ -302,11 +307,6 @@
} }
} }
- (void) removeAllObjects
{
GSIMapCleanMap(&map);
}
- (id) unique: (id)anObject - (id) unique: (id)anObject
{ {
GSIMapNode node; GSIMapNode node;

View file

@ -1,9 +1,9 @@
/* Concrete implementation of NSSet based on GNU Set class /* Concrete implementation of NSSet based on GNU Set class
Copyright (C) 1995, 1996, 1998 Free Software Foundation, Inc. Copyright (C) 1995, 1996, 1998, 2000 Free Software Foundation, Inc.
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu> Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
Created: September 1995 Created: September 1995
Rewrite by: Richard frith-Macdonald <richard@brainstorm.co.uk> Rewrite by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
This file is part of the GNUstep Base Library. This file is part of the GNUstep Base Library.
@ -42,35 +42,35 @@
@class NSSetNonCore; @class NSSetNonCore;
@class NSMutableSetNonCore; @class NSMutableSetNonCore;
@interface NSGSet : NSSet @interface GSSet : NSSet
{ {
@public @public
GSIMapTable_t map; GSIMapTable_t map;
} }
@end @end
@interface NSGMutableSet : NSMutableSet @interface GSMutableSet : NSMutableSet
{ {
@public @public
GSIMapTable_t map; GSIMapTable_t map;
} }
@end @end
@interface NSGSetEnumerator : NSEnumerator @interface GSSetEnumerator : NSEnumerator
{ {
NSGSet *set; GSSet *set;
GSIMapNode node; GSIMapNode node;
} }
@end @end
@implementation NSGSetEnumerator @implementation GSSetEnumerator
- (id) initWithSet: (NSSet*)d - (id) initWithSet: (NSSet*)d
{ {
self = [super init]; self = [super init];
if (self != nil) if (self != nil)
{ {
set = (NSGSet*)RETAIN(d); set = (GSSet*)RETAIN(d);
node = set->map.firstNode; node = set->map.firstNode;
} }
return self; return self;
@ -97,7 +97,7 @@
@end @end
@implementation NSGSet @implementation GSSet
static Class arrayClass; static Class arrayClass;
static Class setClass; static Class setClass;
@ -105,74 +105,15 @@ static Class mutableSetClass;
+ (void) initialize + (void) initialize
{ {
if (self == [NSGSet class]) if (self == [GSSet class])
{ {
class_add_behavior(self, [NSSetNonCore class]); class_add_behavior(self, [NSSetNonCore class]);
arrayClass = [NSArray class]; arrayClass = [NSArray class];
setClass = [NSGSet class]; setClass = [GSSet class];
mutableSetClass = [NSGMutableSet class]; mutableSetClass = [GSMutableSet class];
} }
} }
- (unsigned) count
{
return map.nodeCount;
}
- (void) dealloc
{
GSIMapEmptyMap(&map);
[super dealloc];
}
/* Designated initialiser */
- (id) initWithObjects: (id*)objs count: (unsigned)c
{
int i;
GSIMapInitWithZoneAndCapacity(&map, [self zone], c);
for (i = 0; i < c; i++)
{
GSIMapNode node;
if (objs[i] == nil)
{
IF_NO_GC(AUTORELEASE(self));
[NSException raise: NSInvalidArgumentException
format: @"Tried to init set with nil value"];
}
node = GSIMapNodeForKey(&map, (GSIMapKey)objs[i]);
if (node == 0)
{
GSIMapAddKey(&map, (GSIMapKey)objs[i]);
}
}
return self;
}
- (id) member: (id)anObject
{
if (anObject)
{
GSIMapNode node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
if (node)
{
return node->key.obj;
}
}
return nil;
}
- (NSEnumerator*) objectEnumerator
{
return AUTORELEASE([[NSGSetEnumerator alloc] initWithSet: self]);
}
@end
@implementation NSGSet (NonCore)
- (NSArray*) allObjects - (NSArray*) allObjects
{ {
id objs[map.nodeCount]; id objs[map.nodeCount];
@ -191,9 +132,24 @@ static Class mutableSetClass;
- (id) anyObject - (id) anyObject
{ {
if (map.nodeCount > 0) if (map.nodeCount > 0)
return map.firstNode->key.obj; {
return map.firstNode->key.obj;
}
else else
return nil; {
return nil;
}
}
- (unsigned) count
{
return map.nodeCount;
}
- (void) dealloc
{
GSIMapEmptyMap(&map);
[super dealloc];
} }
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
@ -236,6 +192,31 @@ static Class mutableSetClass;
return self; return self;
} }
/* Designated initialiser */
- (id) initWithObjects: (id*)objs count: (unsigned)c
{
unsigned i;
GSIMapInitWithZoneAndCapacity(&map, [self zone], c);
for (i = 0; i < c; i++)
{
GSIMapNode node;
if (objs[i] == nil)
{
IF_NO_GC(AUTORELEASE(self));
[NSException raise: NSInvalidArgumentException
format: @"Tried to init set with nil value"];
}
node = GSIMapNodeForKey(&map, (GSIMapKey)objs[i]);
if (node == 0)
{
GSIMapAddKey(&map, (GSIMapKey)objs[i]);
}
}
return self;
}
- (BOOL) intersectsSet: (NSSet*) otherSet - (BOOL) intersectsSet: (NSSet*) otherSet
{ {
Class c; Class c;
@ -244,15 +225,19 @@ static Class mutableSetClass;
* If this set is empty, or the other is nil, this method should return NO. * If this set is empty, or the other is nil, this method should return NO.
*/ */
if (map.nodeCount == 0) if (map.nodeCount == 0)
return NO; {
return NO;
}
if (otherSet == nil) if (otherSet == nil)
return NO; {
return NO;
}
// Loop for all members in otherSet // Loop for all members in otherSet
c = GSObjCClass(otherSet); c = GSObjCClass(otherSet);
if (c == setClass || c == mutableSetClass) if (c == setClass || c == mutableSetClass)
{ {
GSIMapNode node = ((NSGSet*)otherSet)->map.firstNode; GSIMapNode node = ((GSSet*)otherSet)->map.firstNode;
while (node != 0) while (node != 0)
{ {
@ -286,7 +271,9 @@ static Class mutableSetClass;
// -1. members of this set(self) <= that of otherSet // -1. members of this set(self) <= that of otherSet
if (map.nodeCount > [otherSet count]) if (map.nodeCount > [otherSet count])
return NO; {
return NO;
}
// 0. Loop for all members in this set(self). // 0. Loop for all members in this set(self).
while (node != 0) while (node != 0)
@ -323,7 +310,7 @@ static Class mutableSetClass;
if (c == setClass || c == mutableSetClass) if (c == setClass || c == mutableSetClass)
{ {
if (map.nodeCount != ((NSGSet*)other)->map.nodeCount) if (map.nodeCount != ((GSSet*)other)->map.nodeCount)
{ {
return NO; return NO;
} }
@ -333,7 +320,7 @@ static Class mutableSetClass;
while (node != 0) while (node != 0)
{ {
if (GSIMapNodeForKey(&(((NSGSet*)other)->map), node->key) if (GSIMapNodeForKey(&(((GSSet*)other)->map), node->key)
== 0) == 0)
{ {
return NO; return NO;
@ -410,16 +397,77 @@ static Class mutableSetClass;
} }
} }
- (id) member: (id)anObject
{
if (anObject != nil)
{
GSIMapNode node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
if (node != 0)
{
return node->key.obj;
}
}
return nil;
}
- (NSEnumerator*) objectEnumerator
{
return AUTORELEASE([[GSSetEnumerator alloc] initWithSet: self]);
}
@end @end
@implementation NSGMutableSet @implementation GSMutableSet
+ (void) initialize + (void) initialize
{ {
if (self == [NSGMutableSet class]) if (self == [GSMutableSet class])
{ {
class_add_behavior(self, [NSMutableSetNonCore class]); class_add_behavior(self, [NSMutableSetNonCore class]);
class_add_behavior(self, [NSGSet class]); class_add_behavior(self, [GSSet class]);
}
}
- (void) addObject: (NSObject*)anObject
{
GSIMapNode node;
if (anObject == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"Tried to add nil to set"];
}
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
if (node == 0)
{
GSIMapAddKey(&map, (GSIMapKey)anObject);
}
}
- (void) addObjectsFromArray: (NSArray*)array
{
unsigned count = [array count];
while (count-- > 0)
{
id anObject = [array objectAtIndex: count];
if (anObject == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"Tried to add nil to set"];
}
else
{
GSIMapNode node;
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
if (node == 0)
{
GSIMapAddKey(&map, (GSIMapKey)anObject);
}
}
} }
} }
@ -458,92 +506,6 @@ static Class mutableSetClass;
return self; return self;
} }
- (void) addObject: (NSObject*)anObject
{
GSIMapNode node;
if (anObject == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"Tried to add nil to set"];
}
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
if (node == 0)
{
GSIMapAddKey(&map, (GSIMapKey)anObject);
}
}
- (void) removeObject: (NSObject *)anObject
{
if (anObject == nil)
{
NSWarnMLog(@"attempt to remove nil object", 0);
return;
}
GSIMapRemoveKey(&map, (GSIMapKey)anObject);
}
- (void) removeAllObjects
{
GSIMapCleanMap(&map);
}
@end
@implementation NSGMutableSet (NonCore)
- (void) addObjectsFromArray: (NSArray*)array
{
unsigned count = [array count];
while (count--)
{
id anObject = [array objectAtIndex: count];
if (anObject == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"Tried to add nil to set"];
}
else
{
GSIMapNode node;
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
if (node == 0)
{
GSIMapAddKey(&map, (GSIMapKey)anObject);
}
}
}
}
- (void) unionSet: (NSSet*) other
{
if (other != self)
{
NSEnumerator *e = [other objectEnumerator];
id anObject;
while ((anObject = [e nextObject]) != nil)
{
GSIMapNode node;
if (anObject == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"Tried to add nil to set"];
}
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
if (node == 0)
{
GSIMapAddKey(&map, (GSIMapKey)anObject);
}
}
}
}
- (void) intersectSet: (NSSet*) other - (void) intersectSet: (NSSet*) other
{ {
if (other != self) if (other != self)
@ -581,4 +543,45 @@ static Class mutableSetClass;
} }
} }
- (void) removeAllObjects
{
GSIMapCleanMap(&map);
}
- (void) removeObject: (NSObject *)anObject
{
if (anObject == nil)
{
NSWarnMLog(@"attempt to remove nil object", 0);
return;
}
GSIMapRemoveKey(&map, (GSIMapKey)anObject);
}
- (void) unionSet: (NSSet*) other
{
if (other != self)
{
NSEnumerator *e = [other objectEnumerator];
id anObject;
while ((anObject = [e nextObject]) != nil)
{
GSIMapNode node;
if (anObject == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"Tried to add nil to set"];
}
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
if (node == 0)
{
GSIMapAddKey(&map, (GSIMapKey)anObject);
}
}
}
}
@end @end

View file

@ -224,10 +224,10 @@ $(GNUSTEP_OBJ_DIR)/NSUnarchiver.o \
# #
# Files that include GSIMap.h will need a rebuild if it is changed. # Files that include GSIMap.h will need a rebuild if it is changed.
# #
$(GNUSTEP_OBJ_DIR)/GSCountedSet.o \
$(GNUSTEP_OBJ_DIR)/GSSet.o \
$(GNUSTEP_OBJ_DIR)/NSArchiver.o \ $(GNUSTEP_OBJ_DIR)/NSArchiver.o \
$(GNUSTEP_OBJ_DIR)/NSGCountedSet.o \
$(GNUSTEP_OBJ_DIR)/NSGDictionary.o \ $(GNUSTEP_OBJ_DIR)/NSGDictionary.o \
$(GNUSTEP_OBJ_DIR)/NSGSet.o \
$(GNUSTEP_OBJ_DIR)/NSNotificationCenter.o \ $(GNUSTEP_OBJ_DIR)/NSNotificationCenter.o \
$(GNUSTEP_OBJ_DIR)/NSSerializer.o \ $(GNUSTEP_OBJ_DIR)/NSSerializer.o \
: $(HEADER_DIR)/GSIMap.h $(HEADER_DIR)/GSUnion.h : $(HEADER_DIR)/GSIMap.h $(HEADER_DIR)/GSUnion.h

View file

@ -24,7 +24,6 @@
#include <config.h> #include <config.h>
#include <base/behavior.h> #include <base/behavior.h>
#include <Foundation/NSSet.h> #include <Foundation/NSSet.h>
#include <Foundation/NSGSet.h>
#include <Foundation/NSCoder.h> #include <Foundation/NSCoder.h>
#include <Foundation/NSArray.h> #include <Foundation/NSArray.h>
#include <Foundation/NSUtilities.h> #include <Foundation/NSUtilities.h>
@ -36,6 +35,7 @@
@class NSSetNonCore; @class NSSetNonCore;
@class NSMutableSetNonCore; @class NSMutableSetNonCore;
@class GSCountedSet;
/* /*
* Class variables for uniquing objects; * Class variables for uniquing objects;
@ -61,7 +61,7 @@ static Class NSCountedSet_concrete_class;
if (self == [NSCountedSet class]) if (self == [NSCountedSet class])
{ {
NSCountedSet_abstract_class = self; NSCountedSet_abstract_class = self;
NSCountedSet_concrete_class = [NSGCountedSet class]; NSCountedSet_concrete_class = [GSCountedSet class];
behavior_class_add_class(self, [NSMutableSetNonCore class]); behavior_class_add_class(self, [NSMutableSetNonCore class]);
behavior_class_add_class(self, [NSSetNonCore class]); behavior_class_add_class(self, [NSSetNonCore class]);
if ([NSThread isMultiThreaded]) if ([NSThread isMultiThreaded])

View file

@ -24,7 +24,6 @@
#include <config.h> #include <config.h>
#include <base/behavior.h> #include <base/behavior.h>
#include <Foundation/NSSet.h> #include <Foundation/NSSet.h>
#include <Foundation/NSGSet.h>
#include <Foundation/NSCoder.h> #include <Foundation/NSCoder.h>
#include <Foundation/NSArray.h> #include <Foundation/NSArray.h>
#include <Foundation/NSUtilities.h> #include <Foundation/NSUtilities.h>
@ -32,6 +31,9 @@
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include <Foundation/NSObjCRuntime.h> #include <Foundation/NSObjCRuntime.h>
@class GSSet;
@class GSMutableSet;
@interface NSSetNonCore : NSSet @interface NSSetNonCore : NSSet
@end @end
@interface NSMutableSetNonCore: NSMutableSet @interface NSMutableSetNonCore: NSMutableSet
@ -44,14 +46,26 @@ static Class NSMutableSet_abstract_class;
static Class NSSet_concrete_class; static Class NSSet_concrete_class;
static Class NSMutableSet_concrete_class; static Class NSMutableSet_concrete_class;
+ (id) allocWithZone: (NSZone*)z
{
if (self == NSSet_abstract_class)
{
return NSAllocateObject(NSSet_concrete_class, 0, z);
}
else
{
return NSAllocateObject(self, 0, z);
}
}
+ (void) initialize + (void) initialize
{ {
if (self == [NSSet class]) if (self == [NSSet class])
{ {
NSSet_abstract_class = [NSSet class]; NSSet_abstract_class = [NSSet class];
NSMutableSet_abstract_class = [NSMutableSet class]; NSMutableSet_abstract_class = [NSMutableSet class];
NSSet_concrete_class = [NSGSet class]; NSSet_concrete_class = [GSSet class];
NSMutableSet_concrete_class = [NSGMutableSet class]; NSMutableSet_concrete_class = [GSMutableSet class];
behavior_class_add_class(self, [NSSetNonCore class]); behavior_class_add_class(self, [NSSetNonCore class]);
} }
} }
@ -61,13 +75,6 @@ static Class NSMutableSet_concrete_class;
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()] init]); return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()] init]);
} }
+ (id) setWithObjects: (id*)objects
count: (unsigned)count
{
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithObjects: objects count: count]);
}
+ (id) setWithArray: (NSArray*)objects + (id) setWithArray: (NSArray*)objects
{ {
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()] return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
@ -80,6 +87,13 @@ static Class NSMutableSet_concrete_class;
initWithObjects: &anObject count: 1]); initWithObjects: &anObject count: 1]);
} }
+ (id) setWithObjects: (id*)objects
count: (unsigned)count
{
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithObjects: objects count: count]);
}
+ (id) setWithObjects: firstObject, ... + (id) setWithObjects: firstObject, ...
{ {
id set; id set;
@ -97,26 +111,35 @@ static Class NSMutableSet_concrete_class;
initWithSet: aSet]); initWithSet: aSet]);
} }
+ (id) allocWithZone: (NSZone*)z - (Class) classForCoder
{ {
if (self == NSSet_abstract_class) return NSSet_abstract_class;
{
return NSAllocateObject(NSSet_concrete_class, 0, z);
}
else
{
return NSAllocateObject(self, 0, z);
}
} }
/* This is the designated initializer */ - (id) copyWithZone: (NSZone*)z
- (id) initWithObjects: (id*)objects {
count: (unsigned)count return RETAIN(self);
}
- (unsigned) count
{ {
[self subclassResponsibility: _cmd]; [self subclassResponsibility: _cmd];
return 0; return 0;
} }
- (void) encodeWithCoder: (NSCoder*)aCoder
{
unsigned count = [self count];
NSEnumerator *e = [self objectEnumerator];
id o;
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &count];
while ((o = [e nextObject]) != nil)
{
[aCoder encodeValueOfObjCType: @encode(id) at: &o];
}
}
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
{ {
unsigned count; unsigned count;
@ -148,51 +171,30 @@ static Class NSMutableSet_concrete_class;
} }
} }
- (Class) classForCoder /* This is the designated initializer */
{ - (id) initWithObjects: (id*)objects
return NSSet_abstract_class; count: (unsigned)count
}
- (unsigned) count
{ {
[self subclassResponsibility: _cmd]; [self subclassResponsibility: _cmd];
return 0; return 0;
} }
- (void) encodeWithCoder: (NSCoder*)aCoder
{
unsigned count = [self count];
NSEnumerator *e = [self objectEnumerator];
id o;
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &count];
while ((o = [e nextObject]) != nil)
{
[aCoder encodeValueOfObjCType: @encode(id) at: &o];
}
}
- (id) member: (id)anObject - (id) member: (id)anObject
{ {
return [self subclassResponsibility: _cmd]; return [self subclassResponsibility: _cmd];
return 0; return 0;
} }
- (NSEnumerator*) objectEnumerator
{
return [self subclassResponsibility: _cmd];
}
- (id) copyWithZone: (NSZone*)z
{
return RETAIN(self);
}
- (id) mutableCopyWithZone: (NSZone*)z - (id) mutableCopyWithZone: (NSZone*)z
{ {
return [[NSMutableSet_concrete_class allocWithZone: z] initWithSet: self]; return [[NSMutableSet_concrete_class allocWithZone: z] initWithSet: self];
} }
- (NSEnumerator*) objectEnumerator
{
return [self subclassResponsibility: _cmd];
}
@end @end
@implementation NSSetNonCore @implementation NSSetNonCore
@ -331,11 +333,6 @@ static Class NSMutableSet_concrete_class;
} }
} }
- (Class) classForCoder
{
return NSSet_abstract_class;
}
- (BOOL) containsObject: (id)anObject - (BOOL) containsObject: (id)anObject
{ {
return (([self member: anObject]) ? YES : NO); return (([self member: anObject]) ? YES : NO);
@ -488,6 +485,11 @@ static Class NSMutableSet_concrete_class;
} }
} }
- (Class) classForCoder
{
return NSMutableSet_concrete_class;
}
- (id) copyWithZone: (NSZone*)z - (id) copyWithZone: (NSZone*)z
{ {
return [[NSSet_concrete_class allocWithZone: z] initWithSet: self]; return [[NSSet_concrete_class allocWithZone: z] initWithSet: self];