Index: src/bridge/Makefile ================================================================== --- src/bridge/Makefile +++ src/bridge/Makefile @@ -10,14 +10,16 @@ SRCS = OFArray+NSObject.m \ OFEnumerator+NSObject.m \ OFException+Swift.m \ OFDictionary+NSObject.m \ + OFNumber+NSObject.m \ OFString+NSObject.m \ NSArray+OFObject.m \ NSDictionary+OFObject.m \ NSEnumerator+OFObject.m \ + NSNumber+OFObject.m \ NSString+OFObject.m INCLUDES := ${SRCS:.m=.h} \ NSBridging.h \ OFBridging.h \ ADDED src/bridge/NSNumber+OFObject.h Index: src/bridge/NSNumber+OFObject.h ================================================================== --- src/bridge/NSNumber+OFObject.h +++ src/bridge/NSNumber+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 OFNumber; + +#ifdef __cplusplus +extern "C" { +#endif +extern int _NSNumber_OFObject_reference; +#ifdef __cplusplus +} +#endif + +/*! + * @category NSNumber (OFObject) + * NSNumber+OFObject.h ObjFWBridge/NSNumber+OFObject.h + * + * @brief Support for bridging NSNumbers to OFNumbers. + */ +@interface NSNumber (OFObject) +@property (readonly, nonatomic) OFNumber *OFObject; +@end + +OF_ASSUME_NONNULL_END ADDED src/bridge/NSNumber+OFObject.m Index: src/bridge/NSNumber+OFObject.m ================================================================== --- src/bridge/NSNumber+OFObject.m +++ src/bridge/NSNumber+OFObject.m @@ -0,0 +1,61 @@ +/* + * 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 "NSNumber+OFObject.h" +#import "OFNumber.h" + +#import "OFInvalidArgumentException.h" + +int _NSNumber_OFObject_reference; + +@implementation NSNumber (OFObject) +- (id)OFObject +{ + const char *type = self.objCType; + + if (strcmp(type, "c") == 0) + return [OFNumber numberWithChar: self.charValue]; + else if (strcmp(type, "C") == 0) + return [OFNumber numberWithUnsignedChar: + self.unsignedCharValue]; + else if (strcmp(type, "s") == 0) + return [OFNumber numberWithShort: self.shortValue]; + else if (strcmp(type, "S") == 0) + return [OFNumber numberWithUnsignedShort: + self.unsignedShortValue]; + else if (strcmp(type, "i") == 0) + return [OFNumber numberWithInt: self.intValue]; + else if (strcmp(type, "I") == 0) + return [OFNumber numberWithUnsignedInt: self.unsignedIntValue]; + else if (strcmp(type, "l") == 0) + return [OFNumber numberWithLong: self.longValue]; + else if (strcmp(type, "L") == 0) + return [OFNumber numberWithUnsignedLong: + self.unsignedLongValue]; + else if (strcmp(type, "q") == 0) + return [OFNumber numberWithLongLong: self.longLongValue]; + else if (strcmp(type, "Q") == 0) + return [OFNumber numberWithUnsignedLongLong: + self.unsignedLongLongValue]; + else if (strcmp(type, "f") == 0) + return [OFNumber numberWithFloat: self.floatValue]; + else if (strcmp(type, "d") == 0) + return [OFNumber numberWithDouble: self.doubleValue]; + + @throw [OFInvalidArgumentException exception]; +} +@end ADDED src/bridge/OFNumber+NSObject.h Index: src/bridge/OFNumber+NSObject.h ================================================================== --- src/bridge/OFNumber+NSObject.h +++ src/bridge/OFNumber+NSObject.h @@ -0,0 +1,50 @@ +/* + * 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 "OFNumber.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 _OFNumber_NSObject_reference; +#ifdef __cplusplus +} +#endif + +/*! + * @category OFNumber (NSObject) \ + * OFNumber+NSObject.h ObjFWBridge/OFNumber+NSObject.h + * + * @brief Support for bridging OFNumbers to NSNumbers. + */ +@interface OFNumber (NSObject) +@property (readonly, nonatomic) NSNumber *NSObject; +@end + +OF_ASSUME_NONNULL_END ADDED src/bridge/OFNumber+NSObject.m Index: src/bridge/OFNumber+NSObject.m ================================================================== --- src/bridge/OFNumber+NSObject.m +++ src/bridge/OFNumber+NSObject.m @@ -0,0 +1,64 @@ +/* + * 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 "OFNumber+NSObject.h" + +#import "OFInvalidArgumentException.h" + +int _OFNumber_NSObject_reference; + +@implementation OFNumber (NSObject) +- (id)NSObject +{ + const char *type = self.objCType; + + if (strcmp(type, "B") == 0) + return [NSNumber numberWithBool: self.boolValue]; + else if (strcmp(type, "c") == 0) + return [NSNumber numberWithChar: self.charValue]; + else if (strcmp(type, "C") == 0) + return [NSNumber numberWithUnsignedChar: + self.unsignedCharValue]; + else if (strcmp(type, "s") == 0) + return [NSNumber numberWithShort: self.shortValue]; + else if (strcmp(type, "S") == 0) + return [NSNumber numberWithUnsignedShort: + self.unsignedShortValue]; + else if (strcmp(type, "i") == 0) + return [NSNumber numberWithInt: self.intValue]; + else if (strcmp(type, "I") == 0) + return [NSNumber numberWithUnsignedInt: self.unsignedIntValue]; + else if (strcmp(type, "l") == 0) + return [NSNumber numberWithLong: self.longValue]; + else if (strcmp(type, "L") == 0) + return [NSNumber numberWithUnsignedLong: + self.unsignedLongValue]; + else if (strcmp(type, "q") == 0) + return [NSNumber numberWithLongLong: self.longLongValue]; + else if (strcmp(type, "Q") == 0) + return [NSNumber numberWithUnsignedLongLong: + self.unsignedLongLongValue]; + else if (strcmp(type, "f") == 0) + return [NSNumber numberWithFloat: self.floatValue]; + else if (strcmp(type, "d") == 0) + return [NSNumber numberWithDouble: self.doubleValue]; + + @throw [OFInvalidArgumentException exception]; +} +@end Index: src/bridge/ObjFWBridge.h ================================================================== --- src/bridge/ObjFWBridge.h +++ src/bridge/ObjFWBridge.h @@ -15,11 +15,15 @@ * file. */ #import "NSArray+OFObject.h" #import "NSDictionary+OFObject.h" +#import "NSEnumerator+OFObject.h" +#import "NSNumber+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 "OFString+NSObject.h"