forked from LIJI32/SameBoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHFFullMemoryByteSlice.m
46 lines (37 loc) · 1.21 KB
/
HFFullMemoryByteSlice.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
//
// HFFullMemoryByteSlice.m
// HexFiend_2
//
// Copyright 2007 ridiculous_fish. All rights reserved.
//
#import "HFFullMemoryByteSlice.h"
@implementation HFFullMemoryByteSlice
- (instancetype)initWithData:(NSData *)val {
REQUIRE_NOT_NULL(val);
self = [super init];
data = [val copy];
return self;
}
- (void)dealloc {
[data release];
[super dealloc];
}
- (unsigned long long)length { return [data length]; }
- (void)copyBytes:(unsigned char *)dst range:(HFRange)lrange {
NSRange range;
HFASSERT(lrange.location <= NSUIntegerMax);
HFASSERT(lrange.length <= NSUIntegerMax);
HFASSERT(lrange.location + lrange.length >= lrange.location);
range.location = ll2l(lrange.location);
range.length = ll2l(lrange.length);
[data getBytes:dst range:range];
}
- (HFByteSlice *)subsliceWithRange:(HFRange)range {
HFASSERT(range.length > 0);
HFASSERT(range.location < [self length]);
HFASSERT([self length] - range.location >= range.length);
HFASSERT(range.location <= NSUIntegerMax);
HFASSERT(range.length <= NSUIntegerMax);
return [[[[self class] alloc] initWithData:[data subdataWithRange:NSMakeRange(ll2l(range.location), ll2l(range.length))]] autorelease];
}
@end