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
78
79
80
81
82
83
84
85
86
87
88
89
|
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
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
|
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
+
-
+
-
+
-
+
-
-
-
-
+
-
+
-
+
|
#import "OFExceptions.h"
@implementation OFMutableArray
- (id)copy
{
OFArray *new = [[OFArray alloc] init];
OFObject **objs;
size_t len, i;
size_t count, i;
objs = [array cArray];
len = [array count];
count = [array count];
[new->array addNItems: len
[new->array addNItems: count
fromCArray: objs];
for (i = 0; i < len; i++)
for (i = 0; i < count; i++)
[objs[i] retain];
return new;
}
- addObject: (OFObject*)obj
{
[array addItem: &obj];
[obj retain];
return self;
}
- removeObject: (id)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: (id)obj
{
OFObject **objs = [array cArray];
size_t i, count = [array count];
for (i = 0; i < count; i++) {
if (objs[i] == obj) {
[obj release];
[array removeItemAtIndex: i];
}
}
return self;
}
- removeObjectAtIndex: (size_t)index
{
return [self removeNObjects: 1
atIndex: index];
}
- removeNObjects: (size_t)nobjects
{
OFObject **objs;
OFObject **objs = [array cArray];
size_t len, i;
objs = [array cArray];
len = [array count];
size_t i, count = [array count];
if (nobjects > len)
if (nobjects > count)
@throw [OFOutOfRangeException newWithClass: isa];
for (i = len - nobjects; i < len; i++)
for (i = count - nobjects; i < count; i++)
[objs[i] release];
[array removeNItems: nobjects];
return self;
}
- removeNObjects: (size_t)nobjects
atIndex: (size_t)index
{
OFObject **objs;
OFObject **objs = [array cArray];
size_t len, i;
objs = [array cArray];
len = [array count];
size_t i, count = [array count];
if (nobjects > len)
if (nobjects > count)
@throw [OFOutOfRangeException newWithClass: isa];
for (i = index; i < len && i < index + nobjects; i++)
for (i = index; i < count && i < index + nobjects; i++)
[objs[i] release];
[array removeNItems: nobjects
atIndex: index];
return self;
}
@end
|