Index: src/bridge/Makefile ================================================================== --- src/bridge/Makefile +++ src/bridge/Makefile @@ -3,22 +3,26 @@ 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 \ - OFString+NSObject.m \ - NSArray+OFObject.m \ - NSArray_OFArray.m \ +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 + OFBridging.h \ + NSBridging.h \ + bridge.h include ../../buildsys.mk CPPFLAGS += -I. -I.. -I../.. -I../exceptions LD = ${OBJC} LDFLAGS += -Wl,-flat_namespace,-undefined,suppress 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/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