Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -224,16 +224,19 @@ AC_ARG_ENABLE(shared, AS_HELP_STRING([--disable-shared], [do not build shared library])) AS_IF([test x"$enable_shared" != x"no"], [ BUILDSYS_SHARED_LIB AC_SUBST(OBJFW_SHARED_LIB, "${LIB_PREFIX}objfw${LIB_SUFFIX}") + AC_SUBST(OBJFW_BRIDGE_SHARED_LIB, + "${LIB_PREFIX}objfw-bridge${LIB_SUFFIX}") AC_SUBST(EXCEPTIONS_LIB_A, "exceptions.lib.a") AC_SUBST(EXCEPTIONS_EXCEPTIONS_LIB_A, "exceptions/exceptions.lib.a") ]) AC_ARG_ENABLE(static, AS_HELP_STRING([--enable-static], [build static library])) AS_IF([test x"$enable_static" = x"yes" -o x"$enable_shared" = x"no"], [ AC_SUBST(OBJFW_STATIC_LIB, "libobjfw.a") + AC_SUBST(OBJFW_BRIDGE_STATIC_LIB, "libobjfw-bridge.a") AC_SUBST(EXCEPTIONS_A, "exceptions.a") AC_SUBST(EXCEPTIONS_EXCEPTIONS_A, "exceptions/exceptions.a") ]) AC_DEFINE_UNQUOTED(PLUGIN_SUFFIX, "$PLUGIN_SUFFIX", [Suffix for plugins]) @@ -593,10 +596,11 @@ ]) AS_IF([test x"$objc_runtime" = x"Apple"], [ AC_CHECK_HEADER(Foundation/NSObject.h, [ AC_SUBST(FOUNDATION_COMPAT_M, "foundation-compat.m") + AC_SUBST(BRIDGE, "bridge") ]) ]) 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,13 +2,17 @@ OBJFW_STATIC_LIB = @OBJFW_STATIC_LIB@ OBJFW_LIB_MAJOR = 5 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@ 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 +SUBDIRS = exceptions ${BRIDGE} SHARED_LIB = ${OBJFW_SHARED_LIB} STATIC_LIB = ${OBJFW_STATIC_LIB} LIB_MAJOR = ${OBJFW_LIB_MAJOR} LIB_MINOR = ${OBJFW_LIB_MINOR} ADDED src/bridge/Makefile Index: src/bridge/Makefile ================================================================== --- src/bridge/Makefile +++ src/bridge/Makefile @@ -0,0 +1,20 @@ +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 = OFString+NSObject.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 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/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/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/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,19 @@ +/* + * 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+NSObject.h"