Index: src/bridge/Makefile ================================================================== --- src/bridge/Makefile +++ src/bridge/Makefile @@ -3,11 +3,15 @@ SHARED_LIB = ${OBJFW_BRIDGE_SHARED_LIB} STATIC_LIB = ${OBJFW_BRIDGE_STATIC_LIB} LIB_MAJOR = ${OBJFW_LIB_MAJOR} LIB_MINOR = ${OBJFW_LIB_MINOR} -SRCS = OFString+NSObject.m \ +SRCS = OFArray+NSObject.m \ + OFArray_NSArray.m \ + OFString+NSObject.m \ + NSArray+OFObject.m \ + NSArray_OFArray.m \ NSString+OFObject.m INCLUDES = ${SRCS:.m=.h} \ OFBridging.h \ NSBridging.h \ ADDED src/bridge/NSArray+OFObject.h Index: src/bridge/NSArray+OFObject.h ================================================================== --- src/bridge/NSArray+OFObject.h +++ src/bridge/NSArray+OFObject.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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" + +/** + * \brief Support for bridging NSArrays to OFArrays. + */ +@interface NSArray (OFObject) +@end ADDED src/bridge/NSArray+OFObject.m Index: src/bridge/NSArray+OFObject.m ================================================================== --- src/bridge/NSArray+OFObject.m +++ src/bridge/NSArray+OFObject.m @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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 "NSArray+OFObject.h" +#import "OFArray_NSArray.h" + +@implementation NSArray (OFObject) +- (id)OFObject +{ + return [[[OFArray_NSArray alloc] initWithNSArray: self] autorelease]; +} +@end ADDED src/bridge/NSArray_OFArray.h Index: src/bridge/NSArray_OFArray.h ================================================================== --- src/bridge/NSArray_OFArray.h +++ src/bridge/NSArray_OFArray.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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 + +@class OFArray; + +@interface NSArray_OFArray: NSArray +{ + OFArray *array; +} + +- initWithOFArray: (OFArray*)array; +@end ADDED src/bridge/NSArray_OFArray.m Index: src/bridge/NSArray_OFArray.m ================================================================== --- src/bridge/NSArray_OFArray.m +++ src/bridge/NSArray_OFArray.m @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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 "NSArray_OFArray.h" +#import "OFArray.h" +#import "OFBridging.h" + +@implementation NSArray_OFArray +- initWithOFArray: (OFArray*)array_ +{ + if ((self = [super init]) != nil) { + @try { + array = [array_ retain]; + } @catch (id e) { + return nil; + } + } + + return self; +} + +- (id)objectAtIndex: (size_t)index +{ + id object = [array objectAtIndex: index]; + + if ([object conformsToProtocol: @protocol(OFBridging)]) + return [object NSObject]; + + return object; +} + +- (size_t)count +{ + return [array count]; +} +@end ADDED src/bridge/OFArray+NSObject.h Index: src/bridge/OFArray+NSObject.h ================================================================== --- src/bridge/OFArray+NSObject.h +++ src/bridge/OFArray+NSObject.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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 "OFArray.h" + +#import "OFBridging.h" + +/** + * \brief Support for bridging OFArrays to NSArrays. + */ +@interface OFArray (NSObject) +@end ADDED src/bridge/OFArray+NSObject.m Index: src/bridge/OFArray+NSObject.m ================================================================== --- src/bridge/OFArray+NSObject.m +++ src/bridge/OFArray+NSObject.m @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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 "NSArray_OFArray.h" + +#import "OFArray+NSObject.h" + +@implementation OFArray (NSObject) +- (id)NSObject +{ + return [[[NSArray_OFArray alloc] initWithOFArray: self] autorelease]; +} +@end ADDED src/bridge/OFArray_NSArray.h Index: src/bridge/OFArray_NSArray.h ================================================================== --- src/bridge/OFArray_NSArray.h +++ src/bridge/OFArray_NSArray.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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 "OFArray.h" + +@class NSArray; + +@interface OFArray_NSArray: OFArray +{ + NSArray *array; +} + +- initWithNSArray: (NSArray*)array; +@end ADDED src/bridge/OFArray_NSArray.m Index: src/bridge/OFArray_NSArray.m ================================================================== --- src/bridge/OFArray_NSArray.m +++ src/bridge/OFArray_NSArray.m @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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 "OFArray_NSArray.h" +#import "NSBridging.h" + +#import "OFInitializationFailedException.h" + +@implementation OFArray_NSArray +- initWithNSArray: (NSArray*)array_ +{ + self = [super init]; + + @try { + array = [array_ retain]; + + if (array == nil) + @throw [OFInitializationFailedException + exceptionWithClass: isa]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (id)objectAtIndex: (size_t)index +{ + id object = [array objectAtIndex: index]; + + if ([object conformsToProtocol: @protocol(NSBridging)]) + return [object OFObject]; + + return object; +} + +- (size_t)count +{ + return [array count]; +} +@end Index: src/bridge/bridge.h ================================================================== --- src/bridge/bridge.h +++ src/bridge/bridge.h @@ -12,8 +12,10 @@ * 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 "NSArray+OFObject.h" #import "NSString+OFObject.h" +#import "OFArray+NSObject.h" #import "OFString+NSObject.h"