Modify the interfaces of all collection classes to be compatible with the

new lightweight generics implemenation. (Newer MacOS X/iOS code assuming 
the presence of the generics annotations can otherwise not be compiled with
GNUstep). This should be well-behaved under clang and gcc both. 

Fix NSCache which was copying the cache keys when it really shouldn't
have. Added a few test cases for eviction behaviour.

Few smaller tweaks to avoid compiler warnings.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39406 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Niels Grewe 2016-02-22 21:04:18 +00:00
parent 4851131f49
commit 28c824a78a
14 changed files with 541 additions and 273 deletions

View file

@ -3,19 +3,19 @@
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
Created: Sep 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 Lesser 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 Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
@ -24,7 +24,7 @@
AutogsdocSource: NSSet.m
AutogsdocSource: NSCountedSet.m
*/
*/
#ifndef _NSSet_h_GNUSTEP_BASE_INCLUDE
#define _NSSet_h_GNUSTEP_BASE_INCLUDE
@ -38,38 +38,45 @@
extern "C" {
#endif
@class NSArray, NSString, NSEnumerator, NSDictionary;
@class GS_GENERIC_CLASS(NSArray, ElementT);
@class GS_GENERIC_CLASS(NSEnumerator, ElementT);
@class GS_GENERIC_CLASS(NSDictionary, KeyT:id<NSCopying>, ValT);
@class NSString;
@interface NSSet : NSObject <NSCoding, NSCopying, NSMutableCopying, NSFastEnumeration>
@interface GS_GENERIC_CLASS(NSSet, __covariant ElementT) : NSObject <NSCoding,
NSCopying,
NSMutableCopying,
NSFastEnumeration>
+ (id) set;
+ (id) setWithArray: (NSArray*)objects;
+ (id) setWithObject: (id)anObject;
+ (id) setWithObjects: (id)firstObject, ...;
+ (instancetype) set;
+ (instancetype) setWithArray: (GS_GENERIC_CLASS(NSArray, ElementT)*)objects;
+ (instancetype) setWithObject: (GS_GENERIC_TYPE(ElementT))anObject;
+ (instancetype) setWithObjects: (GS_GENERIC_TYPE(ElementT))firstObject, ...;
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
+ (id) setWithObjects: (const id[])objects
count: (NSUInteger)count;
+ (instancetype) setWithObjects: (const GS_GENERIC_TYPE(ElementT)[])objects
count: (NSUInteger)count;
#endif
+ (id) setWithSet: (NSSet*)aSet;
+ (instancetype) setWithSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)aSet;
- (NSArray*) allObjects;
- (id) anyObject;
- (BOOL) containsObject: (id)anObject;
- (GS_GENERIC_CLASS(NSArray, ElementT)*) allObjects;
- (GS_GENERIC_TYPE(ElementT)) anyObject;
- (BOOL) containsObject: (GS_GENERIC_TYPE(ElementT))anObject;
- (NSUInteger) count;
- (NSString*) description;
- (NSString*) descriptionWithLocale: (id)locale;
- (id) init;
- (id) initWithArray: (NSArray*)other;
- (id) initWithObjects: (id)firstObject, ...;
- (id) initWithObjects: (const id[])objects
count: (NSUInteger)count;
- (id) initWithSet: (NSSet*)other;
- (id) initWithSet: (NSSet*)other copyItems: (BOOL)flag;
- (instancetype) init;
- (instancetype) initWithArray: (GS_GENERIC_CLASS(NSArray, ElementT)*)other;
- (instancetype) initWithObjects: (GS_GENERIC_TYPE(ElementT))firstObject, ...;
- (instancetype) initWithObjects: (const GS_GENERIC_TYPE(ElementT)[])objects
count: (NSUInteger)count;
- (instancetype) initWithSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)other;
- (instancetype) initWithSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)other
copyItems: (BOOL)flag;
- (BOOL) intersectsSet: (NSSet*)otherSet;
- (BOOL) isEqualToSet: (NSSet*)other;
- (BOOL) isSubsetOfSet: (NSSet*)otherSet;
- (BOOL) intersectsSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)otherSet;
- (BOOL) isEqualToSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)other;
- (BOOL) isSubsetOfSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)otherSet;
- (void) makeObjectsPerform: (SEL)aSelector;
- (void) makeObjectsPerform: (SEL)aSelector withObject: (id)argument;
@ -77,13 +84,13 @@ extern "C" {
- (void) makeObjectsPerformSelector: (SEL)aSelector;
- (void) makeObjectsPerformSelector: (SEL)aSelector withObject: (id)argument;
#endif
- (id) member: (id)anObject;
- (NSEnumerator*) objectEnumerator;
- (GS_GENERIC_TYPE(ElementT)) member: (GS_GENERIC_TYPE(ElementT))anObject;
- (GS_GENERIC_CLASS(NSEnumerator, ElementT)*) objectEnumerator;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
DEFINE_BLOCK_TYPE(GSSetEnumeratorBlock, void, id, BOOL*);
DEFINE_BLOCK_TYPE(GSSetFilterBlock, BOOL, id, BOOL*);
DEFINE_BLOCK_TYPE(GSSetEnumeratorBlock, void, GS_GENERIC_TYPE(ElementT), BOOL*);
DEFINE_BLOCK_TYPE(GSSetFilterBlock, BOOL, GS_GENERIC_TYPE(ElementT), BOOL*);
/**
* Enumerate over the collection using a given block. The first argument is
@ -106,40 +113,46 @@ DEFINE_BLOCK_TYPE(GSSetFilterBlock, BOOL, id, BOOL*);
- (void) enumerateObjectsWithOptions: (NSEnumerationOptions)opts
usingBlock: (GSSetEnumeratorBlock)aBlock;
- (NSSet *) objectsPassingTest: (GSSetFilterBlock)aBlock;
- (NSSet *) objectsWithOptions: (NSEnumerationOptions)opts
passingTest: (GSSetFilterBlock)aBlock;
- (GS_GENERIC_CLASS(NSSet, ElementT) *) objectsPassingTest:
(GSSetFilterBlock)aBlock;
- (GS_GENERIC_CLASS(NSSet, ElementT) *) objectsWithOptions:
(NSEnumerationOptions)opts
passingTest: (GSSetFilterBlock)aBlock;
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5,GS_API_LATEST)
- (NSSet *) setByAddingObject: (id)anObject;
- (NSSet *) setByAddingObjectsFromSet: (NSSet *)other;
- (NSSet *) setByAddingObjectsFromArray: (NSArray *)other;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5,GS_API_LATEST)
- (GS_GENERIC_CLASS(NSSet, ElementT) *) setByAddingObject:
(GS_GENERIC_TYPE(ElementT))anObject;
- (GS_GENERIC_CLASS(NSSet, ElementT) *) setByAddingObjectsFromSet:
(GS_GENERIC_CLASS(NSSet, ElementT) *)other;
- (GS_GENERIC_CLASS(NSSet, ElementT) *) setByAddingObjectsFromArray:
(GS_GENERIC_CLASS(NSArray, ElementT) *)other;
#endif
@end
@interface NSMutableSet: NSSet
@interface GS_GENERIC_CLASS(NSMutableSet, ElementT):
GS_GENERIC_CLASS(NSSet, ElementT)
+ (id) setWithCapacity: (NSUInteger)numItems;
+ (instancetype) setWithCapacity: (NSUInteger)numItems;
- (void) addObject: (id)anObject;
- (void) addObjectsFromArray: (NSArray*)array;
- (id) initWithCapacity: (NSUInteger)numItems;
- (void) intersectSet: (NSSet*)other;
- (void) minusSet: (NSSet*)other;
- (void) addObject: (GS_GENERIC_TYPE(ElementT))anObject;
- (void) addObjectsFromArray: (GS_GENERIC_CLASS(NSArray, ElementT)*)array;
- (instancetype) initWithCapacity: (NSUInteger)numItems;
- (void) intersectSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)other;
- (void) minusSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)other;
- (void) removeAllObjects;
- (void) removeObject: (id)anObject;
- (void) removeObject: (GS_GENERIC_TYPE(ElementT))anObject;
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
- (void) setSet: (NSSet*)other;
- (void) setSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)other;
#endif
- (void) unionSet: (NSSet*)other;
- (void) unionSet: (GS_GENERIC_CLASS(NSSet, ElementT)*)other;
@end
@interface NSCountedSet : NSMutableSet
@interface GS_GENERIC_CLASS(NSCountedSet, ElementT) :
GS_GENERIC_CLASS(NSMutableSet, ElementT)
- (NSUInteger) countForObject: (id)anObject;
- (NSUInteger) countForObject: (GS_GENERIC_TYPE(ElementT))anObject;
@end
@ -148,7 +161,7 @@ DEFINE_BLOCK_TYPE(GSSetFilterBlock, BOOL, id, BOOL*);
/**
* Utility methods for using a counted set to handle uniquing of objects.
*/
@interface NSCountedSet (GNU_Uniquing)
@interface GS_GENERIC_CLASS(NSCountedSet, ElementT) (GNU_Uniquing)
/**
* <p>
* This method removes from the set all objects whose count is
@ -170,7 +183,7 @@ DEFINE_BLOCK_TYPE(GSSetFilterBlock, BOOL, id, BOOL*);
* is released, and the object in the set is retained and returned.
* Otherwise, the supplied object is added to the set and returned.
* </p>
* <p>
* <p>
* This method is useful for uniquing objects - the init method of
* a class need simply end with -
* <code>
@ -178,7 +191,8 @@ DEFINE_BLOCK_TYPE(GSSetFilterBlock, BOOL, id, BOOL*);
* </code>
* </p>
*/
- (id) unique: (id) NS_CONSUMED anObject NS_RETURNS_RETAINED;
- (GS_GENERIC_TYPE(ElementT)) unique:
(GS_GENERIC_TYPE(ElementT)) NS_CONSUMED anObject NS_RETURNS_RETAINED;
@end
/*
@ -190,7 +204,7 @@ DEFINE_BLOCK_TYPE(GSSetFilterBlock, BOOL, id, BOOL*);
* if uniquing is turned off, GSUnique() simply returns its argument.
*
*/
void GSUniquing(BOOL flag);
void GSUniquing(BOOL flag);
/*
* GSUnique() returns an object that is equal to the one passed to it.