Index: src/bridge/Makefile ================================================================== --- src/bridge/Makefile +++ src/bridge/Makefile @@ -11,15 +11,17 @@ SRCS = OFArray+NSObject.m \ OFEnumerator+NSObject.m \ OFException+Swift.m \ OFDictionary+NSObject.m \ OFNumber+NSObject.m \ + OFSet+NSObject.m \ OFString+NSObject.m \ NSArray+OFObject.m \ NSDictionary+OFObject.m \ NSEnumerator+OFObject.m \ NSNumber+OFObject.m \ + NSSet+OFObject.m \ NSString+OFObject.m INCLUDES := ${SRCS:.m=.h} \ NSBridging.h \ OFBridging.h \ @@ -26,17 +28,19 @@ ObjFWBridge.h SRCS += NSOFArray.m \ NSOFDictionary.m \ NSOFEnumerator.m \ + NSOFSet.m \ OFNSArray.m \ OFNSDictionary.m \ - OFNSEnumerator.m + OFNSEnumerator.m \ + OFNSSet.m includesubdir = ObjFWBridge include ../../buildsys.mk CPPFLAGS += -I. -I.. -I../.. -I../exceptions -DOF_BRIDGE_LOCAL_INCLUDES LD = ${OBJC} FRAMEWORK_LIBS := -framework Foundation -F.. -framework ObjFW ${LIBS} LIBS := -framework Foundation -L.. -lobjfw ${LIBS} ADDED src/bridge/NSOFSet.h Index: src/bridge/NSOFSet.h ================================================================== --- src/bridge/NSOFSet.h +++ src/bridge/NSOFSet.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import + +#import "macros.h" + +@class OFSet; + +OF_ASSUME_NONNULL_BEGIN + +@interface NSOFSet: NSSet +{ + OFSet *_set; +} + +- (instancetype)initWithOFSet: (OFSet *)set; +@end + +OF_ASSUME_NONNULL_END ADDED src/bridge/NSOFSet.m Index: src/bridge/NSOFSet.m ================================================================== --- src/bridge/NSOFSet.m +++ src/bridge/NSOFSet.m @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "NSOFSet.h" +#import "OFEnumerator+NSObject.h" +#import "OFSet.h" + +#import "OFBridging.h" +#import "NSBridging.h" + +#import "OFOutOfRangeException.h" + +@implementation NSOFSet +- (instancetype)initWithOFSet: (OFSet *)set +{ + if ((self = [super init]) != nil) + _set = [set retain]; + + return self; +} + +- (void)dealloc +{ + [_set release]; + + [super dealloc]; +} + +- (id)member: (id)object +{ + id originalObject = object; + + if ([(NSObject *)object conformsToProtocol: @protocol(NSBridging)]) + object = [object OFObject]; + + if ([_set containsObject: object]) + return originalObject; + + return nil; +} + +- (NSUInteger)count +{ + size_t count = _set.count; + + if (count > NSUIntegerMax) + @throw [OFOutOfRangeException exception]; + + return (NSUInteger)count; +} + +- (NSEnumerator *)objectEnumerator +{ + return [_set objectEnumerator].NSObject; +} +@end ADDED src/bridge/NSSet+OFObject.h Index: src/bridge/NSSet+OFObject.h ================================================================== --- src/bridge/NSSet+OFObject.h +++ src/bridge/NSSet+OFObject.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import + +#import "NSBridging.h" + +OF_ASSUME_NONNULL_BEGIN + +@class OFSet OF_GENERIC(ObjectType); + +#ifdef __cplusplus +extern "C" { +#endif +extern int _NSSet_OFObject_reference; +#ifdef __cplusplus +} +#endif + +/*! + * @category NSSet (OFObject) + * NSSet+OFObject.h ObjFWBridge/NSSet+OFObject.h + * + * @brief Support for bridging NSSets to OFSets. + */ +@interface NSSet (OFObject) +@property (readonly, nonatomic) OFSet *OFObject; +@end + +OF_ASSUME_NONNULL_END ADDED src/bridge/NSSet+OFObject.m Index: src/bridge/NSSet+OFObject.m ================================================================== --- src/bridge/NSSet+OFObject.m +++ src/bridge/NSSet+OFObject.m @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "NSSet+OFObject.h" +#import "OFNSSet.h" + +int _NSSet_OFObject_reference; + +@implementation NSSet (OFObject) +- (id)OFObject +{ + return [[[OFNSSet alloc] initWithNSSet: self] autorelease]; +} +@end ADDED src/bridge/OFNSSet.h Index: src/bridge/OFNSSet.h ================================================================== --- src/bridge/OFNSSet.h +++ src/bridge/OFNSSet.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#ifdef OF_BRIDGE_LOCAL_INCLUDES +# import "OFSet.h" +#else +# if defined(__has_feature) && __has_feature(modules) +@import ObjFW; +# else +# import +# endif +#endif + +OF_ASSUME_NONNULL_BEGIN + +@class NSSet; + +@interface OFNSSet: OFSet +{ + NSSet *_set; +} + +- (instancetype)initWithNSSet: (NSSet *)set; +@end + +OF_ASSUME_NONNULL_END ADDED src/bridge/OFNSSet.m Index: src/bridge/OFNSSet.m ================================================================== --- src/bridge/OFNSSet.m +++ src/bridge/OFNSSet.m @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import + +#import "OFNSSet.h" +#import "NSEnumerator+OFObject.h" + +#import "OFBridging.h" +#import "NSBridging.h" + +#import "OFInvalidArgumentException.h" +#import "OFOutOfRangeException.h" + +@implementation OFNSSet +- (instancetype)initWithNSSet: (NSSet *)set +{ + self = [super init]; + + @try { + if (set == nil) + @throw [OFInvalidArgumentException exception]; + + _set = [set retain]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_set release]; + + [super dealloc]; +} + +- (bool)containsObject: (id)object +{ + void *pool = objc_autoreleasePoolPush(); + bool ret; + + if ([(OFObject *)object conformsToProtocol: @protocol(OFBridging)]) + object = [object NSObject]; + + ret = [_set containsObject: object]; + + objc_autoreleasePoolPop(pool); + return ret; +} + +- (size_t)count +{ + return _set.count; +} + +- (OFEnumerator *)objectEnumerator +{ + return [_set objectEnumerator].OFObject; +} +@end ADDED src/bridge/OFSet+NSObject.h Index: src/bridge/OFSet+NSObject.h ================================================================== --- src/bridge/OFSet+NSObject.h +++ src/bridge/OFSet+NSObject.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#ifdef OF_BRIDGE_LOCAL_INCLUDES +# import "OFSet.h" +#else +# if defined(__has_feature) && __has_feature(modules) +@import ObjFW; +# else +# import +# endif +#endif + +#import "OFBridging.h" + +OF_ASSUME_NONNULL_BEGIN + +#ifdef __cplusplus +extern "C" { +#endif +extern int _OFSet_NSObject_reference; +#ifdef __cplusplus +} +#endif + +/*! + * @category OFSet (NSObject) \ + * OFSet+NSObject.h ObjFWBridge/OFSet+NSObject.h + * @brief Support for bridging OFSets to NSSets. + */ +@interface OFSet (NSObject) +@property (readonly, nonatomic) NSSet *NSObject; +@end + +OF_ASSUME_NONNULL_END ADDED src/bridge/OFSet+NSObject.m Index: src/bridge/OFSet+NSObject.m ================================================================== --- src/bridge/OFSet+NSObject.m +++ src/bridge/OFSet+NSObject.m @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "NSOFSet.h" + +#import "OFSet+NSObject.h" + +int _OFSet_NSObject_reference; + +@implementation OFSet (NSObject) +- (id)NSObject +{ + return [[[NSOFSet alloc] initWithOFSet: self] autorelease]; +} +@end Index: src/bridge/ObjFWBridge.h ================================================================== --- src/bridge/ObjFWBridge.h +++ src/bridge/ObjFWBridge.h @@ -17,13 +17,15 @@ #import "NSArray+OFObject.h" #import "NSDictionary+OFObject.h" #import "NSEnumerator+OFObject.h" #import "NSNumber+OFObject.h" +#import "NSSet+OFObject.h" #import "NSString+OFObject.h" #import "OFArray+NSObject.h" #import "OFException+Swift.h" #import "OFDictionary+NSObject.h" #import "OFEnumerator+NSObject.h" #import "OFNumber+NSObject.h" +#import "OFSet+NSObject.h" #import "OFString+NSObject.h"