ObjFW  Check-in [1e249becdf]

Overview
Comment:Add +[OFArray arrayWithArray:].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1e249becdf636af67a0a8aaee9f37aba85bfa2c6f251ddf310fa2ce968338d5b
User & Date: js on 2011-05-19 00:47:55
Other Links: manifest | tags
Context
2011-05-21
18:04
Make sure OF_ENDIANESS_NATIVE is always defined. check-in: 0158f764e3 user: js tags: trunk
2011-05-19
00:47
Add +[OFArray arrayWithArray:]. check-in: 1e249becdf user: js tags: trunk
2011-05-15
17:00
Make it possible to specify the byte order for Unicode / UTF-16. check-in: 3dad5e5803 user: js tags: trunk
Changes

Modified src/OFArray.h from [3c74f95010] to [a17707039e].

59
60
61
62
63
64
65








66
67
68
69
70
71
72
 * \brief Creates a new OFArray with the specified objects, terminated by nil.
 *
 * \param firstObject The first object in the array
 * \return A new autoreleased OFArray
 */
+ arrayWithObjects: (id)firstObject, ...;









/**
 * \brief Creates a new OFArray with the objects from the specified C array.
 *
 * \param objects A C array of objects, terminated with nil
 * \return A new autoreleased OFArray
 */
+ arrayWithCArray: (id*)objects;







>
>
>
>
>
>
>
>







59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
 * \brief Creates a new OFArray with the specified objects, terminated by nil.
 *
 * \param firstObject The first object in the array
 * \return A new autoreleased OFArray
 */
+ arrayWithObjects: (id)firstObject, ...;

/**
 * \brief Creates a new OFArray with the objects from the specified array.
 *
 * \param array An array
 * \return A new autoreleased OFArray
 */
+ arrayWithArray: (OFArray*)array;

/**
 * \brief Creates a new OFArray with the objects from the specified C array.
 *
 * \param objects A C array of objects, terminated with nil
 * \return A new autoreleased OFArray
 */
+ arrayWithCArray: (id*)objects;
104
105
106
107
108
109
110








111
112
113
114
115
116
117
 * \param firstObject The first object
 * \param arguments A va_list
 * \return An initialized OFArray
 */
- initWithObject: (id)firstObject
       arguments: (va_list)arguments;









/**
 * \brief Initializes an OFArray with the objects from the specified C array.
 *
 * \param objects A C array of objects, terminated with nil
 * \return An initialized OFArray
 */
- initWithCArray: (id*)objects;







>
>
>
>
>
>
>
>







112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
 * \param firstObject The first object
 * \param arguments A va_list
 * \return An initialized OFArray
 */
- initWithObject: (id)firstObject
       arguments: (va_list)arguments;

/**
 * \brief Initializes an OFArray with the objects from the specified array.
 *
 * \param array An array
 * \return An initialized OFArray
 */
- initWithArray: (OFArray*)array;

/**
 * \brief Initializes an OFArray with the objects from the specified C array.
 *
 * \param objects A C array of objects, terminated with nil
 * \return An initialized OFArray
 */
- initWithCArray: (id*)objects;

Modified src/OFArray.m from [7df94bcaeb] to [d444e53917].

48
49
50
51
52
53
54





55
56
57
58
59
60
61
	va_start(arguments, firstObject);
	ret = [[[self alloc] initWithObject: firstObject
				  arguments: arguments] autorelease];
	va_end(arguments);

	return ret;
}






+ arrayWithCArray: (id*)objects
{
	return [[[self alloc] initWithCArray: objects] autorelease];
}

+ arrayWithCArray: (id*)objects







>
>
>
>
>







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
	va_start(arguments, firstObject);
	ret = [[[self alloc] initWithObject: firstObject
				  arguments: arguments] autorelease];
	va_end(arguments);

	return ret;
}

+ arrayWithArray: (OFArray*)array
{
	return [[[self alloc] initWithArray: array] autorelease];
}

+ arrayWithCArray: (id*)objects
{
	return [[[self alloc] initWithCArray: objects] autorelease];
}

+ arrayWithCArray: (id*)objects
119
120
121
122
123
124
125




































126
127
128
129
130
131
132
		[firstObject retain];

		while ((object = va_arg(arguments, id)) != nil) {
			[array addItem: &object];
			[object retain];
		}
	} @catch (id e) {




































		[self release];
		@throw e;
	}

	return self;
}








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







124
125
126
127
128
129
130
131
132
133
134
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
163
164
165
166
167
168
169
170
171
172
173
		[firstObject retain];

		while ((object = va_arg(arguments, id)) != nil) {
			[array addItem: &object];
			[object retain];
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithArray: (OFArray*)array_
{
	id *cArray;
	size_t i, count;

	self = [self init];

	@try {
		cArray = [array_ cArray];
		count = [array_ count];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	@try {
		for (i = 0; i < count; i++)
			[cArray[i] retain];

		[array addNItems: count
		      fromCArray: cArray];
	} @catch (id e) {
		for (i = 0; i < count; i++)
			[cArray[i] release];

		/* Prevent double-release of objects */
		[array release];
		array = nil;

		[self release];
		@throw e;
	}

	return self;
}

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
- copy
{
	return [self retain];
}

- mutableCopy
{
	OFArray *mutableCopy = [[OFMutableArray alloc] init];
	id *cArray;
	size_t count, i;

	cArray = [array cArray];
	count = [array count];

	[mutableCopy->array addNItems: count
			   fromCArray: cArray];

	for (i = 0; i < count; i++)
		[cArray[i] retain];

	return mutableCopy;
}

- (id)objectAtIndex: (size_t)index
{
	return *((id*)[array itemAtIndex: index]);
}








|
<
<
<
<
<
<
<
<
<
<
<
<
<







238
239
240
241
242
243
244
245













246
247
248
249
250
251
252
- copy
{
	return [self retain];
}

- mutableCopy
{
	return [[OFMutableArray alloc] initWithArray: self];













}

- (id)objectAtIndex: (size_t)index
{
	return *((id*)[array itemAtIndex: index]);
}

Modified src/OFMutableArray.m from [26e57101fb] to [cc5ed55b35].

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
#import "OFEnumerationMutationException.h"
#import "OFInvalidArgumentException.h"
#import "OFOutOfRangeException.h"

@implementation OFMutableArray
- copy
{
	OFArray *copy = [[OFArray alloc] init];
	id *cArray = [array cArray];
	size_t i, count = [array count];

	[copy->array addNItems: count
		    fromCArray: cArray];

	for (i = 0; i < count; i++)
		[cArray[i] retain];

	return copy;
}

- (void)addObject: (id)object
{
	[array addItem: &object];
	[object retain];








|
<
<
<
<
<
<
<
<
<
<







25
26
27
28
29
30
31
32










33
34
35
36
37
38
39
#import "OFEnumerationMutationException.h"
#import "OFInvalidArgumentException.h"
#import "OFOutOfRangeException.h"

@implementation OFMutableArray
- copy
{
	return [[OFArray alloc] initWithArray: self];










}

- (void)addObject: (id)object
{
	[array addItem: &object];
	[object retain];