Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -633,10 +633,20 @@ ]) AS_IF([test x"$objc_runtime" = x"Apple runtime"], [ AC_CHECK_HEADER(Foundation/NSObject.h, [ AC_SUBST(FOUNDATION_COMPAT_M, "foundation-compat.m") + AC_SUBST(BRIDGE, "bridge") + + AS_IF([test x"$enable_shared" != x"no"], [ + AC_SUBST(OBJFW_BRIDGE_SHARED_LIB, + "${LIB_PREFIX}objfw-bridge${LIB_SUFFIX}") + ]) + AS_IF([test x"$enable_static" = x"yes" \ + -o x"$enable_shared" = x"no"], [ + AC_SUBST(OBJFW_BRIDGE_STATIC_LIB, "libobjfw-bridge.a") + ]) ]) ]) AS_IF([test x"$GOBJC" = x"yes"], [ OBJCFLAGS="$OBJCFLAGS -Wwrite-strings -Wpointer-arith -Werror" Index: extra.mk.in ================================================================== --- extra.mk.in +++ extra.mk.in @@ -2,14 +2,18 @@ OBJFW_STATIC_LIB = @OBJFW_STATIC_LIB@ OBJFW_LIB_MAJOR = 6 OBJFW_LIB_MINOR = 0 OBJFW_LIB_MAJOR_MINOR = ${OBJFW_LIB_MAJOR}.${OBJFW_LIB_MINOR} +OBJFW_BRIDGE_SHARED_LIB = @OBJFW_BRIDGE_SHARED_LIB@ +OBJFW_BRIDGE_STATIC_LIB = @OBJFW_BRIDGE_STATIC_LIB@ + ASPRINTF_M = @ASPRINTF_M@ AUTORELEASE_M = @AUTORELEASE_M@ ATOMIC_H = @ATOMIC_H@ BIN_PREFIX = @BIN_PREFIX@ +BRIDGE = @BRIDGE@ EXCEPTIONS_A = @EXCEPTIONS_A@ EXCEPTIONS_EXCEPTIONS_A = @EXCEPTIONS_EXCEPTIONS_A@ EXCEPTIONS_EXCEPTIONS_LIB_A = @EXCEPTIONS_EXCEPTIONS_LIB_A@ EXCEPTIONS_LIB_A = @EXCEPTIONS_LIB_A@ FOUNDATION_COMPAT_M = @FOUNDATION_COMPAT_M@ Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -1,8 +1,8 @@ include ../extra.mk -SUBDIRS = exceptions ${RUNTIME} +SUBDIRS = exceptions ${RUNTIME} ${BRIDGE} SHARED_LIB = ${OBJFW_SHARED_LIB} STATIC_LIB = ${OBJFW_STATIC_LIB} LIB_MAJOR = ${OBJFW_LIB_MAJOR} LIB_MINOR = ${OBJFW_LIB_MINOR} @@ -111,5 +111,7 @@ include ../buildsys.mk CPPFLAGS += -I. -I.. -Iexceptions -Iruntime LD = ${OBJC} LDFLAGS += ${REEXPORT_LIBOBJC} ${MACH_ALIAS_LIST} + +${BRIDGE}: ${SHARED_LIB} ADDED src/bridge/Makefile Index: src/bridge/Makefile ================================================================== --- src/bridge/Makefile +++ src/bridge/Makefile @@ -0,0 +1,29 @@ +include ../../extra.mk + +SHARED_LIB = ${OBJFW_BRIDGE_SHARED_LIB} +STATIC_LIB = ${OBJFW_BRIDGE_STATIC_LIB} +LIB_MAJOR = ${OBJFW_LIB_MAJOR} +LIB_MINOR = ${OBJFW_LIB_MINOR} + +SRCS = OFArray+NSObject.m \ + OFArray_NSArray.m \ + OFDictionary+NSObject.m \ + OFDictionary_NSDictionary.m \ + OFString+NSObject.m \ + NSArray+OFObject.m \ + NSArray_OFArray.m \ + NSDictionary+OFObject.m \ + NSDictionary_OFDictionary.m \ + NSString+OFObject.m + +INCLUDES = ${SRCS:.m=.h} \ + OFBridging.h \ + NSBridging.h \ + bridge.h + +include ../../buildsys.mk + +CPPFLAGS += -I. -I.. -I../.. -I../exceptions +LD = ${OBJC} +LDFLAGS += -Wl,-flat_namespace,-undefined,suppress +LIBS = -L.. -lobjfw -framework Foundation 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/NSBridging.h Index: src/bridge/NSBridging.h ================================================================== --- src/bridge/NSBridging.h +++ src/bridge/NSBridging.h @@ -0,0 +1,31 @@ +/* + * 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. + */ + +/*! + * @brief A protocol implemented by classes supporting bridging Foundation + * objects to ObjFW objects. + */ +@protocol NSBridging +/*! + * @brief Returns an instance of an ObjFW object corresponding to the receiver. + * + * If possible, the original object is wrapped. If this is not possible, an + * autoreleased copy is created. + * + * @return The receiver as an ObjFW object + */ +- (id)OFObject; +@end ADDED src/bridge/NSDictionary+OFObject.h Index: src/bridge/NSDictionary+OFObject.h ================================================================== --- src/bridge/NSDictionary+OFObject.h +++ src/bridge/NSDictionary+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 NSDictionaries to OFDictionaries. + */ +@interface NSDictionary (OFObject) +@end ADDED src/bridge/NSDictionary+OFObject.m Index: src/bridge/NSDictionary+OFObject.m ================================================================== --- src/bridge/NSDictionary+OFObject.m +++ src/bridge/NSDictionary+OFObject.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 "NSDictionary+OFObject.h" +#import "OFDictionary_NSDictionary.h" + +@implementation NSDictionary (OFObject) +- (id)OFObject +{ + return [[[OFDictionary_NSDictionary alloc] + initWithNSDictionary: self] autorelease]; +} +@end ADDED src/bridge/NSDictionary_OFDictionary.h Index: src/bridge/NSDictionary_OFDictionary.h ================================================================== --- src/bridge/NSDictionary_OFDictionary.h +++ src/bridge/NSDictionary_OFDictionary.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 OFDictionary; + +@interface NSDictionary_OFDictionary: NSDictionary +{ + OFDictionary *dictionary; +} + +- initWithOFDictionary: (OFDictionary*)dictionary; +@end ADDED src/bridge/NSDictionary_OFDictionary.m Index: src/bridge/NSDictionary_OFDictionary.m ================================================================== --- src/bridge/NSDictionary_OFDictionary.m +++ src/bridge/NSDictionary_OFDictionary.m @@ -0,0 +1,56 @@ +/* + * 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 "NSDictionary_OFDictionary.h" +#import "OFDictionary.h" + +#import "NSBridging.h" +#import "OFBridging.h" + +@implementation NSDictionary_OFDictionary +- initWithOFDictionary: (OFDictionary*)dictionary_ +{ + if ((self = [super init]) != nil) { + @try { + dictionary = [dictionary_ retain]; + } @catch (id e) { + return nil; + } + } + + return self; +} + +- (id)objectForKey: (id)key +{ + id object; + + if ([key conformsToProtocol: @protocol(NSBridging)]) + key = [key OFObject]; + + object = [dictionary objectForKey: key]; + + if ([object conformsToProtocol: @protocol(OFBridging)]) + return [object NSObject]; + + return object; +} + +- (size_t)count +{ + return [dictionary count]; +} +@end ADDED src/bridge/NSString+OFObject.h Index: src/bridge/NSString+OFObject.h ================================================================== --- src/bridge/NSString+OFObject.h +++ src/bridge/NSString+OFObject.h @@ -0,0 +1,29 @@ +/* + * 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 NSStrings to OFStrings. + * + * Unfortunately, they need to be copied, as NSString is not capable of + * handling UCS-4 properly (a character of NSString is only 2 bytes, while a + * character of OFString is 4). + */ +@interface NSString (OFObject) +@end ADDED src/bridge/NSString+OFObject.m Index: src/bridge/NSString+OFObject.m ================================================================== --- src/bridge/NSString+OFObject.m +++ src/bridge/NSString+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 "NSString+OFObject.h" +#import "OFString.h" + +@implementation NSString (OFObject) +- (id)OFObject +{ + return [OFString stringWithUTF8String: [self UTF8String]]; +} +@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 ADDED src/bridge/OFBridging.h Index: src/bridge/OFBridging.h ================================================================== --- src/bridge/OFBridging.h +++ src/bridge/OFBridging.h @@ -0,0 +1,32 @@ +/* + * 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. + */ + +/*! + * @brief A protocol implemented by classes supporting bridging ObjFW objects + * to Foundation objects. + */ +@protocol OFBridging +/*! + * @brief Returns an instance of a Foundation object corresponding to the + * receiver. + * + * If possible, the original object is wrapped. If this is not possible, an + * autoreleased copy is created. + * + * @return The receiver as Foundation object + */ +- (id)NSObject; +@end ADDED src/bridge/OFDictionary+NSObject.h Index: src/bridge/OFDictionary+NSObject.h ================================================================== --- src/bridge/OFDictionary+NSObject.h +++ src/bridge/OFDictionary+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 "OFDictionary.h" + +#import "OFBridging.h" + +/*! + * @brief Support for bridging OFDictionaries to NSDictionaries. + */ +@interface OFDictionary (NSObject) +@end ADDED src/bridge/OFDictionary+NSObject.m Index: src/bridge/OFDictionary+NSObject.m ================================================================== --- src/bridge/OFDictionary+NSObject.m +++ src/bridge/OFDictionary+NSObject.m @@ -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 "NSDictionary_OFDictionary.h" + +#import "OFDictionary+NSObject.h" + +@implementation OFDictionary (NSObject) +- (id)NSObject +{ + return [[[NSDictionary_OFDictionary alloc] + initWithOFDictionary: self] autorelease]; +} +@end ADDED src/bridge/OFDictionary_NSDictionary.h Index: src/bridge/OFDictionary_NSDictionary.h ================================================================== --- src/bridge/OFDictionary_NSDictionary.h +++ src/bridge/OFDictionary_NSDictionary.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 "OFDictionary.h" + +@class NSDictionary; + +@interface OFDictionary_NSDictionary: OFDictionary +{ + NSDictionary *dictionary; +} + +- initWithNSDictionary: (NSDictionary*)dictionary; +@end ADDED src/bridge/OFDictionary_NSDictionary.m Index: src/bridge/OFDictionary_NSDictionary.m ================================================================== --- src/bridge/OFDictionary_NSDictionary.m +++ src/bridge/OFDictionary_NSDictionary.m @@ -0,0 +1,64 @@ +/* + * 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 "OFDictionary_NSDictionary.h" + +#import "NSBridging.h" +#import "OFBridging.h" + +#import "OFInitializationFailedException.h" + +@implementation OFDictionary_NSDictionary +- initWithNSDictionary: (NSDictionary*)dictionary_ +{ + self = [super init]; + + @try { + dictionary = [dictionary_ retain]; + + if (dictionary == nil) + @throw [OFInitializationFailedException + exceptionWithClass: isa]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (id)objectForKey: (id)key +{ + id object; + + if ([key conformsToProtocol: @protocol(OFBridging)]) + key = [key NSObject]; + + object = [dictionary objectForKey: key]; + + if ([object conformsToProtocol: @protocol(NSBridging)]) + return [object OFObject]; + + return object; +} + +- (size_t)count +{ + return [dictionary count]; +} +@end ADDED src/bridge/OFString+NSObject.h Index: src/bridge/OFString+NSObject.h ================================================================== --- src/bridge/OFString+NSObject.h +++ src/bridge/OFString+NSObject.h @@ -0,0 +1,28 @@ +/* + * 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 "OFString.h" +#import "OFBridging.h" + +/*! + * @brief Support for bridging OFStrings to NSStrings. + * + * Unfortunately, they need to be copied, as NSString is not capable of + * handling UCS-4 properly (a character of NSString is only 2 bytes, while a + * character of OFString is 4). + */ +@interface OFString (NSObject) +@end ADDED src/bridge/OFString+NSObject.m Index: src/bridge/OFString+NSObject.m ================================================================== --- src/bridge/OFString+NSObject.m +++ src/bridge/OFString+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 + +#import "OFString+NSObject.h" + +@implementation OFString (NSObject) +- (id)NSObject +{ + return [NSString stringWithUTF8String: [self UTF8String]]; +} +@end ADDED src/bridge/bridge.h Index: src/bridge/bridge.h ================================================================== --- src/bridge/bridge.h +++ src/bridge/bridge.h @@ -0,0 +1,21 @@ +/* + * 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 "NSString+OFObject.h" + +#import "OFArray+NSObject.h" +#import "OFString+NSObject.h"