ObjFW  Check-in [29ccaef03b]

Overview
Comment:bridge: Add bridge for {OF,NS}Set
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 29ccaef03bc76bb8bc2e81ad80d796228b6b66ce867f51037a937656ff0d045e
User & Date: js on 2019-06-21 00:09:08
Other Links: manifest | tags
Context
2019-06-23
16:00
objfw-compile: Add --help check-in: dedb037552 user: js tags: trunk
2019-06-21
00:09
bridge: Add bridge for {OF,NS}Set check-in: 29ccaef03b user: js tags: trunk
2019-06-20
23:47
Avoid retaining enumerator during fast enumeration check-in: 13864f512c user: js tags: trunk
Changes

Modified src/bridge/Makefile from [b9279e9d57] to [5a2e1acbf4].

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
LIB_MINOR = ${OBJFW_LIB_MINOR}

SRCS = OFArray+NSObject.m	\
       OFEnumerator+NSObject.m	\
       OFException+Swift.m	\
       OFDictionary+NSObject.m	\
       OFNumber+NSObject.m	\

       OFString+NSObject.m	\
       NSArray+OFObject.m	\
       NSDictionary+OFObject.m	\
       NSEnumerator+OFObject.m	\
       NSNumber+OFObject.m	\

       NSString+OFObject.m

INCLUDES := ${SRCS:.m=.h}	\
	    NSBridging.h	\
	    OFBridging.h	\
	    ObjFWBridge.h

SRCS += NSOFArray.m		\
	NSOFDictionary.m	\
	NSOFEnumerator.m	\

	OFNSArray.m		\
	OFNSDictionary.m	\
	OFNSEnumerator.m


includesubdir = ObjFWBridge

include ../../buildsys.mk

CPPFLAGS += -I. -I.. -I../.. -I../exceptions -DOF_BRIDGE_LOCAL_INCLUDES
LD = ${OBJC}
FRAMEWORK_LIBS := -framework Foundation -F.. -framework ObjFW ${LIBS}
LIBS := -framework Foundation -L.. -lobjfw ${LIBS}







>





>










>


|
>









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
LIB_MINOR = ${OBJFW_LIB_MINOR}

SRCS = OFArray+NSObject.m	\
       OFEnumerator+NSObject.m	\
       OFException+Swift.m	\
       OFDictionary+NSObject.m	\
       OFNumber+NSObject.m	\
       OFSet+NSObject.m		\
       OFString+NSObject.m	\
       NSArray+OFObject.m	\
       NSDictionary+OFObject.m	\
       NSEnumerator+OFObject.m	\
       NSNumber+OFObject.m	\
       NSSet+OFObject.m		\
       NSString+OFObject.m

INCLUDES := ${SRCS:.m=.h}	\
	    NSBridging.h	\
	    OFBridging.h	\
	    ObjFWBridge.h

SRCS += NSOFArray.m		\
	NSOFDictionary.m	\
	NSOFEnumerator.m	\
	NSOFSet.m		\
	OFNSArray.m		\
	OFNSDictionary.m	\
	OFNSEnumerator.m	\
	OFNSSet.m

includesubdir = ObjFWBridge

include ../../buildsys.mk

CPPFLAGS += -I. -I.. -I../.. -I../exceptions -DOF_BRIDGE_LOCAL_INCLUDES
LD = ${OBJC}
FRAMEWORK_LIBS := -framework Foundation -F.. -framework ObjFW ${LIBS}
LIBS := -framework Foundation -L.. -lobjfw ${LIBS}

Added src/bridge/NSOFSet.h version [ecd8b85750].





































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * 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/NSSet.h>

#import "macros.h"

@class OFSet;

OF_ASSUME_NONNULL_BEGIN

@interface NSOFSet: NSSet
{
	OFSet *_set;
}

- (instancetype)initWithOFSet: (OFSet *)set;
@end

OF_ASSUME_NONNULL_END

Added src/bridge/NSOFSet.m version [4d8161701e].













































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
65
66
67
68
69
70
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * 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 "NSOFSet.h"
#import "OFEnumerator+NSObject.h"
#import "OFSet.h"

#import "OFBridging.h"
#import "NSBridging.h"

#import "OFOutOfRangeException.h"

@implementation NSOFSet
- (instancetype)initWithOFSet: (OFSet *)set
{
	if ((self = [super init]) != nil)
		_set = [set retain];

	return self;
}

- (void)dealloc
{
	[_set release];

	[super dealloc];
}

- (id)member: (id)object
{
	id originalObject = object;

	if ([(NSObject *)object conformsToProtocol: @protocol(NSBridging)])
		object = [object OFObject];

	if ([_set containsObject: object])
		return originalObject;

	return nil;
}

- (NSUInteger)count
{
	size_t count = _set.count;

	if (count > NSUIntegerMax)
		@throw [OFOutOfRangeException exception];

	return (NSUInteger)count;
}

- (NSEnumerator *)objectEnumerator
{
	return [_set objectEnumerator].NSObject;
}
@end

Added src/bridge/NSSet+OFObject.h version [95644fdbb4].

























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * 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/NSSet.h>

#import "NSBridging.h"

OF_ASSUME_NONNULL_BEGIN

@class OFSet OF_GENERIC(ObjectType);

#ifdef __cplusplus
extern "C" {
#endif
extern int _NSSet_OFObject_reference;
#ifdef __cplusplus
}
#endif

/*!
 * @category NSSet (OFObject)
 *	     NSSet+OFObject.h ObjFWBridge/NSSet+OFObject.h
 *
 * @brief Support for bridging NSSets to OFSets.
 */
@interface NSSet (OFObject) <NSBridging>
@property (readonly, nonatomic) OFSet *OFObject;
@end

OF_ASSUME_NONNULL_END

Added src/bridge/NSSet+OFObject.m version [58ed03c5dd].

























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * 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 "NSSet+OFObject.h"
#import "OFNSSet.h"

int _NSSet_OFObject_reference;

@implementation NSSet (OFObject)
- (id)OFObject
{
	return [[[OFNSSet alloc] initWithNSSet: self] autorelease];
}
@end

Added src/bridge/OFNSSet.h version [ba268dd3f1].

















































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * 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.
 */

#ifdef OF_BRIDGE_LOCAL_INCLUDES
# import "OFSet.h"
#else
# if defined(__has_feature) && __has_feature(modules)
@import ObjFW;
# else
#  import <ObjFW/OFSet.h>
# endif
#endif

OF_ASSUME_NONNULL_BEGIN

@class NSSet;

@interface OFNSSet: OFSet
{
	NSSet *_set;
}

- (instancetype)initWithNSSet: (NSSet *)set;
@end

OF_ASSUME_NONNULL_END

Added src/bridge/OFNSSet.m version [e04047bc2d].



























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * 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/NSSet.h>

#import "OFNSSet.h"
#import "NSEnumerator+OFObject.h"

#import "OFBridging.h"
#import "NSBridging.h"

#import "OFInvalidArgumentException.h"
#import "OFOutOfRangeException.h"

@implementation OFNSSet
- (instancetype)initWithNSSet: (NSSet *)set
{
	self = [super init];

	@try {
		if (set == nil)
			@throw [OFInvalidArgumentException exception];

		_set = [set retain];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_set release];

	[super dealloc];
}

- (bool)containsObject: (id)object
{
	void *pool = objc_autoreleasePoolPush();
	bool ret;

	if ([(OFObject *)object conformsToProtocol: @protocol(OFBridging)])
		object = [object NSObject];

	ret = [_set containsObject: object];

	objc_autoreleasePoolPop(pool);
	return ret;
}

- (size_t)count
{
	return _set.count;
}

- (OFEnumerator *)objectEnumerator
{
	return [_set objectEnumerator].OFObject;
}
@end

Added src/bridge/OFSet+NSObject.h version [d0cfc416f0].



































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * 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.
 */

#ifdef OF_BRIDGE_LOCAL_INCLUDES
# import "OFSet.h"
#else
# if defined(__has_feature) && __has_feature(modules)
@import ObjFW;
# else
#  import <ObjFW/OFSet.h>
# endif
#endif

#import "OFBridging.h"

OF_ASSUME_NONNULL_BEGIN

#ifdef __cplusplus
extern "C" {
#endif
extern int _OFSet_NSObject_reference;
#ifdef __cplusplus
}
#endif

/*!
 * @category OFSet (NSObject) \
 *	     OFSet+NSObject.h ObjFWBridge/OFSet+NSObject.h
 * @brief Support for bridging OFSets to NSSets.
 */
@interface OFSet (NSObject) <OFBridging>
@property (readonly, nonatomic) NSSet *NSObject;
@end

OF_ASSUME_NONNULL_END

Added src/bridge/OFSet+NSObject.m version [30afb08cab].



























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * 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 "NSOFSet.h"

#import "OFSet+NSObject.h"

int _OFSet_NSObject_reference;

@implementation OFSet (NSObject)
- (id)NSObject
{
	return [[[NSOFSet alloc] initWithOFSet: self] autorelease];
}
@end

Modified src/bridge/ObjFWBridge.h from [5613e41fd6] to [508b2276c9].

15
16
17
18
19
20
21

22
23
24
25
26
27
28

29
 * file.
 */

#import "NSArray+OFObject.h"
#import "NSDictionary+OFObject.h"
#import "NSEnumerator+OFObject.h"
#import "NSNumber+OFObject.h"

#import "NSString+OFObject.h"

#import "OFArray+NSObject.h"
#import "OFException+Swift.h"
#import "OFDictionary+NSObject.h"
#import "OFEnumerator+NSObject.h"
#import "OFNumber+NSObject.h"

#import "OFString+NSObject.h"







>







>

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 * file.
 */

#import "NSArray+OFObject.h"
#import "NSDictionary+OFObject.h"
#import "NSEnumerator+OFObject.h"
#import "NSNumber+OFObject.h"
#import "NSSet+OFObject.h"
#import "NSString+OFObject.h"

#import "OFArray+NSObject.h"
#import "OFException+Swift.h"
#import "OFDictionary+NSObject.h"
#import "OFEnumerator+NSObject.h"
#import "OFNumber+NSObject.h"
#import "OFSet+NSObject.h"
#import "OFString+NSObject.h"