ObjFW  Check-in [5207c4ea4d]

Overview
Comment:Prepare OFSet and OFMutableSet for OFCountedSet.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5207c4ea4dcb31330b25fb486101036fe57fc5b62f5cd7facf92f635c18da836
User & Date: js on 2011-07-26 18:12:58
Other Links: manifest | tags
Context
2011-07-26
21:42
Add OFCountedSet. check-in: eb791d09d1 user: js tags: trunk
18:12
Prepare OFSet and OFMutableSet for OFCountedSet. check-in: 5207c4ea4d user: js tags: trunk
2011-07-24
20:05
Add a few defines for runtime methods so they always have the same name. check-in: c7bc7b93d9 user: js tags: trunk
Changes

Modified src/OFMutableSet.m from [842dbccb4e] to [ff741b1139].

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

#include "config.h"

#define OF_MUTABLE_SET_M

#import "OFMutableSet.h"
#import "OFDictionary.h"
#import "OFNull.h"
#import "OFArray.h"
#import "OFAutoreleasePool.h"

@implementation OFMutableSet
- (void)addObject: (id)object
{
	[dictionary _setObject: [OFNull null]
			forKey: object
		       copyKey: NO];

	mutations++;
}

- (void)removeObject: (id)object







|
|





|







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

#include "config.h"

#define OF_MUTABLE_SET_M

#import "OFMutableSet.h"
#import "OFDictionary.h"
#import "OFArray.h"
#import "OFNumber.h"
#import "OFAutoreleasePool.h"

@implementation OFMutableSet
- (void)addObject: (id)object
{
	[dictionary _setObject: [OFNumber numberWithSize: 1]
			forKey: object
		       copyKey: NO];

	mutations++;
}

- (void)removeObject: (id)object

Modified src/OFSet.m from [055b4111d5] to [b1d260547d].

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "config.h"

#define OF_SET_M

#import "OFSet.h"
#import "OFDictionary.h"
#import "OFArray.h"
#import "OFNull.h"
#import "OFString.h"
#import "OFAutoreleasePool.h"

@implementation OFSet
+ set
{
	return [[[self alloc] init] autorelease];
}







|
|







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "config.h"

#define OF_SET_M

#import "OFSet.h"
#import "OFDictionary.h"
#import "OFArray.h"
#import "OFString.h"
#import "OFNumber.h"
#import "OFAutoreleasePool.h"

@implementation OFSet
+ set
{
	return [[[self alloc] init] autorelease];
}
66
67
68
69
70
71
72
73
74
75




76





77

78


79
80
81
82
83
84
85
86
87
88
89
90
91


92
93
94
95
96
97
98
99


100
101
102
103
104
105
106
	}

	return self;
}

- initWithSet: (OFSet*)set
{
	self = [super init];

	@try {




		dictionary = [[OFMutableDictionary alloc]





		    _initWithDictionary: set->dictionary

			       copyKeys: NO];


	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithArray: (OFArray*)array
{
	self = [self init];

	@try {


		id *cArray = [array cArray];
		size_t i, count = [array count];
		OFNull *null = [OFNull null];

		for (i = 0; i < count; i++)
			[dictionary _setObject: null
					forKey: cArray[i]
				       copyKey: NO];


	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}







|


>
>
>
>
|
>
>
>
>
>
|
>
|
>
>













>
>


<


|


>
>







66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

108
109
110
111
112
113
114
115
116
117
118
119
120
121
	}

	return self;
}

- initWithSet: (OFSet*)set
{
	self = [self init];

	@try {
		OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
		OFNumber *one = [OFNumber numberWithSize: 1];
		OFEnumerator *enumerator = [set objectEnumerator];
		id object;

		/*
		 * We can't just copy the dictionary as the specified set might
		 * be a counted set, but we're just a normal set.
		 */
		while ((object = [enumerator nextObject]) != nil)
			[dictionary _setObject: one
					forKey: object
				       copyKey: NO];

		[pool release];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithArray: (OFArray*)array
{
	self = [self init];

	@try {
		OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
		OFNumber *one = [OFNumber numberWithSize: 1];
		id *cArray = [array cArray];
		size_t i, count = [array count];


		for (i = 0; i < count; i++)
			[dictionary _setObject: one
					forKey: cArray[i]
				       copyKey: NO];

		[pool release];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
120
121
122
123
124
125
126

127
128
129
130
131
132
133
134
135
136
137


138
139
140
141
142
143
144

- initWithObject: (id)firstObject
       arguments: (va_list)arguments
{
	self = [self init];

	@try {

		OFNull *null = [OFNull null];
		id object;

		[dictionary _setObject: null
				forKey: firstObject
			       copyKey: NO];

		while ((object = va_arg(arguments, id)) != nil)
			[dictionary _setObject: null
					forKey: object
				       copyKey: NO];


	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}







>
|


|




|


>
>







135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

- initWithObject: (id)firstObject
       arguments: (va_list)arguments
{
	self = [self init];

	@try {
		OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
		OFNumber *one = [OFNumber numberWithSize: 1];
		id object;

		[dictionary _setObject: one
				forKey: firstObject
			       copyKey: NO];

		while ((object = va_arg(arguments, id)) != nil)
			[dictionary _setObject: one
					forKey: object
				       copyKey: NO];

		[pool release];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}