mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
add block enumeration
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32459 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
c518b0f246
commit
6a859778a6
3 changed files with 55 additions and 0 deletions
|
@ -1,3 +1,9 @@
|
|||
2011-03-05 Tom Davie <beelsebob2>
|
||||
|
||||
* Source/NSSet.m:
|
||||
* Headers/Foundation/NSSet.h:
|
||||
Add block enumeration.
|
||||
|
||||
2011-03-05 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSUserDefaults.m: Small optimisation suggested by Fred.
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#import <Foundation/NSObject.h>
|
||||
#import <Foundation/NSEnumerator.h>
|
||||
#import <GNUstepBase/GSBlocks.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
|
@ -79,6 +80,31 @@ extern "C" {
|
|||
- (id) member: (id)anObject;
|
||||
- (NSEnumerator*) objectEnumerator;
|
||||
|
||||
#if OS_API_VERSION(100600, GS_API_LATEST)
|
||||
|
||||
DEFINE_BLOCK_TYPE(GSSetEnumeratorBlock, void, id, BOOL*);
|
||||
/**
|
||||
* Enumerate over the collection using a given block. The first argument is
|
||||
* the object. The second argument is a pointer to a BOOL indicating
|
||||
* whether the enumeration should stop. Setting this to YES will interupt
|
||||
* the enumeration.
|
||||
*/
|
||||
- (void) enumerateObjectsUsingBlock:(GSSetEnumeratorBlock)aBlock;
|
||||
|
||||
/**
|
||||
* Enumerate over the collection using the given block. The first argument is
|
||||
* the object. The second argument is a pointer to a BOOL indicating whether
|
||||
* the enumeration should stop. Setting this to YES will interrupt the
|
||||
* enumeration.
|
||||
*
|
||||
* The opts argument is a bitfield. Setting the NSNSEnumerationConcurrent flag
|
||||
* specifies that it is thread-safe. The NSEnumerationReverse bit specifies
|
||||
* that it should be enumerated in reverse order.
|
||||
*/
|
||||
- (void) enumerateObjectsWithOptions: (NSEnumerationOptions)opts
|
||||
usingBlock: (GSSetEnumeratorBlock)aBlock;
|
||||
#endif
|
||||
|
||||
#if OS_API_VERSION(100500,GS_API_LATEST)
|
||||
- (NSSet *) setByAddingObject: (id)anObject;
|
||||
- (NSSet *) setByAddingObjectsFromSet: (NSSet *)other;
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#import "Foundation/NSKeyedArchiver.h"
|
||||
#import "GSPrivate.h"
|
||||
#import "GNUstepBase/NSObject+GNUstepBase.h"
|
||||
#import "GSFastEnumeration.h"
|
||||
|
||||
@class GSSet;
|
||||
@interface GSSet : NSObject // Help the compiler
|
||||
|
@ -857,6 +858,28 @@ static Class NSMutableSet_concrete_class;
|
|||
return result;
|
||||
}
|
||||
|
||||
- (void) enumerateObjectsUsingBlock: (GSSetEnumeratorBlock)aBlock
|
||||
{
|
||||
[self enumerateObjectsWithOptions: 0 usingBlock: aBlock];
|
||||
}
|
||||
|
||||
- (void) enumerateObjectsWithOptions: (NSEnumerationOptions)opts
|
||||
usingBlock: (GSSetEnumeratorBlock)aBlock
|
||||
{
|
||||
BOOL shouldStop = NO;
|
||||
id<NSFastEnumeration> enumerator = self;
|
||||
|
||||
FOR_IN (id, obj, enumerator)
|
||||
{
|
||||
CALL_BLOCK(aBlock, obj, &shouldStop);
|
||||
if(shouldStop)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
END_FOR_IN(enumerator)
|
||||
}
|
||||
|
||||
/** Return a set formed by adding anObject to the receiver.
|
||||
*/
|
||||
- (NSSet *) setByAddingObject: (id)anObject
|
||||
|
|
Loading…
Reference in a new issue