ObjFW  Check-in [bf310bcc5d]

Overview
Comment:Add +[arrayWithCArray:length:] to OFArray.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: bf310bcc5dd21766c0683141d3c02d8b45ac4ae14a0e33057249956f09ca9eea
User & Date: js on 2010-02-07 12:40:55
Other Links: manifest | tags
Context
2010-02-07
14:09
Add +[superclass] to OFObject. check-in: 047af7a8ad user: js tags: trunk
12:40
Add +[arrayWithCArray:length:] to OFArray. check-in: bf310bcc5d user: js tags: trunk
2010-02-05
22:16
Conditional imports in ObjFW.h. check-in: a5c1129e8d user: js tags: trunk
Changes

Modified src/OFArray.h from [3e0b6e88ce] to [b25e7c62a4].

50
51
52
53
54
55
56











57
58
59
60
61
62
63
 * Creates a new OFArray with the objects from the specified C array.
 *
 * \param objs A C array of objects, terminated with nil
 * \return A new autoreleased OFArray
 */
+ arrayWithCArray: (OFObject**)objs;












/**
 * Initializes an OFArray with the specified object.
 *
 * \param obj An object
 * \return An initialized OFArray
 */
- initWithObject: (OFObject*)obj;







>
>
>
>
>
>
>
>
>
>
>







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
 * Creates a new OFArray with the objects from the specified C array.
 *
 * \param objs A C array of objects, terminated with nil
 * \return A new autoreleased OFArray
 */
+ arrayWithCArray: (OFObject**)objs;

/**
 * Creates a new OFArray with the objects from the specified C array of the
 * specified length.
 *
 * \param objs A C array of objects
 * \param len The length of the C array
 * \return A new autoreleased OFArray
 */
+ arrayWithCArray: (OFObject**)objs
	   length: (size_t)length;

/**
 * Initializes an OFArray with the specified object.
 *
 * \param obj An object
 * \return An initialized OFArray
 */
- initWithObject: (OFObject*)obj;
84
85
86
87
88
89
90











91
92
93
94
95
96
97
 * Initializes an OFArray with the objects from the specified C array.
 *
 * \param objs A C array of objects, terminated with nil
 * \return An initialized OFArray
 */
- initWithCArray: (OFObject**)objs;












/**
 * \return The number of objects in the array
 */
- (size_t)count;

/**
 * \return The objects of the array as a C array







>
>
>
>
>
>
>
>
>
>
>







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
 * Initializes an OFArray with the objects from the specified C array.
 *
 * \param objs A C array of objects, terminated with nil
 * \return An initialized OFArray
 */
- initWithCArray: (OFObject**)objs;

/**
 * Initializes an OFArray with the objects from the specified C array of the
 * specified length.
 *
 * \param objs A C array of objects
 * \param len The length of the C array
 * \return An initialized OFArray
 */
- initWithCArray: (OFObject**)objs
	  length: (size_t)len;

/**
 * \return The number of objects in the array
 */
- (size_t)count;

/**
 * \return The objects of the array as a C array

Modified src/OFArray.m from [cfc59d89e5] to [752a63309a].

43
44
45
46
47
48
49







50
51
52
53
54
55
56
	return ret;
}

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








- init
{
	self = [super init];

	@try {
		array = [[OFDataArray alloc]







>
>
>
>
>
>
>







43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
	return ret;
}

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

+ arrayWithCArray: (OFObject**)objs
	   length: (size_t)len
{
	return [[[self alloc] initWithCArray: objs
				      length: len] autorelease];
}

- init
{
	self = [super init];

	@try {
		array = [[OFDataArray alloc]
123
124
125
126
127
128
129




















130
131
132
133
134
135
136

	self = [self init];

	@try {
		for (obj = objs; *obj != nil; obj++) {
			[array addItem: obj];
			[*obj retain];




















		}
	} @catch (OFException *e) {
		[self dealloc];
		@throw e;
	}

	return self;







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







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

	self = [self init];

	@try {
		for (obj = objs; *obj != nil; obj++) {
			[array addItem: obj];
			[*obj retain];
		}
	} @catch (OFException *e) {
		[self dealloc];
		@throw e;
	}

	return self;
}

- initWithCArray: (OFObject**)objs
	  length: (size_t)len
{
	self = [self init];

	@try {
		size_t i;

		for (i = 0; i < len; i++) {
			[array addItem: objs + i];
			[objs[i] retain];
		}
	} @catch (OFException *e) {
		[self dealloc];
		@throw e;
	}

	return self;

Modified tests/OFArray.m from [e8b5e9e9d5] to [d47aa5b83d].

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
	nil
};

void
array_tests()
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFArray *a[2];
	OFMutableArray *m[2];
	OFEnumerator *enumerator;
	id obj;
	BOOL ok;
	size_t i;

	TEST(@"+[array]", (m[0] = [OFMutableArray array]))

	TEST(@"+[arrayWithObjects:]",
	    (a[0] = [OFArray arrayWithObjects: @"Foo", @"Bar", @"Baz", nil]))

	TEST(@"+[arrayWithCArray:]", (a[1] = [OFArray arrayWithCArray: c_ary]))






	TEST(@"-[addObject:]", [m[0] addObject: c_ary[0]] &&
	    [m[0] addObject: c_ary[2]])

	TEST(@"-[addObject:atIndex:]", [m[0] addObject: c_ary[1]
					       atIndex: 1])








|












>
>
>
>
>







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
	nil
};

void
array_tests()
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFArray *a[3];
	OFMutableArray *m[2];
	OFEnumerator *enumerator;
	id obj;
	BOOL ok;
	size_t i;

	TEST(@"+[array]", (m[0] = [OFMutableArray array]))

	TEST(@"+[arrayWithObjects:]",
	    (a[0] = [OFArray arrayWithObjects: @"Foo", @"Bar", @"Baz", nil]))

	TEST(@"+[arrayWithCArray:]", (a[1] = [OFArray arrayWithCArray: c_ary]))

	TEST(@"+[arrayWithCArray:length:]",
	    (a[2] = [OFArray arrayWithCArray: c_ary
				      length: 3]) &&
	    [a[2] isEqual: a[1]])

	TEST(@"-[addObject:]", [m[0] addObject: c_ary[0]] &&
	    [m[0] addObject: c_ary[2]])

	TEST(@"-[addObject:atIndex:]", [m[0] addObject: c_ary[1]
					       atIndex: 1])