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
114
115
116
117
118
119
120
121
|
+ (instancetype)arrayWithArray: (OFArray*)array
range: (of_range_t)range
{
return [[[self alloc] initWithArray: array
range: range] autorelease];
}
- initWithArray: (OFArray*)array_
range: (of_range_t)range_
{
self = [super init];
@try {
/* Should usually be retain, as it's useless with a copy */
array = [array_ copy];
range = range_;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[array release];
[super dealloc];
}
- (size_t)count
{
return range.length;
}
- (id)objectAtIndex: (size_t)index
{
if (index >= range.length)
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
return [array objectAtIndex: index + range.location];
}
- (void)getObjects: (id*)buffer
inRange: (of_range_t)range_
{
if (range_.length > SIZE_MAX - range_.location ||
range_.location + range_.length > range.length)
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
range_.location += range.location;
return [array getObjects: buffer
inRange: range_];
}
- (size_t)indexOfObject: (id)object
{
size_t index = [array indexOfObject: object];
if (index < range.location)
return OF_NOT_FOUND;
index -= range.location;
if (index >= range.length)
return OF_NOT_FOUND;
return index;
}
- (size_t)indexOfObjectIdenticalTo: (id)object
{
size_t index = [array indexOfObjectIdenticalTo: object];
if (index < range.location)
return OF_NOT_FOUND;
index -= range.location;
if (index >= range.length)
return OF_NOT_FOUND;
return index;
}
- (OFArray*)objectsInRange: (of_range_t)range_
{
if (range_.length > SIZE_MAX - range_.location ||
range_.location + range_.length > range.length)
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
range_.location += range.location;
return [array objectsInRange: range_];
}
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
114
115
116
117
118
119
120
121
|
+ (instancetype)arrayWithArray: (OFArray*)array
range: (of_range_t)range
{
return [[[self alloc] initWithArray: array
range: range] autorelease];
}
- initWithArray: (OFArray*)array
range: (of_range_t)range
{
self = [super init];
@try {
/* Should usually be retain, as it's useless with a copy */
_array = [array copy];
_range = range;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_array release];
[super dealloc];
}
- (size_t)count
{
return _range.length;
}
- (id)objectAtIndex: (size_t)index
{
if (index >= _range.length)
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
return [_array objectAtIndex: index + _range.location];
}
- (void)getObjects: (id*)buffer
inRange: (of_range_t)range
{
if (range.length > SIZE_MAX - range.location ||
range.location + range.length > _range.length)
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
range.location += _range.location;
return [_array getObjects: buffer
inRange: range];
}
- (size_t)indexOfObject: (id)object
{
size_t index = [_array indexOfObject: object];
if (index < _range.location)
return OF_NOT_FOUND;
index -= _range.location;
if (index >= _range.length)
return OF_NOT_FOUND;
return index;
}
- (size_t)indexOfObjectIdenticalTo: (id)object
{
size_t index = [_array indexOfObjectIdenticalTo: object];
if (index < _range.location)
return OF_NOT_FOUND;
index -= _range.location;
if (index >= _range.length)
return OF_NOT_FOUND;
return index;
}
- (OFArray*)objectsInRange: (of_range_t)range
{
if (range.length > SIZE_MAX - range.location ||
range.location + range.length > _range.length)
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
range.location += _range.location;
return [_array objectsInRange: range];
}
@end
|