ObjFW  Check-in [c0326c7cc5]

Overview
Comment:Add -[replaceObject:withObject:] and others to OFMutableArray.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c0326c7cc5ec7d9bb97f9252d2db1789f8aea2f392b664f5e12f53bdd59d33ec
User & Date: js on 2009-12-17 11:26:21
Other Links: manifest | tags
Context
2009-12-17
13:20
Update buildsys. check-in: 50e7f419d0 user: js tags: trunk
11:26
Add -[replaceObject:withObject:] and others to OFMutableArray. check-in: c0326c7cc5 user: js tags: trunk
10:53
Further improve OFTCPSocket. check-in: 1f7898f109 user: js tags: trunk
Changes

Modified src/OFArray.h from [42a4f34f59] to [0ec06e8b4f].

135
136
137
138
139
140
141






142
143
144
145
146
147
148
149
150
151
 * \return A string containing all objects joined by the separator
 */
- (OFString*)componentsJoinedByString: (OFString*)separator;

- addObject: (OFObject*)obj;
- addObject: (OFObject*)obj
    atIndex: (size_t)index;






- removeObject: (OFObject*)obj;
- removeObjectIdenticalTo: (OFObject*)obj;
- removeObjectAtIndex: (size_t)index;
- removeNObjects: (size_t)nobjects;
- removeNObjects: (size_t)nobjects
	 atIndex: (size_t)index;
@end

#import "OFMutableArray.h"
#import "OFString.h"







>
>
>
>
>
>










135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
 * \return A string containing all objects joined by the separator
 */
- (OFString*)componentsJoinedByString: (OFString*)separator;

- addObject: (OFObject*)obj;
- addObject: (OFObject*)obj
    atIndex: (size_t)index;
- replaceObject: (OFObject*)old
     withObject: (OFObject*)new;
- replaceObjectAtIndex: (size_t)index
	    withObject: (OFObject*)obj;
- replaceObjectIdenticalTo: (OFObject*)old
		withObject: (OFObject*)new;
- removeObject: (OFObject*)obj;
- removeObjectIdenticalTo: (OFObject*)obj;
- removeObjectAtIndex: (size_t)index;
- removeNObjects: (size_t)nobjects;
- removeNObjects: (size_t)nobjects
	 atIndex: (size_t)index;
@end

#import "OFMutableArray.h"
#import "OFString.h"

Modified src/OFArray.m from [29164ac41a] to [1587b7303a].

306
307
308
309
310
311
312





















313
314
315
316
317
318
319
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- addObject: (OFObject*)obj
    atIndex: (size_t)index





















{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- removeObject: (OFObject*)obj
{







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







306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- addObject: (OFObject*)obj
    atIndex: (size_t)index
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- replaceObject: (OFObject*)old
     withObject: (OFObject*)new
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- replaceObjectAtIndex: (size_t)index
	    withObject: (OFObject*)obj
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- replaceObjectIdenticalTo: (OFObject*)old
		withObject: (OFObject*)new
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- removeObject: (OFObject*)obj
{

Modified src/OFMutableArray.h from [76c7e15d21] to [f34526b684].

29
30
31
32
33
34
35





























36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 * \param obj An object to add
 * \param index The index where the object should be added
 */
- addObject: (OFObject*)obj
    atIndex: (size_t)index;

/**





























 * Removes the first object equivalent to the specified object.
 *
 * \param obj The object to remove
 */
- removeObject: (OFObject*)obj;

/**
 * Removes the first object that has the same address as the specified object.
 *
 * \param obj The object to remove
 */
- removeObjectIdenticalTo: (OFObject*)obj;

/**
 * Removes the object at the specified index.







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






|







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
78
79
 * \param obj An object to add
 * \param index The index where the object should be added
 */
- addObject: (OFObject*)obj
    atIndex: (size_t)index;

/**
 * Replaces all objects equivalent to the first specified object with the
 * second specified object.
 *
 * \param old The object to replace
 * \param new The replacement object
 */
- replaceObject: (OFObject*)old
     withObject: (OFObject*)new;

/**
 * Replaces the object at the specified index with the specified object.
 *
 * \param index The index of the object to replace
 * \param obj The replacement object
 */
- replaceObjectAtIndex: (size_t)index
	    withObject: (OFObject*)obj;

/**
 * Replaces all objects that have the same address as the first specified object
 * with the second specified object.
 *
 * \param old The object to replace
 * \param new The replacement object
 */
- replaceObjectIdenticalTo: (OFObject*)old
		withObject: (OFObject*)new;

/**
 * Removes all objects equivalent to the specified object.
 *
 * \param obj The object to remove
 */
- removeObject: (OFObject*)obj;

/**
 * Removes all objects that have the same address as the specified object.
 *
 * \param obj The object to remove
 */
- removeObjectIdenticalTo: (OFObject*)obj;

/**
 * Removes the object at the specified index.

Modified src/OFMutableArray.m from [b93f8c643f] to [3bbaec8fd0].

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
{
	[array addItem: &obj
	       atIndex: index];
	[obj retain];

	return self;
}


















































- removeObject: (OFObject*)obj
{
	OFObject **objs = [array cArray];
	size_t i, count = [array count];

	for (i = 0; i < count; i++) {
		if ([objs[i] isEqual: obj]) {
			[objs[i] release];
			[array removeItemAtIndex: i];
			return self;
		}
	}

	return self;
}

- removeObjectIdenticalTo: (OFObject*)obj







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










<







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
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
{
	[array addItem: &obj
	       atIndex: index];
	[obj retain];

	return self;
}

- replaceObject: (OFObject*)old
     withObject: (OFObject*)new
{
	OFObject **objs = [array cArray];
	size_t i, count = [array count];

	for (i = 0; i < count; i++) {
		if ([objs[i] isEqual: old]) {
			[new retain];
			[objs[i] release];
			objs[i] = new;
		}
	}

	return self;
}

- replaceObjectAtIndex: (size_t)index
	    withObject: (OFObject*)obj
{
	OFObject **objs = [array cArray];

	if (index >= [array count])
		@throw [OFOutOfRangeException newWithClass: isa];

	[obj retain];
	[objs[index] release];
	objs[index] = obj;

	return self;
}

- replaceObjectIdenticalTo: (OFObject*)old
		withObject: (OFObject*)new
{
	OFObject **objs = [array cArray];
	size_t i, count = [array count];

	for (i = 0; i < count; i++) {
		if (objs[i] == old) {
			[new retain];
			[objs[i] release];
			objs[i] = new;
		}
	}

	return self;
}

- removeObject: (OFObject*)obj
{
	OFObject **objs = [array cArray];
	size_t i, count = [array count];

	for (i = 0; i < count; i++) {
		if ([objs[i] isEqual: obj]) {
			[objs[i] release];
			[array removeItemAtIndex: i];

		}
	}

	return self;
}

- removeObjectIdenticalTo: (OFObject*)obj

Modified tests/OFArray.m from [4179341566] to [dad59ff475].

62
63
64
65
66
67
68





















69
70
71
72
73
74
75
	    [[a[2] objectAtIndex: 2] isEqual: c_ary[2]])

	TEST(@"-[indexOfObject:]", [a[0] indexOfObject: c_ary[1]] == 1)

	TEST(@"-[indexOfObjectIdenticalTo:]",
	    [a[0] indexOfObjectIdenticalTo: c_ary[1]] == 1)






















	TEST(@"-[removeObject:]",
	    [a[0] removeObject: c_ary[1]] && [a[0] count] == 2)

	TEST(@"-[removeObjectIdenticalTo:]",
	    [a[0] removeObjectIdenticalTo: c_ary[2]] && [a[0] count] == 1)

	[a[0] addObject: c_ary[0]];







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







62
63
64
65
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
	    [[a[2] objectAtIndex: 2] isEqual: c_ary[2]])

	TEST(@"-[indexOfObject:]", [a[0] indexOfObject: c_ary[1]] == 1)

	TEST(@"-[indexOfObjectIdenticalTo:]",
	    [a[0] indexOfObjectIdenticalTo: c_ary[1]] == 1)

	TEST(@"-[replaceObject:withObject:]",
	    [a[0] replaceObject: c_ary[1]
		     withObject: c_ary[0]] &&
	    [[a[0] objectAtIndex: 0] isEqual: c_ary[0]] &&
	    [[a[0] objectAtIndex: 1] isEqual: c_ary[0]] &&
	    [[a[0] objectAtIndex: 2] isEqual: c_ary[2]])

	TEST(@"-[replaceObject:identicalTo:]",
	    [a[0] replaceObjectIdenticalTo: c_ary[0]
				withObject: c_ary[1]] &&
	    [[a[0] objectAtIndex: 0] isEqual: c_ary[1]] &&
	    [[a[0] objectAtIndex: 1] isEqual: c_ary[1]] &&
	    [[a[0] objectAtIndex: 2] isEqual: c_ary[2]])

	TEST(@"-[replaceObjectAtIndex:withObject:]",
	    [a[0] replaceObjectAtIndex: 0
			    withObject: c_ary[0]] &&
	    [[a[0] objectAtIndex: 0] isEqual: c_ary[0]] &&
	    [[a[0] objectAtIndex: 1] isEqual: c_ary[1]] &&
	    [[a[0] objectAtIndex: 2] isEqual: c_ary[2]])

	TEST(@"-[removeObject:]",
	    [a[0] removeObject: c_ary[1]] && [a[0] count] == 2)

	TEST(@"-[removeObjectIdenticalTo:]",
	    [a[0] removeObjectIdenticalTo: c_ary[2]] && [a[0] count] == 1)

	[a[0] addObject: c_ary[0]];