File: HFFullMemoryByteSlice.m

package info (click to toggle)
sameboy 1.0.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 10,528 kB
  • sloc: ansic: 29,948; objc: 22,249; asm: 1,424; pascal: 1,373; makefile: 1,065; xml: 111
file content (46 lines) | stat: -rw-r--r-- 1,241 bytes parent folder | download | duplicates (2)
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