ObjFW  Check-in [898f6b5fbb]

Overview
Comment:Add bridging for dictionaries.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bridge
Files: files | file ages | folders
SHA3-256: 898f6b5fbb8238478f8dde973c2e2a85995218ad2048f12d38c4220c6e885a5b
User & Date: js on 2012-03-29 08:56:27
Other Links: branch diff | manifest | tags
Context
2012-10-29
09:18
Merge branch 'bridge' check-in: 1cb9a5edb8 user: js tags: trunk
2012-03-29
08:56
Add bridging for dictionaries. Closed-Leaf check-in: 898f6b5fbb user: js tags: bridge
2012-03-27
09:42
Merge branch 'master' into bridge check-in: 2933c425bf user: js tags: bridge
Changes

Modified src/bridge/Makefile from [326589f960] to [3817e595cf].

1
2
3
4
5
6
7
8
9


10
11
12


13
14
15
16
17
18
19
20
21
22
23
24
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	\


       OFString+NSObject.m	\
       NSArray+OFObject.m	\
       NSArray_OFArray.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







|
|
>
>
|
|
|
>
>



|
|
|






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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

Added src/bridge/NSDictionary+OFObject.h version [04d94283dc].



















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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 <Foundation/NSDictionary.h>

#import "NSBridging.h"

/**
 * \brief Support for bridging NSDictionaries to OFDictionaries.
 */
@interface NSDictionary (OFObject) <NSBridging>
@end

Added src/bridge/NSDictionary+OFObject.m version [8c223e7b6f].





















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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 version [44a026bf0b].























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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 <Foundation/NSDictionary.h>

@class OFDictionary;

@interface NSDictionary_OFDictionary: NSDictionary
{
	OFDictionary *dictionary;
}

- initWithOFDictionary: (OFDictionary*)dictionary;
@end

Added src/bridge/NSDictionary_OFDictionary.m version [68c180ab17].

















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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 version [12cb4e155f].



















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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) <OFBridging>
@end

Added src/bridge/OFDictionary+NSObject.m version [5dd6136b07].























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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 version [7d546035fe].























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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 version [6cf43a6add].

































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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 <Foundation/NSDictionary.h>

#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