-
Notifications
You must be signed in to change notification settings - Fork 5
/
Location.m
71 lines (59 loc) · 1.38 KB
/
Location.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
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
@implementation Location
+(instancetype)locationWithBase:(NSObject<LocationBase>*)base address:(long)address
{
if(address<0)
{
return nil;
}
if([base offsetWithAddress:address]<0)
{
return nil;
}
if(![base pointerWithAddress:address])
{
return nil;
}
Location* location=Location.alloc.init.autorelease;
location.base=base;
location.address=address;
return location;
}
-(long)offset
{
return [self.base offsetWithAddress:self.address];
}
-(char*)pointer
{
return [self.base pointerWithAddress:self.address];
}
@end
Location* wrapAddressUnsafe(NSObject<LocationBase>* base,long address)
{
return [Location locationWithBase:base address:address];
}
Location* wrapOffsetUnsafe(NSObject<LocationBase>* base,long offset)
{
return wrapAddressUnsafe(base,[base addressWithOffset:offset]);
}
Location* wrapPointerUnsafe(NSObject<LocationBase>* base,char* pointer)
{
return wrapAddressUnsafe(base,[base addressWithPointer:pointer]);
}
Location* wrapAddress(NSObject<LocationBase>* base,long address)
{
Location* result=wrapAddressUnsafe(base,address);
assert(result);
return result;
}
Location* wrapOffset(NSObject<LocationBase>* base,long offset)
{
Location* result=wrapOffsetUnsafe(base,offset);
assert(result);
return result;
}
Location* wrapPointer(NSObject<LocationBase>* base,char* pointer)
{
Location* result=wrapPointerUnsafe(base,pointer);
assert(result);
return result;
}